-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathWorkspaceElastic.test.jsx
More file actions
115 lines (103 loc) · 2.85 KB
/
WorkspaceElastic.test.jsx
File metadata and controls
115 lines (103 loc) · 2.85 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { fireEvent, render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import WorkspaceElastic from '../../../src/components/WorkspaceElastic';
/** create wrapper */
function createWrapper({ elasticLayout = {}, ...props }) {
return render(
<WorkspaceElastic
classes={{}}
elasticLayout={elasticLayout}
workspace={{
draggingEnabled: true,
focusedWindowId: '2',
height: 5000,
viewportPosition: {
x: 20,
y: 20,
},
width: 5000,
}}
setWorkspaceViewportDimensions={() => {}}
setWorkspaceViewportPosition={() => {}}
updateElasticWindowLayout={() => {}}
{...props}
/>,
{
preloadedState: {
companionWindows: {},
elasticLayout,
windows: { 1: { companionWindowIds: [] }, 2: { companionWindowIds: [] } },
workspace: { draggingEnabled: true },
},
},
);
}
/* eslint-disable testing-library/no-node-access, testing-library/no-container */
describe('WorkspaceElastic', () => {
const elasticLayout = {
1: {
height: 200,
width: 200,
windowId: '1',
x: 20,
y: 20,
},
2: {
height: 400,
width: 300,
windowId: '2',
x: 25,
y: 25,
},
};
it('should render properly with an initialValue', () => {
createWrapper({ elasticLayout });
expect(screen.getAllByLabelText('Window:')).toHaveLength(2);
});
describe('workspace behaviour', () => {
it('when workspace itself is dragged', async () => {
const user = userEvent.setup();
const mockDragStop = vi.fn();
const { container } = createWrapper({
elasticLayout,
setWorkspaceViewportPosition: mockDragStop,
});
container.getBoundingClientRect = () => ({
left: -2500,
offsetHeight: 5000,
offsetWidth: 5000,
top: -2500,
});
const el = container.querySelector('.mirador-workspace.react-draggable');
const coords = {
clientX: 400,
clientY: 300,
};
await user.pointer([
{ coords: { clientX: 0, clientY: 0 }, keys: '[MouseLeft>]', target: el },
{ coords },
{ coords, keys: '[/MouseLeft]', target: el },
]);
expect(mockDragStop).toHaveBeenCalledWith({
x: -1 * (400 - 20),
y: -1 * (300 - 20),
});
});
it('when workspace itself is resized', () => {
const mockResize = vi.fn();
const { container } = createWrapper({
elasticLayout,
setWorkspaceViewportDimensions: mockResize,
});
container.firstChild.getBoundingClientRect = () => ({
height: 500,
width: 800,
});
fireEvent(window, new Event('resize'));
expect(mockResize).toHaveBeenCalledWith({
height: 500,
width: 800,
});
});
});
});