@terreno/admin-frontend 0.20.1 → 0.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/.ai/guidelines/core.md +10 -0
- package/dist/AdminBreadcrumbs.d.ts +13 -0
- package/dist/AdminBreadcrumbs.js +22 -0
- package/dist/AdminBreadcrumbs.js.map +1 -0
- package/dist/AdminFieldRenderer.js +3 -3
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +2 -0
- package/dist/AdminFieldRendererCore.js +28 -18
- package/dist/AdminFieldRendererCore.js.map +1 -1
- package/dist/AdminHome.d.ts +22 -0
- package/dist/AdminHome.js +189 -0
- package/dist/AdminHome.js.map +1 -0
- package/dist/AdminModelForm.d.ts +24 -1
- package/dist/AdminModelForm.js +185 -14
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +4 -0
- package/dist/AdminModelList.js +19 -4
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -27
- package/dist/AdminModelTable.js +316 -60
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +1 -0
- package/dist/AdminNestedArrayField.js +26 -6
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +1 -0
- package/dist/AdminObjectPicker.js +6 -2
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +1 -0
- package/dist/AdminPrimitiveArrayField.js +9 -8
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminRefField.js +2 -2
- package/dist/AdminRefField.js.map +1 -1
- package/dist/AdminScriptList.js +114 -7
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +5 -0
- package/dist/AdminScriptRunModal.js +136 -30
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminShell.d.ts +39 -0
- package/dist/AdminShell.js +80 -0
- package/dist/AdminShell.js.map +1 -0
- package/dist/AdminShellLayout.d.ts +23 -0
- package/dist/AdminShellLayout.js +32 -0
- package/dist/AdminShellLayout.js.map +1 -0
- package/dist/AdminVersionConfig.d.ts +5 -0
- package/dist/AdminVersionConfig.js +15 -5
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.js +3 -3
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.js +2 -2
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.js +1 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.js +3 -3
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/adminModelListQueryParams.d.ts +14 -0
- package/dist/adminModelListQueryParams.js +51 -0
- package/dist/adminModelListQueryParams.js.map +1 -0
- package/dist/adminShellNav.d.ts +10 -0
- package/dist/adminShellNav.js +29 -0
- package/dist/adminShellNav.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/scriptRunUtils.d.ts +36 -0
- package/dist/scriptRunUtils.js +121 -0
- package/dist/scriptRunUtils.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +1 -0
- package/dist/useAdminApi.js +11 -0
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminBackgroundTask.d.ts +12 -0
- package/dist/useAdminBackgroundTask.js +26 -0
- package/dist/useAdminBackgroundTask.js.map +1 -0
- package/dist/useAdminScripts.d.ts +19 -1
- package/dist/useAdminScripts.js +33 -4
- package/dist/useAdminScripts.js.map +1 -1
- package/package.json +4 -3
- package/src/AdminBreadcrumbs.test.tsx +27 -0
- package/src/AdminBreadcrumbs.tsx +63 -0
- package/src/AdminFieldRenderer.tsx +3 -0
- package/src/AdminFieldRendererCore.tsx +59 -1
- package/src/AdminHome.test.tsx +208 -0
- package/src/AdminHome.tsx +474 -0
- package/src/AdminModelForm.test.tsx +81 -1
- package/src/AdminModelForm.tsx +282 -34
- package/src/AdminModelList.test.tsx +1 -1
- package/src/AdminModelList.tsx +72 -39
- package/src/AdminModelTable.test.tsx +11 -0
- package/src/AdminModelTable.tsx +530 -92
- package/src/AdminNestedArrayField.tsx +59 -9
- package/src/AdminObjectPicker.tsx +19 -1
- package/src/AdminPrimitiveArrayField.tsx +30 -15
- package/src/AdminRefField.tsx +2 -0
- package/src/AdminScriptList.tsx +307 -30
- package/src/AdminScriptRunModal.tsx +410 -95
- package/src/AdminShell.tsx +296 -0
- package/src/AdminShellLayout.tsx +34 -0
- package/src/AdminVersionConfig.tsx +120 -76
- package/src/ConfigurationScreen.tsx +4 -2
- package/src/ConsentFormEditor.tsx +3 -1
- package/src/ConsentFormList.tsx +1 -1
- package/src/ConsentResponseViewer.tsx +3 -3
- package/src/DocumentStorageBrowser.tsx +1 -1
- package/src/adminModelListQueryParams.ts +61 -0
- package/src/adminShellNav.test.ts +29 -0
- package/src/adminShellNav.ts +33 -0
- package/src/index.tsx +6 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +152 -1
- package/src/scriptRunUtils.test.ts +146 -0
- package/src/scriptRunUtils.ts +149 -0
- package/src/types.ts +69 -0
- package/src/useAdminApi.ts +11 -0
- package/src/useAdminBackgroundTask.ts +40 -0
- package/src/useAdminScripts.ts +56 -5
|
@@ -84,6 +84,8 @@ export interface AdminFieldRendererCoreProps extends AdminScreenProps {
|
|
|
84
84
|
* Forwarded to {@link AdminPrimitiveArrayField} so nested fields participate in the override.
|
|
85
85
|
*/
|
|
86
86
|
refRenderers?: RefRendererMap;
|
|
87
|
+
/** When true, inputs are disabled and ref fields do not open the picker. */
|
|
88
|
+
readOnly?: boolean;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
/**
|
|
@@ -104,10 +106,12 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
104
106
|
modelConfigs,
|
|
105
107
|
parentFormState,
|
|
106
108
|
refRenderers,
|
|
109
|
+
readOnly,
|
|
107
110
|
}) => {
|
|
108
111
|
const label = startCase(fieldKey);
|
|
109
112
|
const helperText = fieldConfig.description;
|
|
110
113
|
const refModel = getRefModel(modelConfigs, USER_REF_MODEL_NAME);
|
|
114
|
+
const isReadOnly = Boolean(readOnly);
|
|
111
115
|
|
|
112
116
|
if (isUserTargetingValueField(fieldKey, parentFormState)) {
|
|
113
117
|
const operator = parentFormState?.operator;
|
|
@@ -120,6 +124,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
120
124
|
return (
|
|
121
125
|
<AdminPrimitiveArrayField
|
|
122
126
|
api={api}
|
|
127
|
+
apiBase={apiBase}
|
|
123
128
|
baseUrl={baseUrl}
|
|
124
129
|
errorText={errorText}
|
|
125
130
|
helperText={helperText ?? "Select users to target for this rule."}
|
|
@@ -127,7 +132,9 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
127
132
|
itemType="objectid"
|
|
128
133
|
modelConfigs={modelConfigs}
|
|
129
134
|
onChange={onChange}
|
|
135
|
+
readOnly={isReadOnly}
|
|
130
136
|
refRenderers={refRenderers}
|
|
137
|
+
routeBase={routeBase}
|
|
131
138
|
title={label}
|
|
132
139
|
value={arrayValue}
|
|
133
140
|
/>
|
|
@@ -144,6 +151,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
144
151
|
errorText={errorText}
|
|
145
152
|
helperText={helperText ?? "Select the user to target for this rule."}
|
|
146
153
|
onChange={onChange}
|
|
154
|
+
readOnly={isReadOnly}
|
|
147
155
|
refModelName={USER_REF_MODEL_NAME}
|
|
148
156
|
routePath={refModel?.routePath ?? ""}
|
|
149
157
|
title={label}
|
|
@@ -159,6 +167,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
159
167
|
errorText={errorText}
|
|
160
168
|
helperText={helperText ?? "Select the user to target for this rule."}
|
|
161
169
|
onChange={onChange}
|
|
170
|
+
readOnly={isReadOnly}
|
|
162
171
|
refModelName={USER_REF_MODEL_NAME}
|
|
163
172
|
routePath={refModel.routePath}
|
|
164
173
|
title={label}
|
|
@@ -181,6 +190,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
181
190
|
if (dynamicOptions.length > 0) {
|
|
182
191
|
return (
|
|
183
192
|
<SelectField
|
|
193
|
+
disabled={isReadOnly}
|
|
184
194
|
errorText={errorText}
|
|
185
195
|
helperText={helperText}
|
|
186
196
|
onChange={onChange}
|
|
@@ -206,6 +216,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
206
216
|
errorText={errorText}
|
|
207
217
|
helperText={helperText}
|
|
208
218
|
onChange={onChange}
|
|
219
|
+
readOnly={isReadOnly}
|
|
209
220
|
refModelName={fieldConfig.ref}
|
|
210
221
|
routeBase={routeBase}
|
|
211
222
|
routePath={refModel?.routePath ?? ""}
|
|
@@ -223,6 +234,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
223
234
|
errorText={errorText}
|
|
224
235
|
helperText={helperText}
|
|
225
236
|
onChange={onChange}
|
|
237
|
+
readOnly={isReadOnly}
|
|
226
238
|
refModelName={fieldConfig.ref}
|
|
227
239
|
routeBase={routeBase}
|
|
228
240
|
routePath={refModel.routePath}
|
|
@@ -236,6 +248,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
236
248
|
if (fieldConfig.type === "boolean") {
|
|
237
249
|
return (
|
|
238
250
|
<BooleanField
|
|
251
|
+
disabled={isReadOnly}
|
|
239
252
|
errorText={errorText}
|
|
240
253
|
helperText={helperText}
|
|
241
254
|
onChange={onChange}
|
|
@@ -253,6 +266,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
253
266
|
const options = includesNullOption ? [{label: "None", value: ""}, ...enumOptions] : enumOptions;
|
|
254
267
|
return (
|
|
255
268
|
<SelectField
|
|
269
|
+
disabled={isReadOnly}
|
|
256
270
|
errorText={errorText}
|
|
257
271
|
helperText={helperText}
|
|
258
272
|
onChange={(nextValue: string) => onChange(nextValue === "" ? undefined : nextValue)}
|
|
@@ -270,6 +284,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
270
284
|
) {
|
|
271
285
|
return (
|
|
272
286
|
<DateTimeField
|
|
287
|
+
disabled={isReadOnly}
|
|
273
288
|
errorText={errorText}
|
|
274
289
|
helperText={helperText}
|
|
275
290
|
onChange={onChange}
|
|
@@ -284,6 +299,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
284
299
|
if (fieldConfig.type === "number") {
|
|
285
300
|
return (
|
|
286
301
|
<TextField
|
|
302
|
+
disabled={isReadOnly}
|
|
287
303
|
errorText={errorText}
|
|
288
304
|
helperText={helperText}
|
|
289
305
|
onChange={(text: string) => {
|
|
@@ -297,6 +313,26 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
297
313
|
);
|
|
298
314
|
}
|
|
299
315
|
|
|
316
|
+
if (isReadOnly && fieldConfig.widget === "locale-content") {
|
|
317
|
+
const localeReadonly =
|
|
318
|
+
value && typeof value === "object" && !Array.isArray(value)
|
|
319
|
+
? (value as Record<string, string>)
|
|
320
|
+
: {};
|
|
321
|
+
return (
|
|
322
|
+
<TextField
|
|
323
|
+
disabled
|
|
324
|
+
grow
|
|
325
|
+
helperText={helperText ?? "Read-only"}
|
|
326
|
+
multiline
|
|
327
|
+
onChange={() => {}}
|
|
328
|
+
rows={8}
|
|
329
|
+
testID={`admin-field-${fieldKey}`}
|
|
330
|
+
title={label}
|
|
331
|
+
value={serializeJsonValue(localeReadonly)}
|
|
332
|
+
/>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
300
336
|
if (fieldConfig.widget === "locale-content") {
|
|
301
337
|
const localeValue =
|
|
302
338
|
value && typeof value === "object" && !Array.isArray(value)
|
|
@@ -323,7 +359,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
323
359
|
const options = localeKeys.map((k) => ({label: k.toUpperCase(), value: k}));
|
|
324
360
|
return (
|
|
325
361
|
<SelectField
|
|
326
|
-
disabled={!hasLocales}
|
|
362
|
+
disabled={!hasLocales || isReadOnly}
|
|
327
363
|
errorText={errorText}
|
|
328
364
|
helperText={
|
|
329
365
|
hasLocales
|
|
@@ -342,6 +378,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
342
378
|
const displayValue = serializeJsonValue(value);
|
|
343
379
|
return (
|
|
344
380
|
<TextField
|
|
381
|
+
disabled={isReadOnly}
|
|
345
382
|
errorText={errorText}
|
|
346
383
|
helperText={helperText ?? "JSON value (string, number, boolean, object, or array)"}
|
|
347
384
|
onChange={(text: string) => {
|
|
@@ -367,6 +404,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
367
404
|
itemType={fieldConfig.itemType}
|
|
368
405
|
modelConfigs={modelConfigs}
|
|
369
406
|
onChange={onChange}
|
|
407
|
+
readOnly={isReadOnly}
|
|
370
408
|
refRenderers={refRenderers}
|
|
371
409
|
routeBase={routeBase}
|
|
372
410
|
title={label}
|
|
@@ -380,6 +418,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
380
418
|
value != null ? (typeof value === "string" ? value : JSON.stringify(value, null, 2)) : "[]";
|
|
381
419
|
return (
|
|
382
420
|
<TextField
|
|
421
|
+
disabled={isReadOnly}
|
|
383
422
|
errorText={errorText}
|
|
384
423
|
grow
|
|
385
424
|
helperText={helperText ?? "Enter valid JSON array"}
|
|
@@ -402,6 +441,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
402
441
|
if (fieldConfig.widget === "markdown") {
|
|
403
442
|
return (
|
|
404
443
|
<MarkdownEditorField
|
|
444
|
+
disabled={isReadOnly}
|
|
405
445
|
errorText={errorText}
|
|
406
446
|
helperText={helperText}
|
|
407
447
|
onChange={onChange}
|
|
@@ -412,6 +452,22 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
412
452
|
);
|
|
413
453
|
}
|
|
414
454
|
|
|
455
|
+
if (isReadOnly && fieldConfig.widget === "checkbox-list") {
|
|
456
|
+
return (
|
|
457
|
+
<TextField
|
|
458
|
+
disabled
|
|
459
|
+
grow
|
|
460
|
+
helperText={helperText ?? "Read-only"}
|
|
461
|
+
multiline
|
|
462
|
+
onChange={() => {}}
|
|
463
|
+
rows={6}
|
|
464
|
+
testID={`admin-field-${fieldKey}`}
|
|
465
|
+
title={label}
|
|
466
|
+
value={serializeJsonValue(value)}
|
|
467
|
+
/>
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
415
471
|
if (fieldConfig.widget === "checkbox-list") {
|
|
416
472
|
return (
|
|
417
473
|
<CheckboxListEditor
|
|
@@ -431,6 +487,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
431
487
|
if (fieldConfig.widget === "textarea") {
|
|
432
488
|
return (
|
|
433
489
|
<TextField
|
|
490
|
+
disabled={isReadOnly}
|
|
434
491
|
errorText={errorText}
|
|
435
492
|
grow
|
|
436
493
|
helperText={helperText}
|
|
@@ -447,6 +504,7 @@ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
|
|
|
447
504
|
// Default: string -> TextField
|
|
448
505
|
return (
|
|
449
506
|
<TextField
|
|
507
|
+
disabled={isReadOnly}
|
|
450
508
|
errorText={errorText}
|
|
451
509
|
helperText={helperText}
|
|
452
510
|
onChange={onChange}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test harness doubles
|
|
2
|
+
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
3
|
+
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
6
|
+
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
7
|
+
|
|
8
|
+
mock.module("expo-router", () => ({
|
|
9
|
+
router: {push: mock(() => {})},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const configState: {config: AdminConfigResponse | null; isLoading: boolean} = {
|
|
13
|
+
config: null,
|
|
14
|
+
isLoading: false,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
mock.module("./useAdminConfig", () => ({
|
|
18
|
+
useAdminConfig: () => ({
|
|
19
|
+
config: configState.config,
|
|
20
|
+
error: null,
|
|
21
|
+
isLoading: configState.isLoading,
|
|
22
|
+
}),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
mock.module("./useAdminApi", () => ({
|
|
26
|
+
useAdminApi: () => ({
|
|
27
|
+
useListQuery: () => ({
|
|
28
|
+
data: {data: [], total: 0},
|
|
29
|
+
error: null,
|
|
30
|
+
isError: false,
|
|
31
|
+
isLoading: false,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
mock.module("./AdminVersionConfig", () => ({
|
|
37
|
+
AdminVersionConfig: () => <React.Fragment />,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
import {AdminHome} from "./AdminHome";
|
|
41
|
+
|
|
42
|
+
const buildConfig = (overrides?: Partial<AdminConfigResponse>): AdminConfigResponse => ({
|
|
43
|
+
customScreens: [],
|
|
44
|
+
home: {
|
|
45
|
+
slots: {
|
|
46
|
+
contentTop: ["feature-flags-overrides"],
|
|
47
|
+
main: ["modelsGrid"],
|
|
48
|
+
navGlobal: ["scriptRunner"],
|
|
49
|
+
sidebar: ["recentActivity", "versionConfig"],
|
|
50
|
+
},
|
|
51
|
+
title: "Test Admin",
|
|
52
|
+
},
|
|
53
|
+
models: [
|
|
54
|
+
{
|
|
55
|
+
defaultSort: "-created",
|
|
56
|
+
displayName: "Feature Flags",
|
|
57
|
+
fields: {key: {required: true, type: "string"}},
|
|
58
|
+
listFields: ["key"],
|
|
59
|
+
name: "FeatureFlag",
|
|
60
|
+
routePath: "/admin/feature-flags",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
defaultSort: "-created",
|
|
64
|
+
displayName: "Widget",
|
|
65
|
+
fields: {title: {required: false, type: "string"}},
|
|
66
|
+
listFields: ["title"],
|
|
67
|
+
name: "Widget",
|
|
68
|
+
routePath: "/admin/widgets",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
displayName: "Audit log",
|
|
72
|
+
fields: {},
|
|
73
|
+
listFields: ["verb"],
|
|
74
|
+
name: "AdminAuditLog",
|
|
75
|
+
routePath: "/admin/audit-logs",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
scripts: [],
|
|
79
|
+
...overrides,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const countTestIdInSubtree = (root: ReactTestInstance, testId: string): number => {
|
|
83
|
+
let count = 0;
|
|
84
|
+
const walk = (node: unknown): void => {
|
|
85
|
+
if (!node || typeof node !== "object") {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const inst = node as ReactTestInstance;
|
|
89
|
+
if (inst.props?.testID === testId) {
|
|
90
|
+
count += 1;
|
|
91
|
+
}
|
|
92
|
+
const ch = inst.children;
|
|
93
|
+
if (Array.isArray(ch)) {
|
|
94
|
+
for (const c of ch) {
|
|
95
|
+
walk(c);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
walk(root);
|
|
100
|
+
return count;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
describe("AdminHome", () => {
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
configState.config = null;
|
|
106
|
+
configState.isLoading = false;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("renders scriptRunner in the top band with contentTop widgets on the same row, not inside main", () => {
|
|
110
|
+
configState.config = buildConfig();
|
|
111
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
112
|
+
<AdminHome api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
113
|
+
);
|
|
114
|
+
const top = UNSAFE_root.findAll(
|
|
115
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-home-slot-top"
|
|
116
|
+
);
|
|
117
|
+
const main = UNSAFE_root.findAll(
|
|
118
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-home-slot-main"
|
|
119
|
+
);
|
|
120
|
+
expect(top.length).toBeGreaterThan(0);
|
|
121
|
+
expect(main.length).toBeGreaterThan(0);
|
|
122
|
+
const topSlot = top[0] as ReactTestInstance;
|
|
123
|
+
const mainSlot = main[0] as ReactTestInstance;
|
|
124
|
+
expect(countTestIdInSubtree(topSlot, "admin-home-widget-scriptRunner")).toBeGreaterThan(0);
|
|
125
|
+
expect(
|
|
126
|
+
countTestIdInSubtree(topSlot, "admin-home-widget-feature-flags-overrides")
|
|
127
|
+
).toBeGreaterThan(0);
|
|
128
|
+
expect(countTestIdInSubtree(mainSlot, "admin-home-widget-scriptRunner")).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("shows per-model row counts on each model card", () => {
|
|
132
|
+
configState.config = buildConfig();
|
|
133
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
134
|
+
<AdminHome api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
135
|
+
);
|
|
136
|
+
const modelCountLabels = UNSAFE_root.findAll(
|
|
137
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-home-model-count-Widget"
|
|
138
|
+
);
|
|
139
|
+
expect(modelCountLabels.length).toBeGreaterThan(0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("normalizes legacy modelStats to a single modelsGrid widget", () => {
|
|
143
|
+
configState.config = buildConfig({
|
|
144
|
+
home: {
|
|
145
|
+
slots: {
|
|
146
|
+
main: ["modelStats", "modelsGrid"],
|
|
147
|
+
navGlobal: [],
|
|
148
|
+
sidebar: [],
|
|
149
|
+
},
|
|
150
|
+
title: "Test Admin",
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
154
|
+
<AdminHome api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
155
|
+
);
|
|
156
|
+
const mainSlots = UNSAFE_root.findAll(
|
|
157
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-home-slot-main"
|
|
158
|
+
);
|
|
159
|
+
expect(mainSlots.length).toBeGreaterThan(0);
|
|
160
|
+
const mainSlot = mainSlots[0] as ReactTestInstance;
|
|
161
|
+
const directWidgetWrappers = mainSlot.children.filter(
|
|
162
|
+
(child) => typeof child === "object" && child !== null
|
|
163
|
+
);
|
|
164
|
+
expect(directWidgetWrappers.length).toBe(1);
|
|
165
|
+
expect(countTestIdInSubtree(mainSlot, "admin-home-widget-modelsGrid")).toBeGreaterThan(0);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("places recentActivity after other sidebar widgets when configured first in sidebar", () => {
|
|
169
|
+
configState.config = buildConfig({
|
|
170
|
+
home: {
|
|
171
|
+
slots: {
|
|
172
|
+
main: [],
|
|
173
|
+
navGlobal: [],
|
|
174
|
+
sidebar: ["recentActivity", "modelsGrid"],
|
|
175
|
+
},
|
|
176
|
+
title: "Test Admin",
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
180
|
+
<AdminHome api={{} as unknown as AdminApi} baseUrl="/admin" />
|
|
181
|
+
);
|
|
182
|
+
const sidebar = UNSAFE_root.findAll(
|
|
183
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-home-slot-sidebar"
|
|
184
|
+
);
|
|
185
|
+
expect(sidebar.length).toBeGreaterThan(0);
|
|
186
|
+
const sidebarSlot = sidebar[0] as ReactTestInstance;
|
|
187
|
+
const ids: string[] = [];
|
|
188
|
+
const walk = (node: unknown): void => {
|
|
189
|
+
if (!node || typeof node !== "object") {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const inst = node as ReactTestInstance;
|
|
193
|
+
const tid = inst.props?.testID as string | undefined;
|
|
194
|
+
if (tid === "admin-home-widget-recentActivity" || tid === "admin-home-widget-modelsGrid") {
|
|
195
|
+
ids.push(tid);
|
|
196
|
+
}
|
|
197
|
+
const ch = inst.children;
|
|
198
|
+
if (Array.isArray(ch)) {
|
|
199
|
+
for (const c of ch) {
|
|
200
|
+
walk(c);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
walk(sidebarSlot);
|
|
205
|
+
expect(ids[ids.length - 1]).toBe("admin-home-widget-recentActivity");
|
|
206
|
+
expect(ids[0]).toBe("admin-home-widget-modelsGrid");
|
|
207
|
+
});
|
|
208
|
+
});
|