-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWorkspaceExport.test.jsx
More file actions
62 lines (52 loc) · 2 KB
/
WorkspaceExport.test.jsx
File metadata and controls
62 lines (52 loc) · 2 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
import { screen, render } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { WorkspaceExport } from '../../../src/components/WorkspaceExport';
describe('WorkspaceExport', () => {
let user;
let handleClose = vi.fn();
let mockState;
beforeEach(() => {
user = userEvent.setup();
handleClose = vi.fn();
mockState = {
companionWindows: {},
config: {},
elasticLayout: {},
viewers: {},
windows: {},
workspace: {},
};
render(<WorkspaceExport open handleClose={handleClose} exportableState={mockState} />);
});
it('renders without an error', () => {
expect(screen.getByRole('dialog')).toBeInTheDocument();
});
it('renders sizing props', () => {
expect(screen.getByRole('dialog')).toHaveClass('MuiDialog-paperWidthSm');
});
it('is closable by clicking the cancel button', async () => {
await user.click(screen.getByRole('button', { name: 'Cancel' }));
expect(handleClose).toHaveBeenCalled();
});
it('reveals a snackbar on copy', async () => {
// jsdom doesn't support the clipboard API or prompt (used as a fallback)
// so we mock the prompt at least to avoid a warning in the test output
vi.stubGlobal(
'prompt',
vi.fn(() => true),
);
await user.click(screen.getByRole('button', { name: 'Copy' }));
expect(screen.getByRole('alert')).toHaveTextContent(
'The workspace configuration was copied to your clipboard',
);
await user.click(screen.getByRole('button', { name: 'Dismiss' }));
expect(handleClose).toHaveBeenCalled();
});
it('renders an exportable version of state', async () => {
await user.click(screen.getByRole('button', { name: 'View workspace configuration' }));
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByRole('region').querySelector('pre')).toHaveTextContent(
'{ "companionWindows": {}, "config": {}, "elasticLayout": {}, "viewers": {}, "windows": {}, "workspace": {} }',
);
});
});