@terreno/admin-frontend 57.20.0 → 57.21.0
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/CHANGELOG.md +50 -0
- package/dist/AdminFilterDrawer.d.ts.map +1 -1
- package/dist/AdminFilterDrawer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -3
- package/src/AdminBreadcrumbs.test.tsx +1 -1
- package/src/AdminFieldRenderer.test.tsx +2 -1
- package/src/AdminFilterDrawer.tsx +1 -2
- package/src/AdminHome.test.tsx +2 -1
- package/src/AdminModelTable.test.tsx +16 -12
- package/src/AdminModelTable.windowed.test.tsx +11 -5
- package/src/AdminPrimitiveArrayField.test.tsx +3 -3
- package/src/AdminProvider.test.tsx +11 -6
- package/src/AdminRolesList.test.tsx +22 -13
- package/src/AdminScreenPage.test.tsx +1 -1
- package/src/AdminScreenRouter.test.tsx +15 -5
- package/src/AdminScriptList.test.tsx +9 -2
- package/src/AdminShell.test.tsx +1 -1
- package/src/AdminVersionConfig.test.tsx +4 -4
- package/src/AnnouncementOverviewScreenWidget.test.tsx +6 -1
- package/src/CheckboxListEditor.test.tsx +11 -9
- package/src/ConfigurationScreen.test.tsx +2 -2
- package/src/adminRequest.test.ts +3 -3
- package/src/adminWindowedTable.test.ts +4 -2
- package/src/comms/CommsDashboardScreen.test.tsx +5 -5
- package/src/comms/CommsMessageDetail.test.tsx +1 -1
- package/src/index.tsx +2 -0
- package/src/isolated/AdminFieldRenderer.isolated.tsx +11 -6
- package/src/isolated/AdminFilterDrawer.isolated.tsx +8 -6
- package/src/isolated/AdminFilterDrawerMobile.isolated.tsx +3 -1
- package/src/isolated/AdminHomeWidgets.isolated.tsx +2 -0
- package/src/isolated/AdminNestedArrayField.isolated.tsx +10 -9
- package/src/isolated/AdminObjectPicker.isolated.tsx +9 -10
- package/src/isolated/AiPromptsListScreen.isolated.tsx +1 -1
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +16 -8
- package/src/isolated/RecentActivityWidget.isolated.tsx +2 -0
- package/src/isolated/adminWidgets.isolated.tsx +46 -6
- package/src/isolated/aiObservabilityScreens.isolated.tsx +18 -9
- package/src/isolated/generateConsentHistoryPdf.isolated.ts +30 -10
- package/src/isolated/generateConsentPdfsMobile.isolated.ts +24 -3
- package/src/isolated/hooks.isolated.tsx +84 -60
- package/src/isolated/rpcDualRun.isolated.tsx +9 -2
- package/src/jobs/JobsDashboardScreen.test.tsx +3 -3
- package/src/jobs/JobsHomeWidget.test.tsx +1 -1
- package/src/jobs/JobsJobDetail.test.tsx +1 -1
- package/src/orgs/OrgManagementScreens.test.tsx +1 -1
- package/src/orgs/adminModelEndpoints.test.ts +1 -1
- package/src/testing/useAdminApiDouble.ts +2 -1
- package/src/types.ts +2 -0
- package/src/useAdminRpc.test.tsx +3 -3
- package/src/widgets/AIRequestsScreenWidget.test.tsx +20 -3
- package/src/widgets/ModelsGridWidget.test.tsx +25 -5
- package/src/widgets/aiObservability/datasets/AiDatasetDetailView.test.tsx +4 -2
- package/src/widgets/aiObservability/datasets/datasetTypes.test.ts +0 -1
- package/src/widgets/aiObservability/evaluators/AiEvaluatorPanels.test.tsx +89 -23
- package/src/widgets/aiObservability/experiments/AiExperimentNewView.test.tsx +4 -0
- package/src/widgets/aiObservability/shell/ObservabilityTable.test.tsx +7 -1
- package/src/widgets/builtInFieldWidgets.test.tsx +16 -3
|
@@ -214,6 +214,10 @@ const mockTask: {data: {task?: BackgroundTask} | undefined; error: unknown} = {
|
|
|
214
214
|
error: null,
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
// The view reads only a task's status.
|
|
218
|
+
const taskWithStatus = (status: BackgroundTask["status"]): BackgroundTask =>
|
|
219
|
+
({status}) as BackgroundTask;
|
|
220
|
+
|
|
217
221
|
const createApiDouble = (): AdminApi => {
|
|
218
222
|
const api = {
|
|
219
223
|
enhanceEndpoints: () => api,
|
|
@@ -314,9 +318,15 @@ describe("AdminMigrationsView", () => {
|
|
|
314
318
|
config: {
|
|
315
319
|
migrations: {enabled: true},
|
|
316
320
|
models: [],
|
|
317
|
-
platformTools: {
|
|
321
|
+
platformTools: {
|
|
322
|
+
configuration: true,
|
|
323
|
+
roles: true,
|
|
324
|
+
runScripts: false,
|
|
325
|
+
scripts: true,
|
|
326
|
+
version: true,
|
|
327
|
+
},
|
|
318
328
|
scripts: [],
|
|
319
|
-
}
|
|
329
|
+
},
|
|
320
330
|
});
|
|
321
331
|
expect(getByTestId("admin-migrations-dry-run").props.accessibilityState.disabled).toBe(true);
|
|
322
332
|
expect(getByTestId("admin-migrations-apply").props.accessibilityState.disabled).toBe(true);
|
|
@@ -408,7 +418,7 @@ describe("AdminMigrationsView", () => {
|
|
|
408
418
|
});
|
|
409
419
|
|
|
410
420
|
it("disables apply while a queued task is in flight", async () => {
|
|
411
|
-
mockTask.data = {task:
|
|
421
|
+
mockTask.data = {task: taskWithStatus("pending")};
|
|
412
422
|
const {getByTestId, getByText} = renderView();
|
|
413
423
|
await act(async () => {
|
|
414
424
|
fireEvent.press(getByText("Dry run"));
|
|
@@ -418,7 +428,7 @@ describe("AdminMigrationsView", () => {
|
|
|
418
428
|
});
|
|
419
429
|
|
|
420
430
|
it("refetches status after a completed task", async () => {
|
|
421
|
-
mockTask.data = {task:
|
|
431
|
+
mockTask.data = {task: taskWithStatus("completed")};
|
|
422
432
|
const {getByText} = renderView();
|
|
423
433
|
await act(async () => {
|
|
424
434
|
fireEvent.press(getByText("Dry run"));
|
|
@@ -427,7 +437,7 @@ describe("AdminMigrationsView", () => {
|
|
|
427
437
|
});
|
|
428
438
|
|
|
429
439
|
it("keeps apply disabled while a task is running", async () => {
|
|
430
|
-
mockTask.data = {task:
|
|
440
|
+
mockTask.data = {task: taskWithStatus("running")};
|
|
431
441
|
const {getByTestId, getByText} = renderView();
|
|
432
442
|
await act(async () => {
|
|
433
443
|
fireEvent.press(getByText("Dry run"));
|
|
@@ -9,7 +9,7 @@ import {adminScriptsHarness} from "./adminScriptsHarness.test";
|
|
|
9
9
|
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
10
10
|
|
|
11
11
|
// Mock useAdminConfig to control returned data
|
|
12
|
-
const mockUseAdminConfig = mock(() => ({
|
|
12
|
+
const mockUseAdminConfig = mock((..._args: unknown[]) => ({
|
|
13
13
|
config: null as AdminConfigResponse | null,
|
|
14
14
|
error: null as Error | null,
|
|
15
15
|
isLoading: false,
|
|
@@ -342,7 +342,14 @@ describe("AdminScriptList", () => {
|
|
|
342
342
|
mockUseAdminConfig.mockReturnValue({
|
|
343
343
|
config: {
|
|
344
344
|
models: [],
|
|
345
|
-
platformTools: {
|
|
345
|
+
platformTools: {
|
|
346
|
+
configuration: true,
|
|
347
|
+
roles: true,
|
|
348
|
+
runScripts: false,
|
|
349
|
+
scripts: true,
|
|
350
|
+
version: true,
|
|
351
|
+
viewScripts: false,
|
|
352
|
+
},
|
|
346
353
|
scripts: [{description: "Test script", name: "test-script"}],
|
|
347
354
|
},
|
|
348
355
|
error: null,
|
package/src/AdminShell.test.tsx
CHANGED
|
@@ -59,7 +59,7 @@ const setWindowWidth = (width: number): (() => void) => {
|
|
|
59
59
|
useWindowDimensionsMock.mockImplementation(dimensionsImpl);
|
|
60
60
|
|
|
61
61
|
return (): void => {
|
|
62
|
-
useWindowDimensionsMock.mockImplementation(getScaledSize(375));
|
|
62
|
+
useWindowDimensionsMock.mockImplementation?.(getScaledSize(375));
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -26,7 +26,7 @@ const apiState: ApiState = {
|
|
|
26
26
|
updateImpl: async () => ({}),
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const updateCalls: unknown[] = [];
|
|
29
|
+
const updateCalls: Record<string, unknown>[] = [];
|
|
30
30
|
const querySpecs: unknown[] = [];
|
|
31
31
|
const mutationSpecs: unknown[] = [];
|
|
32
32
|
const makeApi = () => ({
|
|
@@ -55,7 +55,7 @@ const makeApi = () => ({
|
|
|
55
55
|
isLoading: apiState.isLoading,
|
|
56
56
|
}),
|
|
57
57
|
useUpdateVersionConfigMutation: () => [
|
|
58
|
-
(body: unknown) => ({
|
|
58
|
+
(body: Record<string, unknown>) => ({
|
|
59
59
|
unwrap: async () => {
|
|
60
60
|
updateCalls.push(body);
|
|
61
61
|
return apiState.updateImpl(body);
|
|
@@ -171,7 +171,7 @@ describe("AdminVersionConfig", () => {
|
|
|
171
171
|
await new Promise((r) => setTimeout(r, 150));
|
|
172
172
|
});
|
|
173
173
|
expect(updateCalls.length).toBe(1);
|
|
174
|
-
expect(
|
|
174
|
+
expect(updateCalls[0].updateUrl).toBe("https://x.com");
|
|
175
175
|
expect(updateCalls[0].pollingIntervalMinutes).toBe(120);
|
|
176
176
|
});
|
|
177
177
|
|
|
@@ -217,6 +217,6 @@ describe("AdminVersionConfig", () => {
|
|
|
217
217
|
fireEvent.press(getByText("Save"));
|
|
218
218
|
await new Promise((r) => setTimeout(r, 150));
|
|
219
219
|
});
|
|
220
|
-
expect(
|
|
220
|
+
expect(updateCalls[0].updateUrl).toBeNull();
|
|
221
221
|
});
|
|
222
222
|
});
|
|
@@ -39,7 +39,12 @@ describe("AnnouncementOverviewScreenWidget", () => {
|
|
|
39
39
|
|
|
40
40
|
it("routes create, edit, and analytics table actions through expo-router", () => {
|
|
41
41
|
renderWithTheme(
|
|
42
|
-
<AnnouncementOverviewScreenWidget
|
|
42
|
+
<AnnouncementOverviewScreenWidget
|
|
43
|
+
api={{} as unknown as AdminApi}
|
|
44
|
+
config={{customScreens: [], models: [], scripts: []}}
|
|
45
|
+
routeBase="/admin"
|
|
46
|
+
screenName="announcements"
|
|
47
|
+
/>
|
|
43
48
|
);
|
|
44
49
|
|
|
45
50
|
assert.strictEqual(capturedOverviewProps?.routeBase, "/admin");
|
|
@@ -7,6 +7,8 @@ import type {ReactTestInstance} from "react-test-renderer";
|
|
|
7
7
|
import {renderWithTheme} from "../../ui/src/test-utils";
|
|
8
8
|
import {CheckboxListEditor} from "./CheckboxListEditor";
|
|
9
9
|
|
|
10
|
+
type CheckboxItem = React.ComponentProps<typeof CheckboxListEditor>["value"][number];
|
|
11
|
+
|
|
10
12
|
const press = async (el: ReactTestInstance): Promise<void> => {
|
|
11
13
|
await act(async () => {
|
|
12
14
|
fireEvent.press(el);
|
|
@@ -35,22 +37,22 @@ describe("CheckboxListEditor", () => {
|
|
|
35
37
|
|
|
36
38
|
it("handles non-array values gracefully", () => {
|
|
37
39
|
const {toJSON} = renderWithTheme(
|
|
38
|
-
<CheckboxListEditor onChange={() => {}} value={undefined as unknown as
|
|
40
|
+
<CheckboxListEditor onChange={() => {}} value={undefined as unknown as CheckboxItem[]} />
|
|
39
41
|
);
|
|
40
42
|
expect(toJSON()).toBeDefined();
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
it("adds a new item when Add is clicked", async () => {
|
|
44
|
-
const onChange = mock((_:
|
|
46
|
+
const onChange = mock((_: CheckboxItem[]) => undefined);
|
|
45
47
|
const {getByTestId} = renderWithTheme(<CheckboxListEditor onChange={onChange} value={[]} />);
|
|
46
48
|
await press(getByTestId("checkbox-add-button"));
|
|
47
49
|
expect(onChange).toHaveBeenCalled();
|
|
48
|
-
const next =
|
|
50
|
+
const next = onChange.mock.calls[0][0];
|
|
49
51
|
expect(next).toEqual([{label: "", required: false}]);
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
it("removes an item when the remove icon is clicked", async () => {
|
|
53
|
-
const onChange = mock((_:
|
|
55
|
+
const onChange = mock((_: CheckboxItem[]) => undefined);
|
|
54
56
|
const {getByTestId} = renderWithTheme(
|
|
55
57
|
<CheckboxListEditor
|
|
56
58
|
onChange={onChange}
|
|
@@ -62,29 +64,29 @@ describe("CheckboxListEditor", () => {
|
|
|
62
64
|
);
|
|
63
65
|
await press(getByTestId("checkbox-remove-0"));
|
|
64
66
|
expect(onChange).toHaveBeenCalled();
|
|
65
|
-
const next =
|
|
67
|
+
const next = onChange.mock.calls[0][0];
|
|
66
68
|
expect(next).toHaveLength(1);
|
|
67
69
|
expect(next[0].label).toBe("b");
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
it("updates a field when label/prompt changes", () => {
|
|
71
|
-
const onChange = mock((_:
|
|
73
|
+
const onChange = mock((_: CheckboxItem[]) => undefined);
|
|
72
74
|
const {getByTestId, UNSAFE_root} = renderWithTheme(
|
|
73
75
|
<CheckboxListEditor onChange={onChange} value={[{label: "a", required: false}]} />
|
|
74
76
|
);
|
|
75
77
|
fireEvent.changeText(getByTestId("checkbox-label-0"), "new-label");
|
|
76
|
-
const first =
|
|
78
|
+
const first = onChange.mock.calls[0][0];
|
|
77
79
|
expect(first[0].label).toBe("new-label");
|
|
78
80
|
|
|
79
81
|
fireEvent.changeText(getByTestId("checkbox-prompt-0"), "prompt?");
|
|
80
|
-
const second =
|
|
82
|
+
const second = onChange.mock.calls[1][0];
|
|
81
83
|
expect(second[0].confirmationPrompt).toBe("prompt?");
|
|
82
84
|
|
|
83
85
|
const requiredField = UNSAFE_root.find(
|
|
84
86
|
(node: ReactTestInstance) => node.props?.title === "Required"
|
|
85
87
|
);
|
|
86
88
|
requiredField.props.onChange(true);
|
|
87
|
-
const third =
|
|
89
|
+
const third = onChange.mock.calls[2][0];
|
|
88
90
|
expect(third[0].required).toBe(true);
|
|
89
91
|
});
|
|
90
92
|
});
|
|
@@ -13,13 +13,13 @@ interface QueryState<T> {
|
|
|
13
13
|
const metaState: QueryState<unknown> = {data: undefined, isLoading: false};
|
|
14
14
|
const valuesState: QueryState<unknown> = {data: undefined, isLoading: false};
|
|
15
15
|
let updateImpl: (body: unknown) => Promise<unknown> = async () => ({});
|
|
16
|
-
const updateCalls: unknown[] = [];
|
|
16
|
+
const updateCalls: Record<string, unknown>[] = [];
|
|
17
17
|
|
|
18
18
|
mock.module("./useConfigurationApi", () => ({
|
|
19
19
|
useConfigurationApi: () => ({
|
|
20
20
|
useMetaQuery: () => ({data: metaState.data, isLoading: metaState.isLoading}),
|
|
21
21
|
useUpdateMutation: () => [
|
|
22
|
-
(body: unknown) => ({
|
|
22
|
+
(body: Record<string, unknown>) => ({
|
|
23
23
|
unwrap: async () => {
|
|
24
24
|
updateCalls.push(body);
|
|
25
25
|
return updateImpl(body);
|
package/src/adminRequest.test.ts
CHANGED
|
@@ -55,7 +55,7 @@ describe("adminRequest", () => {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it("maps 4xx JSON failures to AdminAPIError", async () => {
|
|
58
|
-
globalThis.fetch = (async () => {
|
|
58
|
+
globalThis.fetch = (async (_url: string) => {
|
|
59
59
|
return new Response(JSON.stringify({detail: "q", title: "Invalid filter"}), {
|
|
60
60
|
headers: {"Content-Type": "application/json"},
|
|
61
61
|
status: 400,
|
|
@@ -75,7 +75,7 @@ describe("adminRequest", () => {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
it("maps 5xx failures without JSON to AdminAPIError", async () => {
|
|
78
|
-
globalThis.fetch = (async () => {
|
|
78
|
+
globalThis.fetch = (async (_url: string) => {
|
|
79
79
|
return new Response("nope", {status: 503, statusText: "Service Unavailable"});
|
|
80
80
|
}) as typeof fetch;
|
|
81
81
|
|
|
@@ -115,7 +115,7 @@ describe("adminRequest", () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
it("returns a Blob when parseAs is blob", async () => {
|
|
118
|
-
globalThis.fetch = (async () => {
|
|
118
|
+
globalThis.fetch = (async (_url: string) => {
|
|
119
119
|
return new Response(new Uint8Array([1, 2, 3]), {
|
|
120
120
|
headers: {"Content-Type": "application/pdf"},
|
|
121
121
|
status: 200,
|
|
@@ -4,16 +4,18 @@ import {assert} from "chai";
|
|
|
4
4
|
import {isWindowedAdminTable, resolveWindowedTableRows} from "./adminWindowedTable";
|
|
5
5
|
import type {AdminModelConfig, AdminSyncDb} from "./types";
|
|
6
6
|
|
|
7
|
+
// The gate reads only the broadcast flag, sync collection, and `_id` type.
|
|
7
8
|
const stringIdConfig = {
|
|
8
9
|
adminBroadcast: true,
|
|
9
10
|
fields: {_id: {required: true, type: "string"}, title: {required: true, type: "string"}},
|
|
10
11
|
syncCollection: "todos",
|
|
11
|
-
} as AdminModelConfig;
|
|
12
|
+
} as Partial<AdminModelConfig> as AdminModelConfig;
|
|
12
13
|
|
|
14
|
+
// Test double: the gate only checks that a sync client is present.
|
|
13
15
|
const fakeSyncDb = {
|
|
14
16
|
hydrateWindow: async () => ({hydratedIds: []}),
|
|
15
17
|
store: {getEntity: () => undefined},
|
|
16
|
-
} as AdminSyncDb;
|
|
18
|
+
} as unknown as AdminSyncDb;
|
|
17
19
|
|
|
18
20
|
describe("isWindowedAdminTable", () => {
|
|
19
21
|
it("requires syncDb, fetch client, adminBroadcast, syncCollection, and string _id", () => {
|
|
@@ -5,7 +5,7 @@ import React from "react";
|
|
|
5
5
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
6
6
|
import type {AdminApi} from "../types";
|
|
7
7
|
|
|
8
|
-
const pushMock = mock(() => {});
|
|
8
|
+
const pushMock = mock((_href: unknown) => {});
|
|
9
9
|
mock.module("expo-router", () => ({
|
|
10
10
|
router: {push: pushMock, replace: mock(() => {})},
|
|
11
11
|
useLocalSearchParams: () => ({}),
|
|
@@ -119,7 +119,7 @@ describe("CommsDashboardScreen", () => {
|
|
|
119
119
|
|
|
120
120
|
it("writes filter changes through onFiltersChange for URL persistence", () => {
|
|
121
121
|
listState.data = {data: [], more: false, page: 1, total: 0};
|
|
122
|
-
const onFiltersChange = mock(() => {});
|
|
122
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
123
123
|
const {getByTestId} = renderWithTheme(
|
|
124
124
|
<CommsDashboardScreen
|
|
125
125
|
api={createCommsApi()}
|
|
@@ -139,7 +139,7 @@ describe("CommsDashboardScreen", () => {
|
|
|
139
139
|
|
|
140
140
|
it("keeps both default date bounds when search changes with empty URL dates", () => {
|
|
141
141
|
listState.data = {data: [], more: false, page: 1, total: 0};
|
|
142
|
-
const onFiltersChange = mock(() => {});
|
|
142
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
143
143
|
const {getByTestId} = renderWithTheme(
|
|
144
144
|
<CommsDashboardScreen api={createCommsApi()} filters={{}} onFiltersChange={onFiltersChange} />
|
|
145
145
|
);
|
|
@@ -153,7 +153,7 @@ describe("CommsDashboardScreen", () => {
|
|
|
153
153
|
|
|
154
154
|
it("clears every active filter and returns to the first page", async () => {
|
|
155
155
|
listState.data = {data: [], more: false, page: 3, total: 0};
|
|
156
|
-
const onFiltersChange = mock(() => {});
|
|
156
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
157
157
|
const {getByTestId} = renderWithTheme(
|
|
158
158
|
<CommsDashboardScreen
|
|
159
159
|
api={createCommsApi()}
|
|
@@ -333,7 +333,7 @@ describe("CommsDashboardScreen", () => {
|
|
|
333
333
|
|
|
334
334
|
it("pages through results without dropping the active filters", async () => {
|
|
335
335
|
listState.data = {data: [failedRow], more: true, page: 1, total: 60};
|
|
336
|
-
const onFiltersChange = mock(() => {});
|
|
336
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
337
337
|
const {getByTestId} = renderWithTheme(
|
|
338
338
|
<CommsDashboardScreen
|
|
339
339
|
api={createCommsApi()}
|
|
@@ -4,7 +4,7 @@ import React from "react";
|
|
|
4
4
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
5
5
|
import type {AdminApi} from "../types";
|
|
6
6
|
|
|
7
|
-
const pushMock = mock(() => {});
|
|
7
|
+
const pushMock = mock((_href: unknown) => {});
|
|
8
8
|
mock.module("expo-router", () => ({
|
|
9
9
|
router: {push: pushMock, replace: mock(() => {})},
|
|
10
10
|
}));
|
package/src/index.tsx
CHANGED
|
@@ -138,10 +138,12 @@ export {
|
|
|
138
138
|
useOrgContext,
|
|
139
139
|
} from "./orgs/useOrgContext";
|
|
140
140
|
export type {
|
|
141
|
+
AdminApi,
|
|
141
142
|
AdminCapabilities,
|
|
142
143
|
AdminConfigResponse,
|
|
143
144
|
AdminCustomScreen,
|
|
144
145
|
AdminFieldConfig,
|
|
146
|
+
AdminFieldValue,
|
|
145
147
|
AdminFieldWidgetProps,
|
|
146
148
|
AdminGetAuthHeaders,
|
|
147
149
|
AdminHomeWidgetProps,
|
|
@@ -22,7 +22,7 @@ mock.module("../LocaleContentEditor", () => ({
|
|
|
22
22
|
}));
|
|
23
23
|
|
|
24
24
|
import {AdminFieldRenderer} from "../AdminFieldRenderer";
|
|
25
|
-
import type {AdminApi, AdminFieldConfig} from "../types";
|
|
25
|
+
import type {AdminApi, AdminFieldConfig, RefFieldRendererProps} from "../types";
|
|
26
26
|
|
|
27
27
|
const api = {} as unknown as AdminApi;
|
|
28
28
|
const base = {api, baseUrl: "/admin", onChange: () => {}};
|
|
@@ -175,7 +175,12 @@ describe("AdminFieldRenderer", () => {
|
|
|
175
175
|
const {UNSAFE_root} = renderWithTheme(
|
|
176
176
|
<AdminFieldRenderer
|
|
177
177
|
{...base}
|
|
178
|
-
|
|
178
|
+
// Nullable Mongoose enums arrive with a null entry, which `AdminFieldConfig.enum` does not model.
|
|
179
|
+
fieldConfig={{
|
|
180
|
+
enum: [null, "a", "b"] as unknown as string[],
|
|
181
|
+
required: false,
|
|
182
|
+
type: "string",
|
|
183
|
+
}}
|
|
179
184
|
fieldKey="status"
|
|
180
185
|
onChange={(v) => changes.push(v)}
|
|
181
186
|
value=""
|
|
@@ -319,7 +324,7 @@ describe("AdminFieldRenderer", () => {
|
|
|
319
324
|
});
|
|
320
325
|
|
|
321
326
|
it("renders single-value user targeting with a custom renderer", () => {
|
|
322
|
-
const CustomRenderer: React.FC<
|
|
327
|
+
const CustomRenderer: React.FC<RefFieldRendererProps> = (props) =>
|
|
323
328
|
React.createElement("CustomRenderer", props);
|
|
324
329
|
const {UNSAFE_root} = renderWithTheme(
|
|
325
330
|
<AdminFieldRenderer
|
|
@@ -333,7 +338,7 @@ describe("AdminFieldRenderer", () => {
|
|
|
333
338
|
value="user-1"
|
|
334
339
|
/>
|
|
335
340
|
);
|
|
336
|
-
const custom = UNSAFE_root.findAll((node) => node.type === "CustomRenderer")[0];
|
|
341
|
+
const custom = UNSAFE_root.findAll((node) => String(node.type) === "CustomRenderer")[0];
|
|
337
342
|
expect(custom.props.routePath).toBe("/admin/users");
|
|
338
343
|
expect(custom.props.autocomplete).toBe(true);
|
|
339
344
|
});
|
|
@@ -353,7 +358,7 @@ describe("AdminFieldRenderer", () => {
|
|
|
353
358
|
});
|
|
354
359
|
|
|
355
360
|
it("renders a configured reference with a custom renderer", () => {
|
|
356
|
-
const CustomRenderer: React.FC<
|
|
361
|
+
const CustomRenderer: React.FC<RefFieldRendererProps> = (props) =>
|
|
357
362
|
React.createElement("CustomRenderer", props);
|
|
358
363
|
const {UNSAFE_root} = renderWithTheme(
|
|
359
364
|
<AdminFieldRenderer
|
|
@@ -365,7 +370,7 @@ describe("AdminFieldRenderer", () => {
|
|
|
365
370
|
value="org-1"
|
|
366
371
|
/>
|
|
367
372
|
);
|
|
368
|
-
const custom = UNSAFE_root.findAll((node) => node.type === "CustomRenderer")[0];
|
|
373
|
+
const custom = UNSAFE_root.findAll((node) => String(node.type) === "CustomRenderer")[0];
|
|
369
374
|
expect(custom.props.routePath).toBe("/admin/organizations");
|
|
370
375
|
expect(custom.props.value).toBe("org-1");
|
|
371
376
|
});
|
|
@@ -28,13 +28,15 @@ mock.module("../AdminRefField", () => ({
|
|
|
28
28
|
|
|
29
29
|
import {AdminFilterDrawer} from "../AdminFilterDrawer";
|
|
30
30
|
|
|
31
|
+
type OnApply = React.ComponentProps<typeof AdminFilterDrawer>["onApply"];
|
|
32
|
+
|
|
31
33
|
describe("AdminFilterDrawer", () => {
|
|
32
34
|
beforeEach(() => {
|
|
33
35
|
mockWindowWidth = 1200;
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
it("renders desktop drawer with apply button and filter testIDs", async () => {
|
|
37
|
-
const onApply = mock(() => {});
|
|
39
|
+
const onApply = mock<OnApply>(() => {});
|
|
38
40
|
const {getByLabelText, getByTestId, getByText} = renderWithTheme(
|
|
39
41
|
<AdminFilterDrawer
|
|
40
42
|
api={{} as never}
|
|
@@ -68,7 +70,7 @@ describe("AdminFilterDrawer", () => {
|
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
it("enables apply after a draft change and clear-all applies empty filters", async () => {
|
|
71
|
-
const onApply = mock(() => {});
|
|
73
|
+
const onApply = mock<OnApply>(() => {});
|
|
72
74
|
const {getByTestId, rerender} = renderWithTheme(
|
|
73
75
|
<AdminFilterDrawer
|
|
74
76
|
api={{} as never}
|
|
@@ -110,7 +112,7 @@ describe("AdminFilterDrawer", () => {
|
|
|
110
112
|
});
|
|
111
113
|
|
|
112
114
|
it("renders every filter field kind and applies the edited draft", async () => {
|
|
113
|
-
const onApply = mock(() => {});
|
|
115
|
+
const onApply = mock<OnApply>(() => {});
|
|
114
116
|
const {UNSAFE_root, getByTestId} = renderWithTheme(
|
|
115
117
|
<AdminFilterDrawer
|
|
116
118
|
api={{} as never}
|
|
@@ -187,7 +189,7 @@ describe("AdminFilterDrawer", () => {
|
|
|
187
189
|
});
|
|
188
190
|
|
|
189
191
|
it("renders dateRange, choice, text, and ref filters", () => {
|
|
190
|
-
const onApply = mock(() => {});
|
|
192
|
+
const onApply = mock<OnApply>(() => {});
|
|
191
193
|
const {getByTestId, UNSAFE_root} = renderWithTheme(
|
|
192
194
|
<AdminFilterDrawer
|
|
193
195
|
api={{} as never}
|
|
@@ -242,7 +244,7 @@ describe("AdminFilterDrawer", () => {
|
|
|
242
244
|
});
|
|
243
245
|
|
|
244
246
|
it("clears an individual boolean filter and collapses the desktop drawer", async () => {
|
|
245
|
-
const onApply = mock(() => {});
|
|
247
|
+
const onApply = mock<OnApply>(() => {});
|
|
246
248
|
const {getByLabelText, getByText, UNSAFE_root} = renderWithTheme(
|
|
247
249
|
<AdminFilterDrawer
|
|
248
250
|
api={{} as never}
|
|
@@ -273,7 +275,7 @@ describe("AdminFilterDrawer", () => {
|
|
|
273
275
|
|
|
274
276
|
it("opens and dismisses the mobile filter sheet", async () => {
|
|
275
277
|
mockWindowWidth = 320;
|
|
276
|
-
const onApply = mock(() => {});
|
|
278
|
+
const onApply = mock<OnApply>(() => {});
|
|
277
279
|
Object.defineProperty(globalThis, "document", {
|
|
278
280
|
configurable: true,
|
|
279
281
|
value: {activeElement: null},
|
|
@@ -91,6 +91,8 @@ mock.module("../AdminRefField", () => ({
|
|
|
91
91
|
|
|
92
92
|
import {AdminFilterDrawer} from "../AdminFilterDrawer";
|
|
93
93
|
|
|
94
|
+
type OnApply = React.ComponentProps<typeof AdminFilterDrawer>["onApply"];
|
|
95
|
+
|
|
94
96
|
const findWithCallback = (
|
|
95
97
|
root: ReactTestInstance,
|
|
96
98
|
testID: string,
|
|
@@ -105,7 +107,7 @@ const findWithCallback = (
|
|
|
105
107
|
};
|
|
106
108
|
|
|
107
109
|
describe("AdminFilterDrawer mobile", () => {
|
|
108
|
-
const onApply = mock(() => {});
|
|
110
|
+
const onApply = mock<OnApply>(() => {});
|
|
109
111
|
|
|
110
112
|
beforeEach(() => {
|
|
111
113
|
onApply.mockClear();
|
|
@@ -20,8 +20,10 @@ import {ModelsGridWidget} from "../widgets/ModelsGridWidget";
|
|
|
20
20
|
import {ScriptRunnerWidget} from "../widgets/ScriptRunnerWidget";
|
|
21
21
|
|
|
22
22
|
const model: AdminModelConfig = {
|
|
23
|
+
defaultSort: "-created",
|
|
23
24
|
displayName: "Todos",
|
|
24
25
|
fields: {title: {required: true, type: "string"}},
|
|
26
|
+
listFields: ["title"],
|
|
25
27
|
name: "Todo",
|
|
26
28
|
routePath: "/admin/todos",
|
|
27
29
|
};
|
|
@@ -69,6 +69,8 @@ mock.module("@terreno/ui", () => {
|
|
|
69
69
|
|
|
70
70
|
import {AdminNestedArrayField} from "../AdminNestedArrayField";
|
|
71
71
|
|
|
72
|
+
type NestedOnChange = React.ComponentProps<typeof AdminNestedArrayField>["onChange"];
|
|
73
|
+
|
|
72
74
|
const baseItems = {
|
|
73
75
|
active: {default: true, required: false, type: "boolean"},
|
|
74
76
|
count: {required: false, type: "number"},
|
|
@@ -126,7 +128,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
126
128
|
});
|
|
127
129
|
|
|
128
130
|
it("adds a new item using buildDefaultItem for all supported types", () => {
|
|
129
|
-
const onChange = mock(() => {});
|
|
131
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
130
132
|
const {getByTestId} = renderWithTheme(
|
|
131
133
|
<AdminNestedArrayField
|
|
132
134
|
api={{} as unknown as AdminApi}
|
|
@@ -148,7 +150,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
it("builds default item for string type without default value", () => {
|
|
151
|
-
const onChange = mock(() => {});
|
|
153
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
152
154
|
const {getByTestId} = renderWithTheme(
|
|
153
155
|
<AdminNestedArrayField
|
|
154
156
|
api={{} as unknown as AdminApi}
|
|
@@ -169,7 +171,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
169
171
|
});
|
|
170
172
|
|
|
171
173
|
it("builds default item for boolean/number/array types without default values", () => {
|
|
172
|
-
const onChange = mock(() => {});
|
|
174
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
173
175
|
const items = {
|
|
174
176
|
enabled: {required: false, type: "boolean"},
|
|
175
177
|
qty: {required: false, type: "number"},
|
|
@@ -189,12 +191,11 @@ describe("AdminNestedArrayField", () => {
|
|
|
189
191
|
const added = onChange.mock.calls[0][0][0];
|
|
190
192
|
expect(added.enabled).toBe(false);
|
|
191
193
|
expect(added.qty).toBe(0);
|
|
192
|
-
expect(
|
|
193
|
-
expect(added.tags.length).toBe(0);
|
|
194
|
+
expect(added.tags).toEqual([]);
|
|
194
195
|
});
|
|
195
196
|
|
|
196
197
|
it("removes an item via IconButton", () => {
|
|
197
|
-
const onChange = mock(() => {});
|
|
198
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
198
199
|
const {getAllByTestId} = renderWithTheme(
|
|
199
200
|
<AdminNestedArrayField
|
|
200
201
|
api={{} as unknown as AdminApi}
|
|
@@ -217,7 +218,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
it("updates a sub-field value via AdminFieldRenderer onChange", () => {
|
|
220
|
-
const onChange = mock(() => {});
|
|
221
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
221
222
|
const {getAllByTestId} = renderWithTheme(
|
|
222
223
|
<AdminNestedArrayField
|
|
223
224
|
api={{} as unknown as AdminApi}
|
|
@@ -240,7 +241,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
240
241
|
});
|
|
241
242
|
|
|
242
243
|
it("reorders items via DraggableList callback", () => {
|
|
243
|
-
const onChange = mock(() => {});
|
|
244
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
244
245
|
const {getByTestId} = renderWithTheme(
|
|
245
246
|
<AdminNestedArrayField
|
|
246
247
|
api={{} as unknown as AdminApi}
|
|
@@ -262,7 +263,7 @@ describe("AdminNestedArrayField", () => {
|
|
|
262
263
|
});
|
|
263
264
|
|
|
264
265
|
it("supports re-render with longer value array (grows itemIds)", () => {
|
|
265
|
-
const onChange = mock(() => {});
|
|
266
|
+
const onChange = mock<NestedOnChange>(() => {});
|
|
266
267
|
const {rerender, toJSON} = renderWithTheme(
|
|
267
268
|
<AdminNestedArrayField
|
|
268
269
|
api={{} as unknown as AdminApi}
|
|
@@ -24,7 +24,12 @@ const AdminObjectPicker: React.FC<React.ComponentProps<typeof BaseAdminObjectPic
|
|
|
24
24
|
props
|
|
25
25
|
): React.ReactElement => <BaseAdminObjectPicker {...props} autocomplete />;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
interface QuerySpec {
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
url?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const querySpecs: QuerySpec[] = [];
|
|
28
33
|
const makeApi = () => ({
|
|
29
34
|
injectEndpoints: ({endpoints}: {endpoints: (b: unknown) => Record<string, unknown>}) => {
|
|
30
35
|
const build = {
|
|
@@ -89,16 +94,10 @@ describe("AdminObjectPicker", () => {
|
|
|
89
94
|
expect(urls).toContain("/admin/users/search");
|
|
90
95
|
expect(urls).toContain("/admin/users/some-id");
|
|
91
96
|
expect(urls).toContain("/admin/users");
|
|
92
|
-
const listSpec = querySpecs.find(
|
|
93
|
-
(s: unknown) =>
|
|
94
|
-
(s as Record<string, unknown>).url === "/admin/users" &&
|
|
95
|
-
Boolean((s as {params?: {limit?: number}}).params?.limit)
|
|
96
|
-
) as {params?: {limit?: number; page?: number}} | undefined;
|
|
97
|
+
const listSpec = querySpecs.find((s) => s.url === "/admin/users" && Boolean(s.params?.limit));
|
|
97
98
|
expect(listSpec?.params).toEqual({limit: 100, page: 1});
|
|
98
|
-
const searchSpec = querySpecs.find(
|
|
99
|
-
|
|
100
|
-
);
|
|
101
|
-
expect(searchSpec.params).toEqual({q: "some-id"});
|
|
99
|
+
const searchSpec = querySpecs.find((s) => s.url === "/admin/users/search");
|
|
100
|
+
expect(searchSpec?.params).toEqual({q: "some-id"});
|
|
102
101
|
});
|
|
103
102
|
|
|
104
103
|
it("falls back to _id when no known display field is present", () => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
readOnlyPromptObservabilityStatus,
|
|
11
11
|
} from "./observabilityStatusFixtures.isolated";
|
|
12
12
|
|
|
13
|
-
const routerPush = mock(() => undefined);
|
|
13
|
+
const routerPush = mock((..._args: unknown[]) => undefined);
|
|
14
14
|
|
|
15
15
|
mock.module("expo-router", () => ({
|
|
16
16
|
router: {push: (...args: unknown[]) => routerPush(...args)},
|