-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathFullScreenButton.test.jsx
More file actions
79 lines (66 loc) · 2.1 KB
/
FullScreenButton.test.jsx
File metadata and controls
79 lines (66 loc) · 2.1 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import FullScreenContext from '../../../src/contexts/FullScreenContext';
import { FullScreenButton } from '../../../src/components/FullScreenButton';
/** */
function createWrapper(props, contextProps = { active: false }) {
return render(
<FullScreenContext.Provider value={{ enter: () => {}, exit: () => {}, ...contextProps }}>
<FullScreenButton
classes={{}}
className="xyz"
{...props}
/>
</FullScreenContext.Provider>,
);
}
describe('FullScreenButton', () => {
it('renders without an error', () => {
createWrapper();
expect(screen.getByRole('button')).toHaveClass('xyz');
});
describe('when not in fullscreen', () => {
let enter;
let user;
beforeEach(() => {
enter = vi.fn();
user = userEvent.setup();
createWrapper({}, { enter });
});
it('has the proper aria-label i18n key', () => {
expect(screen.getByRole('button')).toHaveAccessibleName('Full screen');
});
it('triggers the handle enter with the appropriate boolean', async () => {
await user.click(screen.getByRole('button'));
expect(enter).toHaveBeenCalled();
});
});
describe('when in fullscreen', () => {
let exit;
let user;
beforeEach(() => {
exit = vi.fn();
user = userEvent.setup();
createWrapper({}, { active: true, exit });
});
it('has the proper aria-label', () => {
expect(screen.getByRole('button')).toHaveAccessibleName('Exit full screen');
});
it('triggers the handle exit with the appropriate boolean', async () => {
await user.click(screen.getByRole('button'));
expect(exit).toHaveBeenCalled();
});
});
describe('when requestFullscreen is not supported', () => {
beforeAll(() => {
__disableMockRequestFullscreen();
});
afterAll(() => {
__mockRequestFullscreen();
});
it('does not render the button', () => {
createWrapper();
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
});
});