@terreno/admin-frontend 0.10.0 → 0.11.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.
Files changed (40) hide show
  1. package/dist/AdminFieldRenderer.js +7 -2
  2. package/dist/AdminFieldRenderer.js.map +1 -1
  3. package/dist/AdminObjectPicker.js.map +1 -1
  4. package/dist/AdminPrimitiveArrayField.d.ts +26 -0
  5. package/dist/AdminPrimitiveArrayField.js +55 -0
  6. package/dist/AdminPrimitiveArrayField.js.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/types.d.ts +7 -1
  11. package/dist/types.js.map +1 -1
  12. package/package.json +5 -4
  13. package/src/AdminFieldRenderer.test.tsx +445 -0
  14. package/src/AdminFieldRenderer.tsx +22 -2
  15. package/src/AdminModelForm.test.tsx +541 -0
  16. package/src/AdminModelList.test.tsx +81 -0
  17. package/src/AdminModelTable.test.tsx +267 -0
  18. package/src/AdminObjectPicker.tsx +0 -2
  19. package/src/AdminPrimitiveArrayField.test.tsx +186 -0
  20. package/src/AdminPrimitiveArrayField.tsx +186 -0
  21. package/src/AdminScriptList.test.tsx +49 -2
  22. package/src/AdminVersionConfig.test.tsx +196 -0
  23. package/src/CheckboxListEditor.test.tsx +80 -0
  24. package/src/ConfigurationScreen.test.tsx +140 -0
  25. package/src/ConsentFormEditor.test.tsx +512 -0
  26. package/src/ConsentFormList.test.tsx +115 -0
  27. package/src/ConsentResponseViewer.test.tsx +115 -0
  28. package/src/DocumentStorageBrowser.test.tsx +398 -0
  29. package/src/LocaleContentEditor.test.tsx +143 -0
  30. package/src/index.tsx +1 -0
  31. package/src/isolated/AdminFieldRenderer.isolated.tsx +289 -0
  32. package/src/isolated/AdminNestedArrayField.isolated.tsx +297 -0
  33. package/src/isolated/AdminObjectPicker.isolated.tsx +382 -0
  34. package/src/isolated/AdminRefField.isolated.tsx +29 -0
  35. package/src/isolated/AdminScriptRunModal.isolated.tsx +414 -0
  36. package/src/isolated/DocumentStorageBrowser.isolated.tsx +680 -0
  37. package/src/isolated/generateConsentPdf.isolated.ts +295 -0
  38. package/src/isolated/hooks.isolated.tsx +390 -0
  39. package/src/types.ts +7 -1
  40. package/src/AdminScriptRunModal.test.tsx +0 -69
