@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,17 +1,20 @@
|
|
|
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 routerPush = mock(() => {});
|
|
8
|
-
const setOptions = mock((_:
|
|
11
|
+
const setOptions = mock((_: unknown) => {});
|
|
9
12
|
mock.module("expo-router", () => ({
|
|
10
13
|
router: {push: routerPush},
|
|
11
14
|
useNavigation: () => ({setOptions}),
|
|
12
15
|
}));
|
|
13
16
|
|
|
14
|
-
const configState: {config:
|
|
17
|
+
const configState: {config: AdminConfigResponse | null; isLoading: boolean} = {
|
|
15
18
|
config: null,
|
|
16
19
|
isLoading: false,
|
|
17
20
|
};
|
|
@@ -23,7 +26,7 @@ mock.module("./useAdminConfig", () => ({
|
|
|
23
26
|
}),
|
|
24
27
|
}));
|
|
25
28
|
|
|
26
|
-
const listState: {data:
|
|
29
|
+
const listState: {data: unknown; isLoading: boolean} = {
|
|
27
30
|
data: {data: [], total: 0},
|
|
28
31
|
isLoading: false,
|
|
29
32
|
};
|
|
@@ -80,7 +83,7 @@ describe("AdminModelTable", () => {
|
|
|
80
83
|
it("renders loading page while config is loading", () => {
|
|
81
84
|
configState.isLoading = true;
|
|
82
85
|
const {toJSON} = renderWithTheme(
|
|
83
|
-
<AdminModelTable api={{} as
|
|
86
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
84
87
|
);
|
|
85
88
|
expect(toJSON()).toBeDefined();
|
|
86
89
|
});
|
|
@@ -88,7 +91,7 @@ describe("AdminModelTable", () => {
|
|
|
88
91
|
it("renders loading page when model config is missing", () => {
|
|
89
92
|
configState.config = {customScreens: [], models: [], scripts: []};
|
|
90
93
|
const {toJSON} = renderWithTheme(
|
|
91
|
-
<AdminModelTable api={{} as
|
|
94
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
92
95
|
);
|
|
93
96
|
expect(toJSON()).toBeDefined();
|
|
94
97
|
});
|
|
@@ -96,7 +99,7 @@ describe("AdminModelTable", () => {
|
|
|
96
99
|
it("renders empty state when no data present", () => {
|
|
97
100
|
configState.config = fullConfig;
|
|
98
101
|
const {toJSON} = renderWithTheme(
|
|
99
|
-
<AdminModelTable api={{} as
|
|
102
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
100
103
|
);
|
|
101
104
|
expect(toJSON()).toBeDefined();
|
|
102
105
|
expect(setOptions).toHaveBeenCalled();
|
|
@@ -106,7 +109,7 @@ describe("AdminModelTable", () => {
|
|
|
106
109
|
configState.config = fullConfig;
|
|
107
110
|
listState.isLoading = true;
|
|
108
111
|
const {toJSON} = renderWithTheme(
|
|
109
|
-
<AdminModelTable api={{} as
|
|
112
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
110
113
|
);
|
|
111
114
|
expect(toJSON()).toBeDefined();
|
|
112
115
|
});
|
|
@@ -135,7 +138,7 @@ describe("AdminModelTable", () => {
|
|
|
135
138
|
total: 2,
|
|
136
139
|
};
|
|
137
140
|
const {toJSON} = renderWithTheme(
|
|
138
|
-
<AdminModelTable api={{} as
|
|
141
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
139
142
|
);
|
|
140
143
|
expect(toJSON()).toBeDefined();
|
|
141
144
|
});
|
|
@@ -147,7 +150,12 @@ describe("AdminModelTable", () => {
|
|
|
147
150
|
total: 1,
|
|
148
151
|
};
|
|
149
152
|
const {toJSON} = renderWithTheme(
|
|
150
|
-
<AdminModelTable
|
|
153
|
+
<AdminModelTable
|
|
154
|
+
api={{} as unknown as AdminApi}
|
|
155
|
+
baseUrl="/admin"
|
|
156
|
+
columns={["email"]}
|
|
157
|
+
modelName="User"
|
|
158
|
+
/>
|
|
151
159
|
);
|
|
152
160
|
expect(toJSON()).toBeDefined();
|
|
153
161
|
});
|
|
@@ -188,7 +196,7 @@ describe("AdminModelTable", () => {
|
|
|
188
196
|
total: 1,
|
|
189
197
|
};
|
|
190
198
|
const {toJSON} = renderWithTheme(
|
|
191
|
-
<AdminModelTable api={{} as
|
|
199
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="Plain" />
|
|
192
200
|
);
|
|
193
201
|
expect(toJSON()).toBeDefined();
|
|
194
202
|
});
|
|
@@ -196,12 +204,14 @@ describe("AdminModelTable", () => {
|
|
|
196
204
|
it("renders the headerRight create button and pushes to the create route on click", async () => {
|
|
197
205
|
configState.config = fullConfig;
|
|
198
206
|
let headerRight: React.ReactElement | null = null;
|
|
199
|
-
setOptions.mockImplementation((opts:
|
|
207
|
+
setOptions.mockImplementation((opts: Record<string, unknown>) => {
|
|
200
208
|
if (opts?.headerRight) {
|
|
201
209
|
headerRight = opts.headerRight();
|
|
202
210
|
}
|
|
203
211
|
});
|
|
204
|
-
renderWithTheme(
|
|
212
|
+
renderWithTheme(
|
|
213
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
214
|
+
);
|
|
205
215
|
expect(headerRight).not.toBeNull();
|
|
206
216
|
const header = renderWithTheme(headerRight as unknown as React.ReactElement);
|
|
207
217
|
await act(async () => {
|
|
@@ -224,16 +234,16 @@ describe("AdminModelTable", () => {
|
|
|
224
234
|
},
|
|
225
235
|
}));
|
|
226
236
|
const {UNSAFE_root} = renderWithTheme(
|
|
227
|
-
<AdminModelTable api={{} as
|
|
237
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
228
238
|
);
|
|
229
239
|
// Find the actions cellData.onDelete handler and invoke it directly.
|
|
230
|
-
const nodes = UNSAFE_root.findAll((n:
|
|
240
|
+
const nodes = UNSAFE_root.findAll((n: ReactTestInstance) => {
|
|
231
241
|
const v = n.props?.cellData?.value;
|
|
232
242
|
return v && typeof v.onDelete === "function" && v.id === "u1";
|
|
233
243
|
});
|
|
234
244
|
expect(nodes.length).toBeGreaterThan(0);
|
|
235
245
|
await act(async () => {
|
|
236
|
-
(nodes[0] as
|
|
246
|
+
(nodes[0] as ReactTestInstance).props.cellData.value.onDelete("u1");
|
|
237
247
|
await new Promise((r) => setTimeout(r, 50));
|
|
238
248
|
});
|
|
239
249
|
expect(deleteFn).toHaveBeenCalled();
|
|
@@ -244,16 +254,19 @@ describe("AdminModelTable", () => {
|
|
|
244
254
|
listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
|
|
245
255
|
const {UNSAFE_root} = renderWithTheme(
|
|
246
256
|
<AdminModelTable
|
|
247
|
-
api={{} as
|
|
257
|
+
api={{} as unknown as AdminApi}
|
|
248
258
|
baseUrl="/admin"
|
|
249
259
|
columnWidths={{email: 999}}
|
|
250
260
|
modelName="User"
|
|
251
261
|
/>
|
|
252
262
|
);
|
|
253
|
-
const tables = UNSAFE_root.findAll((n:
|
|
263
|
+
const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
|
|
254
264
|
expect(tables.length).toBeGreaterThan(0);
|
|
255
|
-
const cols = (tables[0] as
|
|
256
|
-
|
|
265
|
+
const cols = (tables[0] as ReactTestInstance).props.columns as {
|
|
266
|
+
title: string;
|
|
267
|
+
width?: number;
|
|
268
|
+
}[];
|
|
269
|
+
const emailCol = cols.find((c) => c.title === "Email");
|
|
257
270
|
expect(emailCol?.width).toBe(999);
|
|
258
271
|
});
|
|
259
272
|
|
|
@@ -270,11 +283,14 @@ describe("AdminModelTable", () => {
|
|
|
270
283
|
};
|
|
271
284
|
listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
|
|
272
285
|
const {UNSAFE_root} = renderWithTheme(
|
|
273
|
-
<AdminModelTable api={{} as
|
|
286
|
+
<AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
|
|
274
287
|
);
|
|
275
|
-
const tables = UNSAFE_root.findAll((n:
|
|
276
|
-
const cols = (tables[0] as
|
|
277
|
-
|
|
288
|
+
const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
|
|
289
|
+
const cols = (tables[0] as ReactTestInstance).props.columns as {
|
|
290
|
+
title: string;
|
|
291
|
+
width?: number;
|
|
292
|
+
}[];
|
|
293
|
+
const emailCol = cols.find((c) => c.title === "Email");
|
|
278
294
|
expect(emailCol?.width).toBe(555);
|
|
279
295
|
});
|
|
280
296
|
|
|
@@ -292,15 +308,18 @@ describe("AdminModelTable", () => {
|
|
|
292
308
|
listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
|
|
293
309
|
const {UNSAFE_root} = renderWithTheme(
|
|
294
310
|
<AdminModelTable
|
|
295
|
-
api={{} as
|
|
311
|
+
api={{} as unknown as AdminApi}
|
|
296
312
|
baseUrl="/admin"
|
|
297
313
|
columnWidths={{email: 200}}
|
|
298
314
|
modelName="User"
|
|
299
315
|
/>
|
|
300
316
|
);
|
|
301
|
-
const tables = UNSAFE_root.findAll((n:
|
|
302
|
-
const cols = (tables[0] as
|
|
303
|
-
|
|
317
|
+
const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
|
|
318
|
+
const cols = (tables[0] as ReactTestInstance).props.columns as {
|
|
319
|
+
title: string;
|
|
320
|
+
width?: number;
|
|
321
|
+
}[];
|
|
322
|
+
const emailCol = cols.find((c) => c.title === "Email");
|
|
304
323
|
expect(emailCol?.width).toBe(200);
|
|
305
324
|
});
|
|
306
325
|
|
|
@@ -314,18 +333,25 @@ describe("AdminModelTable", () => {
|
|
|
314
333
|
total: 1,
|
|
315
334
|
};
|
|
316
335
|
const {UNSAFE_root, toJSON} = renderWithTheme(
|
|
317
|
-
<AdminModelTable
|
|
336
|
+
<AdminModelTable
|
|
337
|
+
api={{} as unknown as AdminApi}
|
|
338
|
+
baseUrl="/admin"
|
|
339
|
+
columns={["email"]}
|
|
340
|
+
modelName="User"
|
|
341
|
+
/>
|
|
318
342
|
);
|
|
319
343
|
// Grab setSortColumn from the rendered DataTable and apply a sort with
|
|
320
344
|
// direction "desc" on column 0 (valid) and then column 5 (out of range).
|
|
321
|
-
const table = UNSAFE_root.findAll(
|
|
345
|
+
const table = UNSAFE_root.findAll(
|
|
346
|
+
(n: ReactTestInstance) => typeof n.props?.setSortColumn === "function"
|
|
347
|
+
);
|
|
322
348
|
expect(table.length).toBeGreaterThan(0);
|
|
323
349
|
await act(async () => {
|
|
324
|
-
(table[0] as
|
|
350
|
+
(table[0] as ReactTestInstance).props.setSortColumn({column: 0, direction: "desc"});
|
|
325
351
|
await new Promise((r) => setTimeout(r, 10));
|
|
326
352
|
});
|
|
327
353
|
await act(async () => {
|
|
328
|
-
(table[0] as
|
|
354
|
+
(table[0] as ReactTestInstance).props.setSortColumn({column: 99, direction: "asc"});
|
|
329
355
|
await new Promise((r) => setTimeout(r, 10));
|
|
330
356
|
});
|
|
331
357
|
expect(toJSON()).toBeDefined();
|
|
@@ -107,6 +107,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
|
|
|
107
107
|
}, [api, routePath, searchEndpointKey, readEndpointKey]);
|
|
108
108
|
|
|
109
109
|
const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
110
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
110
111
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
111
112
|
const enhanced = enhancedApi as any;
|
|
112
113
|
const useSearchQuery = enhanced[`use${capitalize(searchEndpointKey)}Query`];
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and mock.calls access
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
import {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";
|
|
6
8
|
import {AdminPrimitiveArrayField} from "./AdminPrimitiveArrayField";
|
|
9
|
+
import type {AdminApi} from "./types";
|
|
7
10
|
|
|
8
|
-
const press = async (el:
|
|
11
|
+
const press = async (el: ReactTestInstance): Promise<void> => {
|
|
9
12
|
await act(async () => {
|
|
10
13
|
fireEvent.press(el);
|
|
11
14
|
await new Promise((r) => setTimeout(r, 150));
|
|
12
15
|
});
|
|
13
16
|
};
|
|
14
17
|
|
|
15
|
-
const mockApi
|
|
18
|
+
const mockApi = {
|
|
16
19
|
endpoints: {},
|
|
17
20
|
reducerPath: "test",
|
|
18
|
-
};
|
|
21
|
+
} as unknown as AdminApi;
|
|
19
22
|
|
|
20
23
|
describe("AdminPrimitiveArrayField", () => {
|
|
21
24
|
it("renders empty state when no items", () => {
|
|
@@ -64,7 +67,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
64
67
|
);
|
|
65
68
|
await press(getByTestId("admin-array-add-Tags"));
|
|
66
69
|
expect(onChange).toHaveBeenCalled();
|
|
67
|
-
const next = (onChange.mock.calls[0] as
|
|
70
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
68
71
|
expect(next).toEqual(["foo", ""]);
|
|
69
72
|
});
|
|
70
73
|
|
|
@@ -82,7 +85,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
82
85
|
);
|
|
83
86
|
await press(getByTestId("admin-array-remove-1"));
|
|
84
87
|
expect(onChange).toHaveBeenCalled();
|
|
85
|
-
const next = (onChange.mock.calls[0] as
|
|
88
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
86
89
|
expect(next).toEqual(["a", "c"]);
|
|
87
90
|
});
|
|
88
91
|
|
|
@@ -100,7 +103,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
100
103
|
);
|
|
101
104
|
fireEvent.changeText(getByTestId("admin-array-item-0"), "new");
|
|
102
105
|
expect(onChange).toHaveBeenCalled();
|
|
103
|
-
const next = (onChange.mock.calls[0] as
|
|
106
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
104
107
|
expect(next).toEqual(["new"]);
|
|
105
108
|
});
|
|
106
109
|
|
|
@@ -117,7 +120,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
117
120
|
/>
|
|
118
121
|
);
|
|
119
122
|
fireEvent.changeText(getByTestId("admin-array-item-0"), "42");
|
|
120
|
-
const next = (onChange.mock.calls[0] as
|
|
123
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
121
124
|
expect(next).toEqual([42, 2]);
|
|
122
125
|
});
|
|
123
126
|
|
|
@@ -134,7 +137,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
134
137
|
/>
|
|
135
138
|
);
|
|
136
139
|
await press(getByTestId("admin-array-add-Flags"));
|
|
137
|
-
const next = (onChange.mock.calls[0] as
|
|
140
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
138
141
|
expect(next).toEqual([false]);
|
|
139
142
|
});
|
|
140
143
|
|
|
@@ -151,7 +154,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
151
154
|
/>
|
|
152
155
|
);
|
|
153
156
|
await press(getByTestId("admin-array-add-Scores"));
|
|
154
|
-
const next = (onChange.mock.calls[0] as
|
|
157
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
155
158
|
expect(next).toEqual([0]);
|
|
156
159
|
});
|
|
157
160
|
|
|
@@ -179,7 +182,7 @@ describe("AdminPrimitiveArrayField", () => {
|
|
|
179
182
|
itemType="string"
|
|
180
183
|
onChange={() => {}}
|
|
181
184
|
title="Tags"
|
|
182
|
-
value={undefined as
|
|
185
|
+
value={undefined as unknown as string[]}
|
|
183
186
|
/>
|
|
184
187
|
);
|
|
185
188
|
expect(toJSON()).toBeDefined();
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
|
|
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";
|
|
5
6
|
import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
|
|
6
7
|
import {AdminScriptList} from "./AdminScriptList";
|
|
8
|
+
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
7
9
|
|
|
8
10
|
// Mock useAdminConfig to control returned data
|
|
9
11
|
const mockUseAdminConfig = mock(() => ({
|
|
10
|
-
config: null as
|
|
11
|
-
error: null as
|
|
12
|
+
config: null as AdminConfigResponse | null,
|
|
13
|
+
error: null as Error | null,
|
|
12
14
|
isLoading: false,
|
|
13
15
|
}));
|
|
14
16
|
|
|
15
17
|
mock.module("./useAdminConfig", () => ({
|
|
16
|
-
useAdminConfig: (...args:
|
|
18
|
+
useAdminConfig: (...args: unknown[]) => mockUseAdminConfig(...args),
|
|
17
19
|
}));
|
|
18
20
|
|
|
19
21
|
const modalCallbacks: {
|
|
@@ -36,7 +38,7 @@ mock.module("./AdminScriptRunModal", () => ({
|
|
|
36
38
|
},
|
|
37
39
|
}));
|
|
38
40
|
|
|
39
|
-
const mockApi = {} as
|
|
41
|
+
const mockApi = {} as unknown as AdminApi;
|
|
40
42
|
|
|
41
43
|
describe("AdminScriptList", () => {
|
|
42
44
|
beforeEach(() => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
|
|
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 * as terrenoUi from "@terreno/ui";
|
|
@@ -5,6 +6,7 @@ import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
|
5
6
|
import React from "react";
|
|
6
7
|
import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
|
|
7
8
|
import {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
9
|
+
import type {AdminApi} from "./types";
|
|
8
10
|
|
|
9
11
|
// Render Modal children inline so we can interact with them in tests
|
|
10
12
|
mock.module("@terreno/ui", () => ({
|
|
@@ -27,10 +29,10 @@ const mockUseAdminScripts = mock(() => ({
|
|
|
27
29
|
}));
|
|
28
30
|
|
|
29
31
|
mock.module("./useAdminScripts", () => ({
|
|
30
|
-
useAdminScripts: (...args:
|
|
32
|
+
useAdminScripts: (...args: unknown[]) => mockUseAdminScripts(...args),
|
|
31
33
|
}));
|
|
32
34
|
|
|
33
|
-
const mockApi = {} as
|
|
35
|
+
const mockApi = {} as unknown as AdminApi;
|
|
34
36
|
|
|
35
37
|
describe("AdminScriptRunModal", () => {
|
|
36
38
|
beforeEach(() => {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic endpoint builders
|
|
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} from "./types";
|
|
6
9
|
|
|
7
10
|
const routerBack = mock(() => {});
|
|
8
11
|
mock.module("expo-router", () => ({
|
|
@@ -10,10 +13,10 @@ mock.module("expo-router", () => ({
|
|
|
10
13
|
}));
|
|
11
14
|
|
|
12
15
|
interface ApiState {
|
|
13
|
-
data:
|
|
16
|
+
data: Record<string, unknown> | null;
|
|
14
17
|
error: unknown;
|
|
15
18
|
isLoading: boolean;
|
|
16
|
-
updateImpl: (body:
|
|
19
|
+
updateImpl: (body: unknown) => Promise<unknown>;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
const apiState: ApiState = {
|
|
@@ -23,20 +26,20 @@ const apiState: ApiState = {
|
|
|
23
26
|
updateImpl: async () => ({}),
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
const updateCalls:
|
|
27
|
-
const querySpecs:
|
|
28
|
-
const mutationSpecs:
|
|
29
|
+
const updateCalls: unknown[] = [];
|
|
30
|
+
const querySpecs: unknown[] = [];
|
|
31
|
+
const mutationSpecs: unknown[] = [];
|
|
29
32
|
const makeApi = () => ({
|
|
30
|
-
injectEndpoints: ({endpoints}: {endpoints: (b:
|
|
33
|
+
injectEndpoints: ({endpoints}: {endpoints: (b: unknown) => Record<string, unknown>}) => {
|
|
31
34
|
const build = {
|
|
32
|
-
mutation: (spec:
|
|
35
|
+
mutation: (spec: Record<string, unknown>) => {
|
|
33
36
|
// Invoke the mutation's query lambda so the URL + body builder runs.
|
|
34
37
|
if (typeof spec?.query === "function") {
|
|
35
38
|
mutationSpecs.push(spec.query({demo: true}));
|
|
36
39
|
}
|
|
37
40
|
return spec;
|
|
38
41
|
},
|
|
39
|
-
query: (spec:
|
|
42
|
+
query: (spec: Record<string, unknown>) => {
|
|
40
43
|
// Invoke the query lambda so the request descriptor builder runs.
|
|
41
44
|
if (typeof spec?.query === "function") {
|
|
42
45
|
querySpecs.push(spec.query());
|
|
@@ -52,7 +55,7 @@ const makeApi = () => ({
|
|
|
52
55
|
isLoading: apiState.isLoading,
|
|
53
56
|
}),
|
|
54
57
|
useUpdateVersionConfigMutation: () => [
|
|
55
|
-
(body:
|
|
58
|
+
(body: unknown) => ({
|
|
56
59
|
unwrap: async () => {
|
|
57
60
|
updateCalls.push(body);
|
|
58
61
|
return apiState.updateImpl(body);
|
|
@@ -79,7 +82,7 @@ describe("AdminVersionConfig", () => {
|
|
|
79
82
|
});
|
|
80
83
|
|
|
81
84
|
it("wires the injected query and mutation endpoints to the version-config URL", () => {
|
|
82
|
-
renderWithTheme(<AdminVersionConfig api={makeApi() as
|
|
85
|
+
renderWithTheme(<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />);
|
|
83
86
|
expect(querySpecs.length).toBeGreaterThan(0);
|
|
84
87
|
expect(querySpecs[0]).toEqual({method: "GET", url: "/admin/version-config"});
|
|
85
88
|
expect(mutationSpecs.length).toBeGreaterThan(0);
|
|
@@ -101,11 +104,13 @@ describe("AdminVersionConfig", () => {
|
|
|
101
104
|
webWarningVersion: 4,
|
|
102
105
|
};
|
|
103
106
|
const {UNSAFE_root, getByText} = renderWithTheme(
|
|
104
|
-
<AdminVersionConfig api={makeApi() as
|
|
107
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
108
|
+
);
|
|
109
|
+
const numberNodes = UNSAFE_root.findAll(
|
|
110
|
+
(n: ReactTestInstance) => typeof n.props?.onChange === "function"
|
|
105
111
|
);
|
|
106
|
-
const numberNodes = UNSAFE_root.findAll((n: any) => typeof n.props?.onChange === "function");
|
|
107
112
|
// Fire onChange on every field with an onChange prop so every setState path runs.
|
|
108
|
-
numberNodes.forEach((n:
|
|
113
|
+
numberNodes.forEach((n: ReactTestInstance, index: number) => {
|
|
109
114
|
try {
|
|
110
115
|
n.props.onChange(String(100 + index));
|
|
111
116
|
} catch {
|
|
@@ -122,7 +127,7 @@ describe("AdminVersionConfig", () => {
|
|
|
122
127
|
it("renders loading state", () => {
|
|
123
128
|
apiState.isLoading = true;
|
|
124
129
|
const {toJSON} = renderWithTheme(
|
|
125
|
-
<AdminVersionConfig api={makeApi() as
|
|
130
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
126
131
|
);
|
|
127
132
|
expect(toJSON()).toBeDefined();
|
|
128
133
|
});
|
|
@@ -130,7 +135,7 @@ describe("AdminVersionConfig", () => {
|
|
|
130
135
|
it("renders error state and calls back on press", async () => {
|
|
131
136
|
apiState.error = new Error("boom");
|
|
132
137
|
const {getByText} = renderWithTheme(
|
|
133
|
-
<AdminVersionConfig api={makeApi() as
|
|
138
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
134
139
|
);
|
|
135
140
|
await act(async () => {
|
|
136
141
|
fireEvent.press(getByText("Back"));
|
|
@@ -142,7 +147,7 @@ describe("AdminVersionConfig", () => {
|
|
|
142
147
|
it("populates the form with defaults when data is missing", () => {
|
|
143
148
|
apiState.data = null;
|
|
144
149
|
const {toJSON} = renderWithTheme(
|
|
145
|
-
<AdminVersionConfig api={makeApi() as
|
|
150
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
146
151
|
);
|
|
147
152
|
expect(toJSON()).toBeDefined();
|
|
148
153
|
});
|
|
@@ -159,14 +164,14 @@ describe("AdminVersionConfig", () => {
|
|
|
159
164
|
webWarningVersion: 4,
|
|
160
165
|
};
|
|
161
166
|
const {getByText} = renderWithTheme(
|
|
162
|
-
<AdminVersionConfig api={makeApi() as
|
|
167
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
163
168
|
);
|
|
164
169
|
await act(async () => {
|
|
165
170
|
fireEvent.press(getByText("Save"));
|
|
166
171
|
await new Promise((r) => setTimeout(r, 150));
|
|
167
172
|
});
|
|
168
173
|
expect(updateCalls.length).toBe(1);
|
|
169
|
-
expect(updateCalls[0].updateUrl).toBe("https://x.com");
|
|
174
|
+
expect((updateCalls[0] as Record<string, unknown>).updateUrl).toBe("https://x.com");
|
|
170
175
|
expect(updateCalls[0].pollingIntervalMinutes).toBe(120);
|
|
171
176
|
});
|
|
172
177
|
|
|
@@ -178,14 +183,14 @@ describe("AdminVersionConfig", () => {
|
|
|
178
183
|
webWarningVersion: 0,
|
|
179
184
|
};
|
|
180
185
|
const {getByText} = renderWithTheme(
|
|
181
|
-
<AdminVersionConfig api={makeApi() as
|
|
186
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
182
187
|
);
|
|
183
188
|
await act(async () => {
|
|
184
189
|
fireEvent.press(getByText("Save"));
|
|
185
190
|
await new Promise((r) => setTimeout(r, 150));
|
|
186
191
|
});
|
|
187
192
|
expect(updateCalls.length).toBe(1);
|
|
188
|
-
expect(updateCalls[0].pollingIntervalMinutes).toBe(1440);
|
|
193
|
+
expect((updateCalls[0] as Record<string, unknown>).pollingIntervalMinutes).toBe(1440);
|
|
189
194
|
});
|
|
190
195
|
|
|
191
196
|
it("handles save failures gracefully", async () => {
|
|
@@ -194,7 +199,7 @@ describe("AdminVersionConfig", () => {
|
|
|
194
199
|
throw new Error("server down");
|
|
195
200
|
};
|
|
196
201
|
const {getByText} = renderWithTheme(
|
|
197
|
-
<AdminVersionConfig api={makeApi() as
|
|
202
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
198
203
|
);
|
|
199
204
|
await act(async () => {
|
|
200
205
|
fireEvent.press(getByText("Save"));
|
|
@@ -206,12 +211,12 @@ describe("AdminVersionConfig", () => {
|
|
|
206
211
|
it("sets updateUrl to null when empty", async () => {
|
|
207
212
|
apiState.data = {updateUrl: null};
|
|
208
213
|
const {getByText} = renderWithTheme(
|
|
209
|
-
<AdminVersionConfig api={makeApi() as
|
|
214
|
+
<AdminVersionConfig api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
|
|
210
215
|
);
|
|
211
216
|
await act(async () => {
|
|
212
217
|
fireEvent.press(getByText("Save"));
|
|
213
218
|
await new Promise((r) => setTimeout(r, 150));
|
|
214
219
|
});
|
|
215
|
-
expect(updateCalls[0].updateUrl).toBeNull();
|
|
220
|
+
expect((updateCalls[0] as Record<string, unknown>).updateUrl).toBeNull();
|
|
216
221
|
});
|
|
217
222
|
});
|
|
@@ -48,6 +48,7 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
48
48
|
});
|
|
49
49
|
}, [api, baseUrl]);
|
|
50
50
|
|
|
51
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
51
52
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
52
53
|
const enhanced = enhancedApi as any;
|
|
53
54
|
const useVersionConfigQuery = enhanced.useAdminVersionConfigQuery;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased mock.calls access for assertion
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
import {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";
|
|
6
8
|
import {CheckboxListEditor} from "./CheckboxListEditor";
|
|
7
9
|
|
|
8
|
-
const press = async (el:
|
|
10
|
+
const press = async (el: ReactTestInstance): Promise<void> => {
|
|
9
11
|
await act(async () => {
|
|
10
12
|
fireEvent.press(el);
|
|
11
13
|
await new Promise((r) => setTimeout(r, 150));
|
|
@@ -33,7 +35,7 @@ describe("CheckboxListEditor", () => {
|
|
|
33
35
|
|
|
34
36
|
it("handles non-array values gracefully", () => {
|
|
35
37
|
const {toJSON} = renderWithTheme(
|
|
36
|
-
<CheckboxListEditor onChange={() => {}} value={undefined as
|
|
38
|
+
<CheckboxListEditor onChange={() => {}} value={undefined as unknown as undefined} />
|
|
37
39
|
);
|
|
38
40
|
expect(toJSON()).toBeDefined();
|
|
39
41
|
});
|
|
@@ -43,7 +45,7 @@ describe("CheckboxListEditor", () => {
|
|
|
43
45
|
const {getByTestId} = renderWithTheme(<CheckboxListEditor onChange={onChange} value={[]} />);
|
|
44
46
|
await press(getByTestId("checkbox-add-button"));
|
|
45
47
|
expect(onChange).toHaveBeenCalled();
|
|
46
|
-
const next = (onChange.mock.calls[0] as
|
|
48
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
47
49
|
expect(next).toEqual([{label: "", required: false}]);
|
|
48
50
|
});
|
|
49
51
|
|
|
@@ -60,7 +62,7 @@ describe("CheckboxListEditor", () => {
|
|
|
60
62
|
);
|
|
61
63
|
await press(getByTestId("checkbox-remove-0"));
|
|
62
64
|
expect(onChange).toHaveBeenCalled();
|
|
63
|
-
const next = (onChange.mock.calls[0] as
|
|
65
|
+
const next = (onChange.mock.calls[0] as unknown[])[0];
|
|
64
66
|
expect(next).toHaveLength(1);
|
|
65
67
|
expect(next[0].label).toBe("b");
|
|
66
68
|
});
|
|
@@ -71,11 +73,11 @@ describe("CheckboxListEditor", () => {
|
|
|
71
73
|
<CheckboxListEditor onChange={onChange} value={[{label: "a", required: false}]} />
|
|
72
74
|
);
|
|
73
75
|
fireEvent.changeText(getByTestId("checkbox-label-0"), "new-label");
|
|
74
|
-
const first = (onChange.mock.calls[0] as
|
|
76
|
+
const first = (onChange.mock.calls[0] as unknown[])[0];
|
|
75
77
|
expect(first[0].label).toBe("new-label");
|
|
76
78
|
|
|
77
79
|
fireEvent.changeText(getByTestId("checkbox-prompt-0"), "prompt?");
|
|
78
|
-
const second = (onChange.mock.calls[1] as
|
|
80
|
+
const second = (onChange.mock.calls[1] as unknown[])[0];
|
|
79
81
|
expect(second[0].confirmationPrompt).toBe("prompt?");
|
|
80
82
|
});
|
|
81
83
|
});
|