-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathCollapsibleSection.test.jsx
More file actions
41 lines (36 loc) · 1.33 KB
/
CollapsibleSection.test.jsx
File metadata and controls
41 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { CollapsibleSection } from '../../../src/components/CollapsibleSection';
/**
* Helper function to create a shallow wrapper around CollapsibleSection
*/
function createWrapper(props) {
return render(
<CollapsibleSection
classes={{}}
id="abc123"
label="The Section Label"
{...props}
>
<span data-testid="child">Child content</span>
</CollapsibleSection>,
);
}
describe('CollapsibleSection', () => {
beforeEach(() => {
createWrapper();
});
it('renders the passed in label is a Typography', () => {
expect(screen.getByRole('heading')).toHaveTextContent('The Section Label');
});
it('renders the appropriate i18n label based on open state', async () => {
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Collapse "The Section Label" section');
await userEvent.click(screen.getByRole('button'));
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Expand "The Section Label" section');
});
it('displays children based on the open state', async () => {
expect(screen.getByTestId('child')).toBeVisible();
await userEvent.click(screen.getByRole('button'));
expect(screen.queryByTestId('child')).not.toBeVisible();
});
});