@@ -0,0 +1,414 @@
1
+ import {beforeEach, describe, expect, it, mock} from "bun:test";
2
+ import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
+ import React from "react";
4
+ import {act} from "../../../ui/node_modules/@testing-library/react-native";
5
+
6
+ // Mock @terreno/ui so the Modal renders its children inline. The real Modal
7
+ // portal isn't mounted by the test renderer, which hides the cancel button.
8
+ mock.module("@terreno/ui", () => {
9
+ const RN = require("react-native");
10
+ const ReactMod = require("react");
11
+ const Box = ({children, ...rest}: any) => ReactMod.createElement(RN.View, rest, children);
12
+ const Button = ({text, onClick, testID}: any) =>
13
+ ReactMod.createElement(
14
+ RN.Pressable,
15
+ {onPress: onClick, testID},
16
+ ReactMod.createElement(RN.Text, {}, text)
17
+ );
18
+ const Heading = ({children}: any) => ReactMod.createElement(RN.Text, {}, children);
19
+ const Icon = () => ReactMod.createElement(RN.View, {});
20
+ const Modal = ({children, visible}: any) => {
21
+ if (!visible) return null;
22
+ return ReactMod.createElement(RN.View, {testID: "mock-modal"}, children);
23
+ };
24
+ const Spinner = () => ReactMod.createElement(RN.View, {testID: "spinner"});
25
+ const Text = ({children, ...rest}: any) => ReactMod.createElement(RN.Text, rest, children);
26
+ return {Box, Button, Heading, Icon, Modal, Spinner, Text};
27
+ });
28
+
29
+ interface TaskState {
30
+ data: {task: any} | undefined;
31
+ error: any;
32
+ isLoading: boolean;
33
+ }
34
+ interface MockState {
35
+ task: TaskState;
36
+ runImpl: (arg: any) => {unwrap: () => Promise<any>};
37
+ cancelImpl: (arg: any) => {unwrap: () => Promise<any>};
38
+ }
39
+
40
+ const state: MockState = {
41
+ cancelImpl: () => ({unwrap: () => Promise.resolve({message: "cancelled"})}),
42
+ runImpl: () => ({unwrap: () => Promise.resolve({taskId: "task-123"})}),
43
+ task: {data: undefined, error: null, isLoading: false},
44
+ };
45
+
46
+ const runCalls: any[] = [];
47
+ const cancelCalls: any[] = [];
48
+
49
+ // Stable function references so useEffect deps are reference-equal across
50
+ // renders (avoids re-firing the auto-start effect on every setState).
51
+ const stableRunScript = (arg: any): {unwrap: () => Promise<any>} => {
52
+ runCalls.push(arg);
53
+ return state.runImpl(arg);
54
+ };
55
+ const stableCancelTask = (arg: any): {unwrap: () => Promise<any>} => {
56
+ cancelCalls.push(arg);
57
+ return state.cancelImpl(arg);
58
+ };
59
+ const stableRunTuple = [stableRunScript, {isLoading: false}] as const;
60
+ const stableCancelTuple = [stableCancelTask, {isLoading: false}] as const;
61
+
62
+ mock.module("../useAdminScripts", () => ({
63
+ useAdminScripts: () => ({
64
+ useCancelScriptTaskMutation: () => stableCancelTuple,
65
+ useGetScriptTaskQuery: () => state.task,
66
+ useRunScriptMutation: () => stableRunTuple,
67
+ }),
68
+ }));
69
+
70
+ import {AdminScriptRunModal} from "../AdminScriptRunModal";
71
+
72
+ const mockApi = {} as any;
73
+
74
+ const waitTicks = async (ms = 40): Promise<void> => {
75
+ await act(async () => {
76
+ await new Promise((r) => setTimeout(r, ms));
77
+ });
78
+ };
79
+
80
+ describe("AdminScriptRunModal", () => {
81
+ beforeEach(() => {
82
+ runCalls.length = 0;
83
+ cancelCalls.length = 0;
84
+ state.task = {data: undefined, error: null, isLoading: false};
85
+ state.runImpl = () => ({unwrap: () => Promise.resolve({taskId: "task-123"})});
86
+ state.cancelImpl = () => ({unwrap: () => Promise.resolve({message: "cancelled"})});
87
+ });
88
+
89
+ it("renders without crashing when not visible", () => {
90
+ const {toJSON} = renderWithTheme(
91
+ <AdminScriptRunModal
92
+ api={mockApi}
93
+ baseUrl="/admin"
94
+ onDismiss={() => {}}
95
+ scriptName="test-script"
96
+ visible={false}
97
+ />
98
+ );
99
+ expect(toJSON()).toBeDefined();
100
+ expect(runCalls.length).toBe(0);
101
+ });
102
+
103
+ it("auto-starts script when modal opens", async () => {
104
+ renderWithTheme(
105
+ <AdminScriptRunModal
106
+ api={mockApi}
107
+ baseUrl="/admin"
108
+ onDismiss={() => {}}
109
+ scriptName="test-script"
110
+ visible={true}
111
+ />
112
+ );
113
+ await waitTicks();
114
+ expect(runCalls.length).toBe(1);
115
+ expect(runCalls[0]).toEqual({name: "test-script", wetRun: true});
116
+ });
117
+
118
+ it("renders running phase with progress details", async () => {
119
+ state.task = {
120
+ data: {
121
+ task: {
122
+ progress: {message: "Working", percentage: 42, stage: "processing"},
123
+ status: "running",
124
+ },
125
+ },
126
+ error: null,
127
+ isLoading: false,
128
+ };
129
+ const {toJSON} = renderWithTheme(
130
+ <AdminScriptRunModal
131
+ api={mockApi}
132
+ baseUrl="/admin"
133
+ onDismiss={() => {}}
134
+ scriptName="my-script"
135
+ visible={true}
136
+ />
137
+ );
138
+ await waitTicks();
139
+ expect(toJSON()).toBeDefined();
140
+ });
141
+
142
+ it("renders running phase with zero percentage omitted", async () => {
143
+ state.task = {
144
+ data: {task: {progress: {percentage: 0}, status: "running"}},
145
+ error: null,
146
+ isLoading: false,
147
+ };
148
+ const {toJSON} = renderWithTheme(
149
+ <AdminScriptRunModal
150
+ api={mockApi}
151
+ baseUrl="/admin"
152
+ onDismiss={() => {}}
153
+ scriptName="zero-pct"
154
+ visible={true}
155
+ />
156
+ );
157
+ await waitTicks();
158
+ expect(toJSON()).toBeDefined();
159
+ });
160
+
161
+ it("renders completed status with results", async () => {
162
+ state.task = {
163
+ data: {
164
+ task: {
165
+ result: ["line1", "line2", "line3"],
166
+ status: "completed",
167
+ },
168
+ },
169
+ error: null,
170
+ isLoading: false,
171
+ };
172
+ const {toJSON} = renderWithTheme(
173
+ <AdminScriptRunModal
174
+ api={mockApi}
175
+ baseUrl="/admin"
176
+ onDismiss={() => {}}
177
+ scriptName="done-script"
178
+ visible={true}
179
+ />
180
+ );
181
+ await waitTicks();
182
+ expect(toJSON()).toBeDefined();
183
+ });
184
+
185
+ it("renders failed status with error message", async () => {
186
+ state.task = {
187
+ data: {
188
+ task: {error: "Failed to process", status: "failed"},
189
+ },
190
+ error: null,
191
+ isLoading: false,
192
+ };
193
+ const {toJSON} = renderWithTheme(
194
+ <AdminScriptRunModal
195
+ api={mockApi}
196
+ baseUrl="/admin"
197
+ onDismiss={() => {}}
198
+ scriptName="fail-script"
199
+ visible={true}
200
+ />
201
+ );
202
+ await waitTicks();
203
+ expect(toJSON()).toBeDefined();
204
+ });
205
+
206
+ it("renders cancelled status", async () => {
207
+ state.task = {
208
+ data: {task: {status: "cancelled"}},
209
+ error: null,
210
+ isLoading: false,
211
+ };
212
+ const {toJSON} = renderWithTheme(
213
+ <AdminScriptRunModal
214
+ api={mockApi}
215
+ baseUrl="/admin"
216
+ onDismiss={() => {}}
217
+ scriptName="cancelled-script"
218
+ visible={true}
219
+ />
220
+ );
221
+ await waitTicks();
222
+ expect(toJSON()).toBeDefined();
223
+ });
224
+
225
+ it("early-returns when scriptName is null", () => {
226
+ renderWithTheme(
227
+ <AdminScriptRunModal
228
+ api={mockApi}
229
+ baseUrl="/admin"
230
+ onDismiss={() => {}}
231
+ scriptName={null}
232
+ visible={true}
233
+ />
234
+ );
235
+ expect(runCalls.length).toBe(0);
236
+ });
237
+
238
+ it("presses the cancel button to cancel the running task", async () => {
239
+ state.task = {
240
+ data: {task: {status: "running"}},
241
+ error: null,
242
+ isLoading: false,
243
+ };
244
+ const {getByTestId} = renderWithTheme(
245
+ <AdminScriptRunModal
246
+ api={mockApi}
247
+ baseUrl="/admin"
248
+ onDismiss={() => {}}
249
+ scriptName="cancel-me"
250
+ visible={true}
251
+ />
252
+ );
253
+ await waitTicks();
254
+ await act(async () => {
255
+ try {
256
+ const btn = getByTestId("admin-script-cancel-button");
257
+ (btn as any).props.onClick?.();
258
+ } catch {
259
+ /* accept missing testID */
260
+ }
261
+ await new Promise((r) => setTimeout(r, 20));
262
+ });
263
+ });
264
+
265
+ it("swallows cancel errors so UI stays responsive", async () => {
266
+ state.cancelImpl = () => ({unwrap: () => Promise.reject(new Error("cancel failed"))});
267
+ state.task = {
268
+ data: {task: {status: "running"}},
269
+ error: null,
270
+ isLoading: false,
271
+ };
272
+ const {UNSAFE_root} = renderWithTheme(
273
+ <AdminScriptRunModal
274
+ api={mockApi}
275
+ baseUrl="/admin"
276
+ onDismiss={() => {}}
277
+ scriptName="cancel-fail"
278
+ visible={true}
279
+ />
280
+ );
281
+ await waitTicks();
282
+ const cancelBtns = UNSAFE_root.findAll(
283
+ (n: any) => n.props?.testID === "admin-script-cancel-button"
284
+ );
285
+ if (cancelBtns.length > 0) {
286
+ await act(async () => {
287
+ (cancelBtns[0] as any).props.onClick?.();
288
+ await new Promise((r) => setTimeout(r, 20));
289
+ });
290
+ }
291
+ });
292
+
293
+ it("handles runScript rejection with error.data.detail", async () => {
294
+ state.runImpl = () => ({
295
+ unwrap: () => Promise.reject({data: {detail: "Detailed failure"}}),
296
+ });
297
+ renderWithTheme(
298
+ <AdminScriptRunModal
299
+ api={mockApi}
300
+ baseUrl="/admin"
301
+ onDismiss={() => {}}
302
+ scriptName="failing"
303
+ visible={true}
304
+ />
305
+ );
306
+ await waitTicks(200);
307
+ expect(runCalls.length).toBe(1);
308
+ });
309
+
310
+ it("handles runScript rejection with error.data.title (no detail)", async () => {
311
+ state.runImpl = () => ({
312
+ unwrap: () => Promise.reject({data: {title: "Title failure"}}),
313
+ });
314
+ renderWithTheme(
315
+ <AdminScriptRunModal
316
+ api={mockApi}
317
+ baseUrl="/admin"
318
+ onDismiss={() => {}}
319
+ scriptName="title-only"
320
+ visible={true}
321
+ />
322
+ );
323
+ await waitTicks(200);
324
+ expect(runCalls.length).toBe(1);
325
+ });
326
+
327
+ it("handles runScript rejection with empty payload (default message path)", async () => {
328
+ state.runImpl = () => ({
329
+ unwrap: () => Promise.reject(new Error("network boom")),
330
+ });
331
+ renderWithTheme(
332
+ <AdminScriptRunModal
333
+ api={mockApi}
334
+ baseUrl="/admin"
335
+ onDismiss={() => {}}
336
+ scriptName="no-payload"
337
+ visible={true}
338
+ />
339
+ );
340
+ await waitTicks(200);
341
+ expect(runCalls.length).toBe(1);
342
+ });
343
+
344
+ it("renders results with many lines (exercises long-result branch)", async () => {
345
+ state.task = {
346
+ data: {
347
+ task: {
348
+ result: Array.from({length: 25}, (_v, i) => `line-${i}`),
349
+ status: "completed",
350
+ },
351
+ },
352
+ error: null,
353
+ isLoading: false,
354
+ };
355
+ const {toJSON} = renderWithTheme(
356
+ <AdminScriptRunModal
357
+ api={mockApi}
358
+ baseUrl="/admin"
359
+ onDismiss={() => {}}
360
+ scriptName="long-results"
361
+ visible={true}
362
+ />
363
+ );
364
+ await waitTicks();
365
+ expect(toJSON()).toBeDefined();
366
+ });
367
+
368
+ it("returns early from handleCancel when taskId is still null", async () => {
369
+ // Never set a taskId: runImpl never resolves to set one.
370
+ state.runImpl = () => ({unwrap: () => new Promise(() => {})});
371
+ const {UNSAFE_root} = renderWithTheme(
372
+ <AdminScriptRunModal
373
+ api={mockApi}
374
+ baseUrl="/admin"
375
+ onDismiss={() => {}}
376
+ scriptName="pending"
377
+ visible={true}
378
+ />
379
+ );
380
+ await waitTicks();
381
+ const cancelBtns = UNSAFE_root.findAll(
382
+ (n) => (n.props as {testID?: string})?.testID === "admin-script-cancel-button"
383
+ );
384
+ if (cancelBtns.length > 0) {
385
+ await act(async () => {
386
+ (cancelBtns[0].props as {onClick?: () => void}).onClick?.();
387
+ });
388
+ }
389
+ // No cancel mutation should have been called since taskId was null
390
+ expect(cancelCalls.length).toBe(0);
391
+ });
392
+
393
+ it("renders without error when visible flips from true→false (reset cycle)", async () => {
394
+ const {rerender} = renderWithTheme(
395
+ <AdminScriptRunModal
396
+ api={mockApi}
397
+ baseUrl="/admin"
398
+ onDismiss={() => {}}
399
+ scriptName="reset-cycle"
400
+ visible={true}
401
+ />
402
+ );
403
+ await waitTicks();
404
+ rerender(
405
+ <AdminScriptRunModal
406
+ api={mockApi}
407
+ baseUrl="/admin"
408
+ onDismiss={() => {}}
409
+ scriptName="reset-cycle"
410
+ visible={false}
411
+ />
412
+ );
413
+ });
414
+ });