forked from ProjectMirador/mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowTopMenu.test.js
More file actions
79 lines (67 loc) · 2.48 KB
/
WindowTopMenu.test.js
File metadata and controls
79 lines (67 loc) · 2.48 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
import { render, screen, within } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { WindowTopMenu } from '../../../src/components/WindowTopMenu';
/** create wrapper */
function Subject({ ...props }) {
return (
<div>
<WindowTopMenu
windowId="xyz"
handleClose={() => {}}
toggleDraggingEnabled={() => {}}
{...props}
/>
,
</div>
);
}
/** create anchor element */
function createAnchor() {
return render(
<button type="button" data-testid="menu-trigger-button">Button</button>,
);
}
describe('WindowTopMenu', () => {
it('renders all needed elements when open', () => {
createAnchor();
render(<Subject anchorEl={screen.getByTestId('menu-trigger-button')} open />);
expect(screen.getByRole('menu')).toBeInTheDocument();
const menuSections = within(screen.getByRole('menu')).getAllByRole('presentation');
expect(menuSections).toHaveLength(2);
expect(menuSections[0]).toHaveTextContent('View');
const menus = within(screen.getByRole('menu')).getAllByRole('menubar');
const viewItems = within(menus[0]).getAllByRole('menuitemradio');
expect(viewItems).toHaveLength(2);
expect(viewItems[0]).toHaveTextContent('Single');
expect(viewItems[1]).toHaveTextContent('Gallery');
expect(menuSections[1]).toHaveTextContent('Thumbnails');
const thumbnailItems = within(menus[1]).getAllByRole('menuitemradio');
expect(thumbnailItems).toHaveLength(3);
expect(thumbnailItems[0]).toHaveTextContent('Off');
expect(thumbnailItems[1]).toHaveTextContent('Bottom');
expect(thumbnailItems[2]).toHaveTextContent('Right');
});
it('does not display unless open', () => {
createAnchor();
render(<Subject open={false} />);
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
});
it('fires the correct callbacks on menu close', async () => {
const user = userEvent.setup();
createAnchor();
const handleClose = vi.fn();
const toggleDraggingEnabled = vi.fn();
const anchorEl = screen.getByTestId('menu-trigger-button');
render(<Subject
anchorEl={anchorEl}
handleClose={handleClose}
open
toggleDraggingEnabled={toggleDraggingEnabled}
/>);
// click a menu item should close the menu
const menuItems = screen.getAllByRole('menuitemradio');
await user.click(menuItems[0]);
expect(handleClose).toHaveBeenCalledTimes(1);
expect(toggleDraggingEnabled).toHaveBeenCalledTimes(1);
});
});