-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathContextMenu.test.tsx
More file actions
29 lines (22 loc) · 921 Bytes
/
ContextMenu.test.tsx
File metadata and controls
29 lines (22 loc) · 921 Bytes
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
import { ReactNode } from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import ContextMenu from './ContextMenu';
import { ContextMenuItem } from './index';
jest.mock('../popper/Popper', () => ({
__esModule: true,
default: ({ children }: { children: ReactNode }) => <div data-testid="mock-popper">{children}</div>
}));
describe('ContextMenu', () => {
it('should render menu items inside the topology popper and close on select', () => {
const onRequestClose = jest.fn();
render(
<ContextMenu reference={{ x: 120, y: 140 }} onRequestClose={onRequestClose}>
<ContextMenuItem>First</ContextMenuItem>
</ContextMenu>
);
expect(screen.getByTestId('mock-popper')).toBeInTheDocument();
const menuItem = screen.getByRole('menuitem', { name: 'First' });
fireEvent.click(menuItem);
expect(onRequestClose).toHaveBeenCalledTimes(1);
});
});