@terreno/admin-frontend 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AdminObjectPicker.js +1 -0
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminVersionConfig.js +1 -0
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConsentFormEditor.js +42 -28
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/useAdminApi.js +1 -2
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.js +1 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.js +1 -0
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.js +1 -0
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.js +1 -0
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +47 -22
- package/src/AdminModelForm.test.tsx +145 -40
- package/src/AdminModelList.test.tsx +13 -5
- package/src/AdminModelTable.test.tsx +57 -31
- package/src/AdminObjectPicker.tsx +1 -0
- package/src/AdminPrimitiveArrayField.test.tsx +13 -10
- package/src/AdminScriptList.test.tsx +6 -4
- package/src/AdminScriptRunModal.test.tsx +4 -2
- package/src/AdminVersionConfig.test.tsx +28 -23
- package/src/AdminVersionConfig.tsx +1 -0
- package/src/CheckboxListEditor.test.tsx +8 -6
- package/src/ConfigurationScreen.test.tsx +15 -11
- package/src/ConsentFormEditor.test.tsx +94 -75
- package/src/ConsentFormEditor.tsx +44 -33
- package/src/ConsentFormList.test.tsx +27 -10
- package/src/ConsentResponseViewer.test.tsx +14 -12
- package/src/DocumentStorageBrowser.test.tsx +68 -42
- package/src/LocaleContentEditor.test.tsx +27 -18
- package/src/isolated/AdminFieldRenderer.isolated.tsx +4 -2
- package/src/isolated/AdminNestedArrayField.isolated.tsx +48 -36
- package/src/isolated/AdminObjectPicker.isolated.tsx +30 -26
- package/src/isolated/AdminRefField.isolated.tsx +3 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +23 -17
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +79 -63
- package/src/isolated/hooks.isolated.tsx +39 -33
- package/src/useAdminApi.ts +1 -2
- package/src/useAdminConfig.ts +1 -0
- package/src/useAdminScripts.ts +1 -0
- package/src/useConfigurationApi.ts +1 -0
- package/src/useDocumentStorageApi.ts +1 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
3
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
4
5
|
import React from "react";
|
|
6
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
5
7
|
import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
|
|
8
|
+
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
6
9
|
|
|
7
10
|
const routerBack = mock(() => {});
|
|
8
11
|
const routerPush = mock(() => {});
|
|
9
|
-
const setOptions = mock((opts:
|
|
12
|
+
const setOptions = mock((opts: Record<string, unknown>) => {
|
|
10
13
|
// Invoke the headerRight render function so its children execute and we
|
|
11
14
|
// exercise the save/delete button useCallbacks when fired elsewhere.
|
|
12
15
|
if (opts?.headerRight) {
|
|
@@ -18,7 +21,7 @@ mock.module("expo-router", () => ({
|
|
|
18
21
|
useNavigation: () => ({setOptions}),
|
|
19
22
|
}));
|
|
20
23
|
|
|
21
|
-
const configState: {config:
|
|
24
|
+
const configState: {config: AdminConfigResponse | null; isLoading: boolean} = {
|
|
22
25
|
config: null,
|
|
23
26
|
isLoading: false,
|
|
24
27
|
};
|
|
@@ -30,7 +33,10 @@ mock.module("./useAdminConfig", () => ({
|
|
|
30
33
|
}),
|
|
31
34
|
}));
|
|
32
35
|
|
|
33
|
-
const readState: {data:
|
|
36
|
+
const readState: {data: Record<string, unknown> | null; isLoading: boolean} = {
|
|
37
|
+
data: null,
|
|
38
|
+
isLoading: false,
|
|
39
|
+
};
|
|
34
40
|
const createFn = mock((_: unknown) => ({unwrap: async () => ({_id: "new"})}));
|
|
35
41
|
const updateFn = mock((_: unknown) => ({unwrap: async () => ({_id: "u"})}));
|
|
36
42
|
const deleteFn = mock((_: unknown) => ({unwrap: async () => ({})}));
|
|
@@ -83,7 +89,12 @@ describe("AdminModelForm", () => {
|
|
|
83
89
|
it("renders loading state while config loads", () => {
|
|
84
90
|
configState.isLoading = true;
|
|
85
91
|
const {toJSON} = renderWithTheme(
|
|
86
|
-
<AdminModelForm
|
|
92
|
+
<AdminModelForm
|
|
93
|
+
api={{} as unknown as AdminApi}
|
|
94
|
+
baseUrl="/admin"
|
|
95
|
+
mode="create"
|
|
96
|
+
modelName="User"
|
|
97
|
+
/>
|
|
87
98
|
);
|
|
88
99
|
expect(toJSON()).toBeDefined();
|
|
89
100
|
});
|
|
@@ -91,7 +102,12 @@ describe("AdminModelForm", () => {
|
|
|
91
102
|
it("renders loading state when the model config is missing", () => {
|
|
92
103
|
configState.config = {customScreens: [], models: [], scripts: []};
|
|
93
104
|
const {toJSON} = renderWithTheme(
|
|
94
|
-
<AdminModelForm
|
|
105
|
+
<AdminModelForm
|
|
106
|
+
api={{} as unknown as AdminApi}
|
|
107
|
+
baseUrl="/admin"
|
|
108
|
+
mode="create"
|
|
109
|
+
modelName="User"
|
|
110
|
+
/>
|
|
95
111
|
);
|
|
96
112
|
expect(toJSON()).toBeDefined();
|
|
97
113
|
});
|
|
@@ -100,7 +116,7 @@ describe("AdminModelForm", () => {
|
|
|
100
116
|
configState.config = config;
|
|
101
117
|
const {toJSON} = renderWithTheme(
|
|
102
118
|
<AdminModelForm
|
|
103
|
-
api={{} as
|
|
119
|
+
api={{} as unknown as AdminApi}
|
|
104
120
|
baseUrl="/admin"
|
|
105
121
|
footerContent={React.createElement("FooterMarker")}
|
|
106
122
|
mode="create"
|
|
@@ -115,7 +131,13 @@ describe("AdminModelForm", () => {
|
|
|
115
131
|
configState.config = config;
|
|
116
132
|
readState.isLoading = true;
|
|
117
133
|
const {toJSON} = renderWithTheme(
|
|
118
|
-
<AdminModelForm
|
|
134
|
+
<AdminModelForm
|
|
135
|
+
api={{} as unknown as AdminApi}
|
|
136
|
+
baseUrl="/admin"
|
|
137
|
+
itemId="u1"
|
|
138
|
+
mode="edit"
|
|
139
|
+
modelName="User"
|
|
140
|
+
/>
|
|
119
141
|
);
|
|
120
142
|
expect(toJSON()).toBeDefined();
|
|
121
143
|
});
|
|
@@ -129,7 +151,13 @@ describe("AdminModelForm", () => {
|
|
|
129
151
|
name: "Existing",
|
|
130
152
|
};
|
|
131
153
|
const {toJSON} = renderWithTheme(
|
|
132
|
-
<AdminModelForm
|
|
154
|
+
<AdminModelForm
|
|
155
|
+
api={{} as unknown as AdminApi}
|
|
156
|
+
baseUrl="/admin"
|
|
157
|
+
itemId="u1"
|
|
158
|
+
mode="edit"
|
|
159
|
+
modelName="User"
|
|
160
|
+
/>
|
|
133
161
|
);
|
|
134
162
|
expect(toJSON()).toBeDefined();
|
|
135
163
|
});
|
|
@@ -147,7 +175,12 @@ describe("AdminModelForm", () => {
|
|
|
147
175
|
scripts: [],
|
|
148
176
|
};
|
|
149
177
|
const {toJSON, getByText} = renderWithTheme(
|
|
150
|
-
<AdminModelForm
|
|
178
|
+
<AdminModelForm
|
|
179
|
+
api={{} as unknown as AdminApi}
|
|
180
|
+
baseUrl="/admin"
|
|
181
|
+
mode="create"
|
|
182
|
+
modelName="User"
|
|
183
|
+
/>
|
|
151
184
|
);
|
|
152
185
|
expect(toJSON()).toBeDefined();
|
|
153
186
|
expect(getByText("No editable fields.")).toBeDefined();
|
|
@@ -160,7 +193,12 @@ describe("AdminModelForm", () => {
|
|
|
160
193
|
scripts: [],
|
|
161
194
|
};
|
|
162
195
|
const {toJSON} = renderWithTheme(
|
|
163
|
-
<AdminModelForm
|
|
196
|
+
<AdminModelForm
|
|
197
|
+
api={{} as unknown as AdminApi}
|
|
198
|
+
baseUrl="/admin"
|
|
199
|
+
mode="create"
|
|
200
|
+
modelName="User"
|
|
201
|
+
/>
|
|
164
202
|
);
|
|
165
203
|
expect(toJSON()).toBeDefined();
|
|
166
204
|
});
|
|
@@ -181,14 +219,19 @@ describe("AdminModelForm", () => {
|
|
|
181
219
|
],
|
|
182
220
|
};
|
|
183
221
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
184
|
-
setOptions.mockImplementation((opts:
|
|
222
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
185
223
|
if (opts?.headerRight) {
|
|
186
224
|
savedHeaderRight = opts.headerRight();
|
|
187
225
|
}
|
|
188
226
|
});
|
|
189
227
|
|
|
190
228
|
renderWithTheme(
|
|
191
|
-
<AdminModelForm
|
|
229
|
+
<AdminModelForm
|
|
230
|
+
api={{} as unknown as AdminApi}
|
|
231
|
+
baseUrl="/admin"
|
|
232
|
+
mode="create"
|
|
233
|
+
modelName="User"
|
|
234
|
+
/>
|
|
192
235
|
);
|
|
193
236
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
194
237
|
await act(async () => {
|
|
@@ -213,13 +256,18 @@ describe("AdminModelForm", () => {
|
|
|
213
256
|
],
|
|
214
257
|
};
|
|
215
258
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
216
|
-
setOptions.mockImplementation((opts:
|
|
259
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
217
260
|
if (opts?.headerRight) {
|
|
218
261
|
savedHeaderRight = opts.headerRight();
|
|
219
262
|
}
|
|
220
263
|
});
|
|
221
264
|
renderWithTheme(
|
|
222
|
-
<AdminModelForm
|
|
265
|
+
<AdminModelForm
|
|
266
|
+
api={{} as unknown as AdminApi}
|
|
267
|
+
baseUrl="/admin"
|
|
268
|
+
mode="create"
|
|
269
|
+
modelName="User"
|
|
270
|
+
/>
|
|
223
271
|
);
|
|
224
272
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
225
273
|
await act(async () => {
|
|
@@ -240,20 +288,20 @@ describe("AdminModelForm", () => {
|
|
|
240
288
|
},
|
|
241
289
|
],
|
|
242
290
|
};
|
|
243
|
-
const transformPayload = mock(async ({payload}: {payload:
|
|
291
|
+
const transformPayload = mock(async ({payload}: {payload: Record<string, unknown>}) => ({
|
|
244
292
|
...payload,
|
|
245
293
|
transformed: true,
|
|
246
294
|
}));
|
|
247
295
|
const onSaveSuccess = mock(async () => undefined);
|
|
248
296
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
249
|
-
setOptions.mockImplementation((opts:
|
|
297
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
250
298
|
if (opts?.headerRight) {
|
|
251
299
|
savedHeaderRight = opts.headerRight();
|
|
252
300
|
}
|
|
253
301
|
});
|
|
254
302
|
renderWithTheme(
|
|
255
303
|
<AdminModelForm
|
|
256
|
-
api={{} as
|
|
304
|
+
api={{} as unknown as AdminApi}
|
|
257
305
|
baseUrl="/admin"
|
|
258
306
|
mode="create"
|
|
259
307
|
modelName="User"
|
|
@@ -278,13 +326,18 @@ describe("AdminModelForm", () => {
|
|
|
278
326
|
},
|
|
279
327
|
}));
|
|
280
328
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
281
|
-
setOptions.mockImplementation((opts:
|
|
329
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
282
330
|
if (opts?.headerRight) {
|
|
283
331
|
savedHeaderRight = opts.headerRight();
|
|
284
332
|
}
|
|
285
333
|
});
|
|
286
334
|
renderWithTheme(
|
|
287
|
-
<AdminModelForm
|
|
335
|
+
<AdminModelForm
|
|
336
|
+
api={{} as unknown as AdminApi}
|
|
337
|
+
baseUrl="/admin"
|
|
338
|
+
mode="create"
|
|
339
|
+
modelName="User"
|
|
340
|
+
/>
|
|
288
341
|
);
|
|
289
342
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
290
343
|
await act(async () => {
|
|
@@ -299,13 +352,19 @@ describe("AdminModelForm", () => {
|
|
|
299
352
|
configState.config = config;
|
|
300
353
|
readState.data = {active: true, age: 1, email: "e@x.com", name: "Name"};
|
|
301
354
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
302
|
-
setOptions.mockImplementation((opts:
|
|
355
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
303
356
|
if (opts?.headerRight) {
|
|
304
357
|
savedHeaderRight = opts.headerRight();
|
|
305
358
|
}
|
|
306
359
|
});
|
|
307
360
|
renderWithTheme(
|
|
308
|
-
<AdminModelForm
|
|
361
|
+
<AdminModelForm
|
|
362
|
+
api={{} as unknown as AdminApi}
|
|
363
|
+
baseUrl="/admin"
|
|
364
|
+
itemId="u1"
|
|
365
|
+
mode="edit"
|
|
366
|
+
modelName="User"
|
|
367
|
+
/>
|
|
309
368
|
);
|
|
310
369
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
311
370
|
// Open confirmation modal.
|
|
@@ -333,13 +392,19 @@ describe("AdminModelForm", () => {
|
|
|
333
392
|
},
|
|
334
393
|
}));
|
|
335
394
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
336
|
-
setOptions.mockImplementation((opts:
|
|
395
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
337
396
|
if (opts?.headerRight) {
|
|
338
397
|
savedHeaderRight = opts.headerRight();
|
|
339
398
|
}
|
|
340
399
|
});
|
|
341
400
|
renderWithTheme(
|
|
342
|
-
<AdminModelForm
|
|
401
|
+
<AdminModelForm
|
|
402
|
+
api={{} as unknown as AdminApi}
|
|
403
|
+
baseUrl="/admin"
|
|
404
|
+
itemId="u1"
|
|
405
|
+
mode="edit"
|
|
406
|
+
modelName="User"
|
|
407
|
+
/>
|
|
343
408
|
);
|
|
344
409
|
// The header render should still succeed in an error-flagged scenario.
|
|
345
410
|
expect(savedHeaderRight).toBeDefined();
|
|
@@ -354,13 +419,19 @@ describe("AdminModelForm", () => {
|
|
|
354
419
|
},
|
|
355
420
|
}));
|
|
356
421
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
357
|
-
setOptions.mockImplementation((opts:
|
|
422
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
358
423
|
if (opts?.headerRight) {
|
|
359
424
|
savedHeaderRight = opts.headerRight();
|
|
360
425
|
}
|
|
361
426
|
});
|
|
362
427
|
renderWithTheme(
|
|
363
|
-
<AdminModelForm
|
|
428
|
+
<AdminModelForm
|
|
429
|
+
api={{} as unknown as AdminApi}
|
|
430
|
+
baseUrl="/admin"
|
|
431
|
+
itemId="u1"
|
|
432
|
+
mode="edit"
|
|
433
|
+
modelName="User"
|
|
434
|
+
/>
|
|
364
435
|
);
|
|
365
436
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
366
437
|
await act(async () => {
|
|
@@ -394,13 +465,19 @@ describe("AdminModelForm", () => {
|
|
|
394
465
|
tags: ["a", null, "b"],
|
|
395
466
|
};
|
|
396
467
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
397
|
-
setOptions.mockImplementation((opts:
|
|
468
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
398
469
|
if (opts?.headerRight) {
|
|
399
470
|
savedHeaderRight = opts.headerRight();
|
|
400
471
|
}
|
|
401
472
|
});
|
|
402
473
|
renderWithTheme(
|
|
403
|
-
<AdminModelForm
|
|
474
|
+
<AdminModelForm
|
|
475
|
+
api={{} as unknown as AdminApi}
|
|
476
|
+
baseUrl="/admin"
|
|
477
|
+
itemId="u1"
|
|
478
|
+
mode="edit"
|
|
479
|
+
modelName="User"
|
|
480
|
+
/>
|
|
404
481
|
);
|
|
405
482
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
406
483
|
await act(async () => {
|
|
@@ -408,7 +485,7 @@ describe("AdminModelForm", () => {
|
|
|
408
485
|
await new Promise((r) => setTimeout(r, 600));
|
|
409
486
|
});
|
|
410
487
|
expect(updateFn).toHaveBeenCalled();
|
|
411
|
-
const body = updateFn.mock.calls[0][0] as {body:
|
|
488
|
+
const body = updateFn.mock.calls[0][0] as {body: Record<string, unknown>; id: string};
|
|
412
489
|
// Array was stripped of null entries.
|
|
413
490
|
expect(body.body.tags).toEqual(["a", "b"]);
|
|
414
491
|
});
|
|
@@ -425,7 +502,12 @@ describe("AdminModelForm", () => {
|
|
|
425
502
|
],
|
|
426
503
|
};
|
|
427
504
|
const {getByTestId} = renderWithTheme(
|
|
428
|
-
<AdminModelForm
|
|
505
|
+
<AdminModelForm
|
|
506
|
+
api={{} as unknown as AdminApi}
|
|
507
|
+
baseUrl="/admin"
|
|
508
|
+
mode="create"
|
|
509
|
+
modelName="User"
|
|
510
|
+
/>
|
|
429
511
|
);
|
|
430
512
|
const nameField = getByTestId("admin-field-name");
|
|
431
513
|
await act(async () => {
|
|
@@ -452,7 +534,12 @@ describe("AdminModelForm", () => {
|
|
|
452
534
|
],
|
|
453
535
|
};
|
|
454
536
|
const {toJSON} = renderWithTheme(
|
|
455
|
-
<AdminModelForm
|
|
537
|
+
<AdminModelForm
|
|
538
|
+
api={{} as unknown as AdminApi}
|
|
539
|
+
baseUrl="/admin"
|
|
540
|
+
mode="create"
|
|
541
|
+
modelName="User"
|
|
542
|
+
/>
|
|
456
543
|
);
|
|
457
544
|
expect(toJSON()).toBeDefined();
|
|
458
545
|
});
|
|
@@ -464,23 +551,29 @@ describe("AdminModelForm", () => {
|
|
|
464
551
|
deleteFn.mockReset();
|
|
465
552
|
deleteFn.mockImplementation(() => ({unwrap: async () => ({})}));
|
|
466
553
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
467
|
-
setOptions.mockImplementation((opts:
|
|
554
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
468
555
|
if (opts?.headerRight) {
|
|
469
556
|
savedHeaderRight = opts.headerRight();
|
|
470
557
|
}
|
|
471
558
|
});
|
|
472
559
|
const {UNSAFE_root} = renderWithTheme(
|
|
473
|
-
<AdminModelForm
|
|
560
|
+
<AdminModelForm
|
|
561
|
+
api={{} as unknown as AdminApi}
|
|
562
|
+
baseUrl="/admin"
|
|
563
|
+
itemId="u1"
|
|
564
|
+
mode="edit"
|
|
565
|
+
modelName="User"
|
|
566
|
+
/>
|
|
474
567
|
);
|
|
475
568
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
476
569
|
// Invoke the delete Button's onClick callback directly so we exercise
|
|
477
570
|
// handleDelete's success branch (calls deleteItem + router.back).
|
|
478
571
|
const deleteBtns = header.UNSAFE_root.findAll(
|
|
479
|
-
(n:
|
|
572
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-delete-button"
|
|
480
573
|
);
|
|
481
574
|
expect(deleteBtns.length).toBeGreaterThan(0);
|
|
482
575
|
await act(async () => {
|
|
483
|
-
(deleteBtns[0] as
|
|
576
|
+
(deleteBtns[0] as ReactTestInstance).props.onClick();
|
|
484
577
|
await new Promise((r) => setTimeout(r, 50));
|
|
485
578
|
});
|
|
486
579
|
expect(deleteFn).toHaveBeenCalledWith("u1");
|
|
@@ -498,20 +591,26 @@ describe("AdminModelForm", () => {
|
|
|
498
591
|
},
|
|
499
592
|
}));
|
|
500
593
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
501
|
-
setOptions.mockImplementation((opts:
|
|
594
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
502
595
|
if (opts?.headerRight) {
|
|
503
596
|
savedHeaderRight = opts.headerRight();
|
|
504
597
|
}
|
|
505
598
|
});
|
|
506
599
|
renderWithTheme(
|
|
507
|
-
<AdminModelForm
|
|
600
|
+
<AdminModelForm
|
|
601
|
+
api={{} as unknown as AdminApi}
|
|
602
|
+
baseUrl="/admin"
|
|
603
|
+
itemId="u1"
|
|
604
|
+
mode="edit"
|
|
605
|
+
modelName="User"
|
|
606
|
+
/>
|
|
508
607
|
);
|
|
509
608
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
510
609
|
const deleteBtns = header.UNSAFE_root.findAll(
|
|
511
|
-
(n:
|
|
610
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-delete-button"
|
|
512
611
|
);
|
|
513
612
|
await act(async () => {
|
|
514
|
-
(deleteBtns[0] as
|
|
613
|
+
(deleteBtns[0] as ReactTestInstance).props.onClick();
|
|
515
614
|
await new Promise((r) => setTimeout(r, 50));
|
|
516
615
|
});
|
|
517
616
|
expect(deleteFn).toHaveBeenCalled();
|
|
@@ -523,13 +622,19 @@ describe("AdminModelForm", () => {
|
|
|
523
622
|
configState.config = config;
|
|
524
623
|
readState.data = {active: true, age: 1, email: "e@x.com", name: "Name"};
|
|
525
624
|
let savedHeaderRight: React.ReactElement | null = null;
|
|
526
|
-
setOptions.mockImplementation((opts:
|
|
625
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
527
626
|
if (opts?.headerRight) {
|
|
528
627
|
savedHeaderRight = opts.headerRight();
|
|
529
628
|
}
|
|
530
629
|
});
|
|
531
630
|
renderWithTheme(
|
|
532
|
-
<AdminModelForm
|
|
631
|
+
<AdminModelForm
|
|
632
|
+
api={{} as unknown as AdminApi}
|
|
633
|
+
baseUrl="/admin"
|
|
634
|
+
itemId="u1"
|
|
635
|
+
mode="edit"
|
|
636
|
+
modelName="User"
|
|
637
|
+
/>
|
|
533
638
|
);
|
|
534
639
|
const header = renderWithTheme(savedHeaderRight as unknown as React.ReactElement);
|
|
535
640
|
await act(async () => {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
3
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
4
5
|
import React from "react";
|
|
6
|
+
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
5
7
|
|
|
6
8
|
const routerPush = mock(() => {});
|
|
7
9
|
mock.module("expo-router", () => ({
|
|
8
10
|
router: {push: routerPush},
|
|
9
11
|
}));
|
|
10
12
|
|
|
11
|
-
const mockConfigState: {data:
|
|
13
|
+
const mockConfigState: {data: AdminConfigResponse | null; error: unknown; isLoading: boolean} = {
|
|
12
14
|
data: null,
|
|
13
15
|
error: null,
|
|
14
16
|
isLoading: false,
|
|
@@ -51,13 +53,17 @@ describe("AdminModelList", () => {
|
|
|
51
53
|
|
|
52
54
|
it("renders a spinner while loading", () => {
|
|
53
55
|
mockConfigState.isLoading = true;
|
|
54
|
-
const {toJSON} = renderWithTheme(
|
|
56
|
+
const {toJSON} = renderWithTheme(
|
|
57
|
+
<AdminModelList api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
58
|
+
);
|
|
55
59
|
expect(toJSON()).toBeDefined();
|
|
56
60
|
});
|
|
57
61
|
|
|
58
62
|
it("renders an error message when loading fails", () => {
|
|
59
63
|
mockConfigState.error = new Error("boom");
|
|
60
|
-
const {toJSON} = renderWithTheme(
|
|
64
|
+
const {toJSON} = renderWithTheme(
|
|
65
|
+
<AdminModelList api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
66
|
+
);
|
|
61
67
|
expect(toJSON()).toBeDefined();
|
|
62
68
|
});
|
|
63
69
|
|
|
@@ -65,7 +71,7 @@ describe("AdminModelList", () => {
|
|
|
65
71
|
mockConfigState.data = baseConfig;
|
|
66
72
|
const {toJSON} = renderWithTheme(
|
|
67
73
|
<AdminModelList
|
|
68
|
-
api={{} as
|
|
74
|
+
api={{} as unknown as AdminApi}
|
|
69
75
|
baseUrl="/admin"
|
|
70
76
|
configurationPath="/admin/configuration"
|
|
71
77
|
customScreens={[{displayName: "Local", name: "local-screen"}]}
|
|
@@ -76,7 +82,9 @@ describe("AdminModelList", () => {
|
|
|
76
82
|
|
|
77
83
|
it("renders the model grid when config has no scripts/custom screens", () => {
|
|
78
84
|
mockConfigState.data = {...baseConfig, customScreens: [], scripts: []};
|
|
79
|
-
const {toJSON} = renderWithTheme(
|
|
85
|
+
const {toJSON} = renderWithTheme(
|
|
86
|
+
<AdminModelList api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
87
|
+
);
|
|
80
88
|
expect(toJSON()).toBeDefined();
|
|
81
89
|
});
|
|
82
90
|
});
|