-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWorkspaceSelectionDialog.test.jsx
More file actions
59 lines (49 loc) · 1.81 KB
/
WorkspaceSelectionDialog.test.jsx
File metadata and controls
59 lines (49 loc) · 1.81 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
import {
render, screen, waitFor,
} from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { WorkspaceSelectionDialog } from '../../../src/components/WorkspaceSelectionDialog';
describe('WorkspaceSelectionDialog', () => {
let handleClose;
let updateWorkspace;
/**
* create wrapper
* @param {*} props additional properties
*/
function createWrapper(props) {
handleClose = vi.fn();
updateWorkspace = vi.fn();
return render(
<WorkspaceSelectionDialog
classes={{ list: 'list' }}
open
handleClose={handleClose}
updateWorkspace={updateWorkspace}
workspaceType="elastic"
{...props}
/>,
);
}
it('renders without an error', () => {
createWrapper();
expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getByRole('menuitem', { name: /Elastic/ })).toBeInTheDocument();
expect(screen.getByRole('menuitem', { name: /Mosaic/ })).toBeInTheDocument();
});
it('sends the updateConfig and handleClose props on workspace selection', async () => {
const user = userEvent.setup();
createWrapper();
await user.click(screen.getByRole('menuitem', { name: /Elastic/ }));
await waitFor(() => expect(updateWorkspace).toHaveBeenLastCalledWith({ type: 'elastic' }));
await user.click(screen.getByRole('menuitem', { name: /Mosaic/ }));
await waitFor(() => expect(updateWorkspace).toHaveBeenLastCalledWith({ type: 'mosaic' }));
await waitFor(() => expect(handleClose).toHaveBeenCalledTimes(2));
});
describe('inital focus', () => {
it('sets an onEntered prop on the Dialog that focuses the selected item', () => {
createWrapper();
const menuItem = screen.getByRole('menuitem', { name: /Elastic/ });
expect(menuItem).toHaveFocus();
});
});
});