-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjest.setup.js
More file actions
353 lines (335 loc) · 13 KB
/
jest.setup.js
File metadata and controls
353 lines (335 loc) · 13 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import '@testing-library/jest-dom';
import { Table } from 'antd';
import { LiteGraphSdk } from 'litegraphdb';
// Mock the antd React 19 patch since tests mock antd without unstableSetRender
jest.mock('@ant-design/v5-patch-for-react-19', () => ({}));
// Mock msw and msw/node to avoid ESM import issues
jest.mock('msw', () => ({
http: {
get: jest.fn((url, handler) => ({ url, handler, method: 'GET' })),
post: jest.fn((url, handler) => ({ url, handler, method: 'POST' })),
put: jest.fn((url, handler) => ({ url, handler, method: 'PUT' })),
delete: jest.fn((url, handler) => ({ url, handler, method: 'DELETE' })),
patch: jest.fn((url, handler) => ({ url, handler, method: 'PATCH' })),
},
HttpResponse: {
json: jest.fn((data) => data),
text: jest.fn((data) => data),
error: jest.fn(() => new Error('Mock error')),
},
delay: jest.fn(() => Promise.resolve()),
}));
jest.mock('msw/node', () => ({
setupServer: jest.fn((...handlers) => ({
listen: jest.fn(),
close: jest.fn(),
resetHandlers: jest.fn(),
use: jest.fn(),
restoreHandlers: jest.fn(),
})),
}));
// Mock next/navigation
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
};
},
usePathname() {
return '';
},
}));
// Patch unsupported selector behavior in Ant Design
Object.defineProperty(window, 'getComputedStyle', {
value: () => ({
getPropertyValue: () => '',
}),
});
// jest.useFakeTimers();
// // Set a fixed date for consistent snapshots
// jest.setSystemTime(new Date('2023-01-01T12:00:00Z'));
// // ... your test code
// jest.useRealTimers(); // Restore real timers after the test
beforeAll(() => {
jest.useFakeTimers('modern');
jest.setSystemTime(new Date('2023-01-01T12:00:00Z'));
});
afterAll(() => {
jest.useRealTimers();
});
// jest.mock('litegraphdb', () => {
// return {
// LiteGraphSdk: jest.fn().mockImplementation(() => ({
// // Mock fetchEdgeById method
// fetchEdgeById: jest.fn().mockResolvedValue({
// GUID: '7b665c02-249a-4029-b782-92526f50d357',
// GraphGUID: 'd52e9587-f9a8-4348-9cfe-b860ab13ba54',
// Name: 'new test 23',
// From: '0be10847-040f-4ce5-8694-72da08824f1e',
// To: 'ada1be94-0272-45bb-84fd-75e14f56ffe8',
// Cost: 2,
// CreatedUtc: '2024-12-24T07:34:47.695616Z',
// Data: {},
// }),
// // Mock exportGraphToGexf method
// exportGraphToGexf: jest
// .fn()
// .mockResolvedValue(
// `<?xml version="1.0" encoding="utf-8"?> <gexf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd" version="1.3" xmlns="http://www.gexf.net/1.3"> <meta lastmodifieddate="2025-01-02T07:37:34.9191749Z"> <creator>LiteGraph</creator> <description>Graph from LiteGraph https://github.com/jchristn/litegraph</description> </meta> <graph defaultedgetype="directed"> <attributes class="node"> <attribute id="0" title="props" type="string" /> </attributes> <nodes> <node id="3897b459-a197-48e0-bb8d-e54255675713" label="new one 2"> <attvalues> <attvalue for="Name" value="new one 2" /> </attvalues> </node> <node id="0be10847-040f-4ce5-8694-72da08824f1e" label="new one"> <attvalues> <attvalue for="Name" value="new one" /> </attvalues> </node> <node id="ada1be94-0272-45bb-84fd-75e14f56ffe8" label="test"> <attvalues> <attvalue for="Name" value="test" /> </attvalues> </node> <node id="976e0552-2462-494b-82bc-fd113f89409c" label="My test node 121"> <attvalues> <attvalue for="Name" value="My test node 121" /> </attvalues> </node> </nodes> <edges> <edge id="7b665c02-249a-4029-b782-92526f50d357" source="0be10847-040f-4ce5-8694-72da08824f1e" target="ada1be94-0272-45bb-84fd-75e14f56ffe8"> <attvalues> <attvalue for="Name" value="new test 23" /> <attvalue for="Cost" value="2" /> </attvalues> </edge> <edge id="d35bea13-f548-43be-b005-c79191117334" source="976e0552-2462-494b-82bc-fd113f89409c" target="ada1be94-0272-45bb-84fd-75e14f56ffe8"> <attvalues> <attvalue for="Name" value="test edge" /> <attvalue for="Cost" value="5" /> </attvalues> </edge> </edges> </graph> </gexf>`
// ),
// // Mock createEdge method
// createEdge: jest.fn().mockResolvedValue({
// GUID: '7b665g72-249a-4029-b782-92526f50d357',
// GraphGUID: 'd52e9587-f9a8-4348-9cfe-b860ab13ba54',
// Name: 'new test 23',
// From: '3fc519b1-5f78-4fc7-810b-c18fade549db',
// To: '6fe5823b-31ad-4431-9d3d-53d8b6f1ed4c',
// Cost: 2,
// CreatedUtc: '2024-12-24T07:34:47.695616Z',
// Data: {},
// }),
// // Mock readEdges method
// readEdges: jest.fn().mockResolvedValue([
// {
// GUID: '7b665c02-249a-4029-b782-92526f50d357',
// GraphGUID: 'd52e9587-f9a8-4348-9cfe-b860ab13ba54',
// Name: 'new test 23',
// From: '3fc519b1-5f78-4fc7-810b-c18fade549db',
// To: '6fe5823b-31ad-4431-9d3d-53d8b6f1ed4c',
// Cost: 2,
// CreatedUtc: '2024-12-24T07:34:47.695616Z',
// Data: {},
// },
// {
// GUID: 'd35bea13-f548-43be-b005-c79191117334',
// GraphGUID: 'd52e9587-f9a8-4348-9cfe-b860ab13ba54',
// Name: 'test edge',
// From: '976e0552-2462-494b-82bc-fd113f89409c',
// To: 'ada1be94-0272-45bb-84fd-75e14f56ffe8',
// Cost: 5,
// CreatedUtc: '2024-12-17T09:24:39.806284Z',
// Data: {},
// },
// ]),
// // Mock tag-related methods
// readTags: jest.fn().mockResolvedValue([
// {
// GUID: '123e4567-e89b-12d3-a456-426614174000',
// TenantGUID: '123e4567-e89b-12d3-a456-426614174111',
// GraphGUID: '123e4567-e89b-12d3-a456-426614174222',
// NodeGUID: '123e4567-e89b-12d3-a456-426614174333',
// Key: 'priority',
// Value: 'high',
// CreatedUtc: '2024-01-15T10:00:00.000Z',
// LastUpdateUtc: '2024-01-15T10:00:00.000Z',
// },
// {
// GUID: '123e4567-e89b-12d3-a456-426614174001',
// TenantGUID: '123e4567-e89b-12d3-a456-426614174111',
// GraphGUID: '123e4567-e89b-12d3-a456-426614174222',
// NodeGUID: '123e4567-e89b-12d3-a456-426614174333',
// Key: 'status',
// Value: 'active',
// CreatedUtc: '2024-01-15T10:00:00.000Z',
// LastUpdateUtc: '2024-01-15T10:00:00.000Z',
// },
// ]),
// createTag: jest.fn().mockResolvedValue({
// GUID: '123e4567-e89b-12d3-a456-426614174002',
// TenantGUID: '123e4567-e89b-12d3-a456-426614174111',
// GraphGUID: '123e4567-e89b-12d3-a456-426614174222',
// NodeGUID: '123e4567-e89b-12d3-a456-426614174333',
// Key: 'newTag',
// Value: 'newValue',
// CreatedUtc: '2024-01-15T10:00:00.000Z',
// LastUpdateUtc: '2024-01-15T10:00:00.000Z',
// }),
// updateTag: jest.fn().mockResolvedValue({
// GUID: '123e4567-e89b-12d3-a456-426614174000',
// TenantGUID: '123e4567-e89b-12d3-a456-426614174111',
// GraphGUID: '123e4567-e89b-12d3-a456-426614174222',
// NodeGUID: '123e4567-e89b-12d3-a456-426614174333',
// Key: 'priority',
// Value: 'updated',
// CreatedUtc: '2024-01-15T10:00:00.000Z',
// LastUpdateUtc: '2024-01-15T11:00:00.000Z',
// }),
// deleteTag: jest.fn().mockResolvedValue({
// GUID: '123e4567-e89b-12d3-a456-426614174000',
// TenantGUID: '123e4567-e89b-12d3-a456-426614174111',
// GraphGUID: '123e4567-e89b-12d3-a456-426614174222',
// NodeGUID: '123e4567-e89b-12d3-a456-426614174333',
// Key: 'priority',
// Value: 'high',
// CreatedUtc: '2024-01-15T10:00:00.000Z',
// LastUpdateUtc: '2024-01-15T10:00:00.000Z',
// }),
// // Mock readGraphs method
// readGraphs: jest.fn().mockResolvedValue([
// {
// GUID: 'e6d4294e-6f49-4d67-8260-5e44c2b077a6',
// Name: 'Test Demo Graph',
// CreatedUtc: '2024-12-23T15:36:07.816289Z',
// Data: {
// name: 'value',
// },
// },
// {
// GUID: 'd52aeab4-4de7-4076-98dd-461d4a61ac88',
// Name: 'testttt 2',
// CreatedUtc: '2024-12-18T07:28:53.965316Z',
// Data: {},
// },
// ]),
// // Mock createGraph method
// createGraph: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8c16',
// Name: 'New Graph',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// // Mock updateGraph method
// updateGraph: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8c16',
// Name: 'Updated Graph',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// // Mock deleteGraph method
// deleteGraph: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8c16',
// Name: 'Updated Graph',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// // Mock readNodes method
// readNodes: jest.fn().mockResolvedValue([
// {
// GUID: '3fc519b1-5f78-4fc7-810b-c18fade549db',
// GraphGUID: '01010101-0101-0101-0101-010101010101',
// Name: 'My updated test node',
// Data: {},
// CreatedUtc: '2024-12-18T07:27:58.206132Z',
// },
// {
// GUID: '6fe5823b-31ad-4431-9d3d-53d8b6f1ed4c',
// GraphGUID: '01010101-0101-0101-0101-010101010101',
// Name: 'test sas',
// Data: {
// Hello: 'world',
// },
// CreatedUtc: '2024-12-16T08:27:17.639147Z',
// },
// ]),
// // Mock createNode method
// createNode: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8a16',
// GraphGUID: '01010101-0101-0101-0101-010101010101',
// Name: 'New Node',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// // Mock updateNode method
// updateNode: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8a16',
// GraphGUID: '01010101-0101-0101-0101-010101010101',
// Name: 'New Updated Node',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// // Mock deleteNode method
// deleteNode: jest.fn().mockResolvedValue({
// GUID: 'b35234a5-e2d9-4401-b9a9-ea74e47f8a16',
// GraphGUID: '01010101-0101-0101-0101-010101010101',
// Name: 'New Updated Node',
// CreatedUtc: '2024-12-26T11:50:04.451739Z',
// Data: {
// graph: {},
// },
// }),
// })),
// };
// });
// jest.mock('./components/base/select/Select', () => ({
// __esModule: true,
// default: jest.fn((props) => (
// <div data-testid="mocked-litegraph-select" {...props}>
// Mocked LitegraphSelect
// </div>
// )),
// }));
// Mock rc-util scrollbar size logic
jest.mock('rc-util/lib/getScrollBarSize', () => ({
__esModule: true,
getTargetScrollBarSize: () => ({
width: 0,
height: 0,
}),
}));
// eslint-disable-next-line react/display-name
jest.mock('@/components/base/select/Select', () => (props) => {
return (
<select
data-testid={props['data-testid']}
value={props.value}
onChange={(e) => props.onChange(e.target.value)}
>
{props?.options?.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
);
});
jest.mock('jsoneditor-react', () => ({
JsonEditor: ({ value, onChange }) => (
<input
data-testid="json-editor-textarea"
value={value}
onChange={(e) => onChange(e.target.value)}
/>
),
}));
window.matchMedia =
window.matchMedia ||
function () {
return {
matches: false,
addListener: () => {},
removeListener: () => {},
};
};
class BroadcastChannelMock {
constructor(channelName) {
this.name = channelName;
this.onmessage = null;
}
postMessage(message) {
if (this.onmessage) {
this.onmessage({ data: message });
}
}
close() {
// No-op
}
}
global.BroadcastChannel = BroadcastChannelMock;
global.TransformStream = class {
constructor() {
this.readable = {};
this.writable = {};
}
};