-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathDropdown.test.tsx
93 lines (79 loc) · 2.62 KB
/
Dropdown.test.tsx
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { axe } from '../../utils/axeHelper';
import { Dropdown } from './Dropdown';
import { Button } from '../Button';
import { DropdownListItem } from './DropdownListItem/DropdownListItem';
import { DropdownList } from './DropdownList/DropdownList';
beforeAll(() => {
Date.now = jest.fn(() => 123456);
Math.random = jest.fn(() => 500);
});
it('renders the component', () => {
const { container } = render(
<Dropdown toggleElement={<Button onClick={() => {}}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
</DropdownList>
</Dropdown>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders the component with an additional class name', () => {
const { container } = render(
<Dropdown toggleElement={<Button onClick={() => {}}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
</DropdownList>
</Dropdown>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders the component as open', () => {
const { container } = render(
<Dropdown isOpen toggleElement={<Button onClick={() => {}}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
</DropdownList>
</Dropdown>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('toggleElement dispactions onClick event', () => {
const onClickFunc = jest.fn();
render(
<Dropdown toggleElement={<Button onClick={onClickFunc}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
</DropdownList>
</Dropdown>,
);
userEvent.click(screen.getByText('Toggle'));
expect(onClickFunc).toHaveBeenCalled();
});
it('renders the component with a submenu', () => {
const { container } = render(
<Dropdown isOpen toggleElement={<Button onClick={() => {}}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
<Dropdown isOpen submenuToggleLabel="Submenu">
<DropdownListItem>entry</DropdownListItem>
</Dropdown>
,
</DropdownList>
</Dropdown>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('has no a11y issues', async () => {
const { container } = render(
<Dropdown toggleElement={<Button onClick={() => {}}>Toggle</Button>}>
<DropdownList>
<DropdownListItem>entry</DropdownListItem>
</DropdownList>
</Dropdown>,
);
const results = await axe(container);
expect(results).toHaveNoViolations();
});