-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWindowTopBarPluginMenu.test.jsx
More file actions
85 lines (69 loc) · 2.6 KB
/
WindowTopBarPluginMenu.test.jsx
File metadata and controls
85 lines (69 loc) · 2.6 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
80
81
82
83
84
85
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { WindowTopBarPluginMenu } from '../../../src/components/WindowTopBarPluginMenu';
import { usePlugins } from '../../../src/extend/usePlugins';
vi.mock('../../../src/extend/usePlugins');
/** 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)', () => {
vi.mocked(usePlugins).mockReturnValue({ PluginComponents: [] });
render(<Subject />);
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();
vi.mocked(usePlugins).mockReturnValue({ PluginComponents: [mockComponentA] });
render(<Subject />);
});
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();
});
});
describe('pluginTarget prop', () => {
it('passes the pluginTarget to usePlugins', () => {
const spy = vi.mocked(usePlugins);
spy.mockReturnValue({ PluginComponents: [mockComponentA] });
render(<Subject pluginTarget="CustomPluginTarget" />);
expect(spy).toHaveBeenCalledWith('CustomPluginTarget');
});
it('defaults pluginTarget to WindowTopBarPluginMenu if not provided', () => {
const spy = vi.mocked(usePlugins);
spy.mockReturnValue({ PluginComponents: [mockComponentA] });
render(<Subject />);
expect(spy).toHaveBeenCalledWith('WindowTopBarPluginMenu');
});
});
});