-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathWindowTopBarPluginMenu.test.js
More file actions
60 lines (52 loc) · 1.84 KB
/
WindowTopBarPluginMenu.test.js
File metadata and controls
60 lines (52 loc) · 1.84 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { WindowTopBarMenu } from '../../../src/components/WindowTopBarMenu';
import { WindowTopBarPluginMenu } from '../../../src/components/WindowTopBarPluginMenu';
/** create wrapper */
function Subject({ ...props }) {
return (
<WindowTopBarPluginMenu
windowId="abc123"
{...props}
/>
);
}
// needs to be a non-functional component to accept forwardRef the way we have it set up
/** */
class mockComponentA extends React.Component {
/** */
render() {
return (
<div data-testid="testA" />
);
}
}
describe('WindowTopBarPluginMenu', () => {
describe('when there are no plugins present', () => {
it('renders nothing (and no Button/Menu/PluginHook)', () => {
render(<WindowTopBarMenu />);
expect(screen.queryByTestId('testA')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Window options' })).not.toBeInTheDocument();
});
});
describe('when there are plugins present', () => {
let user;
beforeEach(() => {
user = userEvent.setup();
render(<Subject PluginComponents={[mockComponentA]} />);
});
it('renders the Button', async () => {
expect(screen.getByRole('button', { name: 'Window options' })).toBeInTheDocument();
});
it('the Menu is controlled by the Button clicks', async () => {
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
expect(screen.queryByTestId('testA')).not.toBeInTheDocument();
// open
await user.click(screen.getByRole('button', { name: 'Window options' }));
expect(screen.getByRole('menu')).toBeInTheDocument();
await user.keyboard('{Escape}');
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
});
});
});