-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathChangeThemeDialog.test.jsx
More file actions
64 lines (52 loc) · 1.8 KB
/
ChangeThemeDialog.test.jsx
File metadata and controls
64 lines (52 loc) · 1.8 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { ChangeThemeDialog } from '../../../src/components/ChangeThemeDialog';
/**
* Helper function to create a shallow wrapper around ErrorDialog
*/
function createWrapper(props) {
render(
<ChangeThemeDialog
classes={{ darkColor: '#000000', lightColor: '#ffffff' }}
handleClose={() => {}}
open
setSelectedTheme={() => {}}
selectedTheme="light"
themeIds={['light', 'dark']}
{...props}
/>,
);
}
describe('ChangeThemeDialog', () => {
it('renders nothing when the dialog is not open', () => {
createWrapper({ open: false });
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
it('renders propertly', () => {
createWrapper();
expect(screen.getByRole('dialog')).toBeInTheDocument();
});
it('shows up theme selection properly', () => {
createWrapper();
const menuItems = screen.queryAllByRole('menuitem');
expect(menuItems.length).toBe(2);
expect(menuItems[0]).toHaveTextContent('Light theme');
expect(menuItems[1]).toHaveTextContent('Dark theme');
});
it('shows up theme selection properly', async () => {
const user = userEvent.setup();
const setSelectedTheme = vi.fn();
createWrapper({ setSelectedTheme });
const menuItem = screen.getByRole('menuitem', { name: 'Light theme' });
expect(menuItem).toBeInTheDocument();
await user.click(menuItem);
expect(setSelectedTheme).toHaveBeenCalledWith('light');
});
describe('inital focus', () => {
it('focuses the selected item', () => {
createWrapper({ selectedTheme: 'light' });
const menuItem = screen.getByRole('menuitem', { name: 'Light theme' });
expect(menuItem).toHaveFocus();
});
});
});