-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDialog.test.tsx
More file actions
81 lines (68 loc) · 2.13 KB
/
Copy pathDialog.test.tsx
File metadata and controls
81 lines (68 loc) · 2.13 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { render, screen, waitFor } from '@testing-library/react';
import { createRef } from 'react';
import { testA11y } from '@interlay/test-utils';
import userEvent from '@testing-library/user-event';
import { Dialog, DialogBody, DialogDivider, DialogFooter, DialogHeader } from '..';
describe('Dialog', () => {
it('should render correctly', () => {
const wrapper = render(
<Dialog>
<DialogHeader>title</DialogHeader>
<DialogDivider />
<DialogBody>body</DialogBody>
<DialogFooter>footer</DialogFooter>
</Dialog>
);
expect(() => wrapper.unmount()).not.toThrow();
});
it('ref should be forwarded', () => {
const ref = createRef<HTMLDivElement>();
render(
<Dialog ref={ref}>
<DialogHeader>title</DialogHeader>
<DialogDivider />
<DialogBody>body</DialogBody>
<DialogFooter>footer</DialogFooter>
</Dialog>
);
expect(ref.current).not.toBeNull();
});
it('should pass a11y', async () => {
await testA11y(
<Dialog>
<DialogHeader>title</DialogHeader>
<DialogDivider />
<DialogBody>body</DialogBody>
<DialogFooter>footer</DialogFooter>
</Dialog>
);
});
it('should dialog sections', async () => {
render(
<Dialog>
<DialogHeader>title</DialogHeader>
<DialogDivider />
<DialogBody>body</DialogBody>
<DialogFooter>footer</DialogFooter>
</Dialog>
);
expect(screen.getByRole('heading', { level: 3, name: /title/i })).toBeInTheDocument();
expect(screen.getByText(/body/i)).toBeInTheDocument();
expect(screen.getByText(/footer/i)).toBeInTheDocument();
});
it('should emit onClose using close btn', async () => {
const handleClose = jest.fn();
render(
<Dialog onClose={handleClose}>
<DialogHeader>title</DialogHeader>
<DialogDivider />
<DialogBody>body</DialogBody>
<DialogFooter>footer</DialogFooter>
</Dialog>
);
userEvent.click(screen.getByRole('button', { name: /dismiss/i }));
await waitFor(() => {
expect(handleClose).toHaveBeenCalledTimes(1);
});
});
});