-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathZoomControls.test.jsx
More file actions
52 lines (43 loc) · 1.52 KB
/
ZoomControls.test.jsx
File metadata and controls
52 lines (43 loc) · 1.52 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { ZoomControls } from '../../../src/components/ZoomControls';
/** Utility function to create a shallow rendering */
function createWrapper(props) {
return render(
<ZoomControls
windowId="xyz"
zoomToWorld={() => {}}
{...props}
/>,
);
}
describe('ZoomControls', () => {
const viewer = { x: 100, y: 100, zoom: 1 };
let updateViewport;
const zoomToWorld = vi.fn();
let user;
beforeEach(() => {
user = userEvent.setup();
updateViewport = vi.fn();
createWrapper({
updateViewport, viewer, zoomToWorld,
});
});
it('renders a couple buttons', () => {
expect(screen.getByRole('button', { name: 'Zoom in' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Zoom out' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Reset zoom' })).toBeInTheDocument();
});
it('has a zoom-in button', async () => {
await user.click(screen.getByRole('button', { name: 'Zoom in' }));
expect(updateViewport).toHaveBeenCalledWith('xyz', { zoom: 2 });
});
it('has a zoom-out button', async () => {
await user.click(screen.getByRole('button', { name: 'Zoom out' }));
expect(updateViewport).toHaveBeenCalledWith('xyz', { zoom: 0.5 });
});
it('has a zoom reset button', async () => {
await user.click(screen.getByRole('button', { name: 'Reset zoom' }));
expect(zoomToWorld).toHaveBeenCalledWith(false);
});
});