-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathNestedMenu.test.jsx
More file actions
57 lines (44 loc) · 1.59 KB
/
NestedMenu.test.jsx
File metadata and controls
57 lines (44 loc) · 1.59 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { NestedMenu } from '../../../src/components/NestedMenu';
/**
* Helper function to wrap creating a NestedMenu component
*/
function createWrapper(props) {
return render(
<NestedMenu
icon="GivenIcon"
label="GivenLabel"
{...props}
>
GivenChildren
</NestedMenu>,
);
}
describe('NestedMenu', () => {
it('renders the given icon wrapped in a MUI ListItemIcon', () => {
createWrapper();
expect(screen.getByText('GivenIcon')).toHaveClass('MuiListItemIcon-root');
});
it('does not render a ListItemIcon if no icon prop is passed', () => {
createWrapper({ icon: null });
expect(screen.queryByText('GivenIcon')).not.toBeInTheDocument();
});
it('renders the given label wrapped in a MUI Typography', () => {
createWrapper();
expect(screen.getByText('GivenLabel')).toHaveClass('MuiTypography-body1');
});
it('toggles the local open state when clicking the MenuItem', async () => {
const user = userEvent.setup();
createWrapper();
expect(screen.queryByText('GivenChildren')).not.toBeInTheDocument();
await user.click(screen.getByRole('menuitem'));
expect(screen.getByText('GivenChildren')).toBeInTheDocument();
await user.click(screen.getByRole('menuitem'));
expect(screen.queryByText('GivenChildren')).not.toBeInTheDocument();
});
it('spreads options to the MenuItem', () => {
createWrapper({ 'data-testid': 'subject' });
expect(screen.getByTestId('subject')).toBeInTheDocument();
});
});