@terreno/admin-frontend 0.13.3 → 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/AdminFieldRenderer.d.ts +5 -53
- package/dist/AdminFieldRenderer.js +6 -168
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +26 -0
- package/dist/AdminFieldRendererCore.js +138 -0
- package/dist/AdminFieldRendererCore.js.map +1 -0
- package/dist/AdminModelForm.d.ts +6 -7
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +2 -3
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -2
- package/dist/AdminModelTable.js +2 -1
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +6 -7
- package/dist/AdminNestedArrayField.js +26 -2
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +2 -2
- package/dist/AdminObjectPicker.js +13 -7
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +2 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +2 -2
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +2 -2
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminVersionConfig.d.ts +2 -2
- package/dist/AdminVersionConfig.js +16 -10
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.d.ts +2 -2
- package/dist/ConfigurationScreen.js +18 -9
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.d.ts +27 -2
- package/dist/ConsentFormEditor.js +48 -32
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.d.ts +2 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.d.ts +2 -1
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/types.d.ts +29 -4
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +2 -2
- package/dist/useAdminApi.js +8 -5
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -3
- package/dist/useAdminConfig.js +2 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +2 -3
- package/dist/useAdminScripts.js +6 -3
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.d.ts +11 -8
- package/dist/useConfigurationApi.js +7 -4
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.d.ts +2 -2
- package/dist/useDocumentStorageApi.js +9 -6
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +48 -22
- package/src/AdminFieldRenderer.tsx +18 -371
- package/src/AdminFieldRendererCore.tsx +356 -0
- package/src/AdminModelForm.test.tsx +146 -40
- package/src/AdminModelForm.tsx +22 -17
- package/src/AdminModelList.test.tsx +14 -5
- package/src/AdminModelList.tsx +5 -5
- package/src/AdminModelTable.test.tsx +58 -31
- package/src/AdminModelTable.tsx +11 -10
- package/src/AdminNestedArrayField.tsx +91 -26
- package/src/AdminObjectPicker.tsx +33 -16
- package/src/AdminPrimitiveArrayField.test.tsx +14 -10
- package/src/AdminPrimitiveArrayField.tsx +2 -3
- package/src/AdminScriptList.test.tsx +7 -4
- package/src/AdminScriptList.tsx +2 -3
- package/src/AdminScriptRunModal.test.tsx +5 -2
- package/src/AdminScriptRunModal.tsx +2 -3
- package/src/AdminVersionConfig.test.tsx +47 -21
- package/src/AdminVersionConfig.tsx +29 -5
- package/src/CheckboxListEditor.test.tsx +9 -6
- package/src/ConfigurationScreen.test.tsx +16 -11
- package/src/ConfigurationScreen.tsx +43 -29
- package/src/ConsentFormEditor.test.tsx +95 -75
- package/src/ConsentFormEditor.tsx +76 -49
- package/src/ConsentFormList.test.tsx +28 -10
- package/src/ConsentFormList.tsx +14 -2
- package/src/ConsentResponseViewer.test.tsx +15 -12
- package/src/ConsentResponseViewer.tsx +3 -2
- package/src/DocumentStorageBrowser.test.tsx +69 -42
- package/src/DocumentStorageBrowser.tsx +4 -4
- package/src/LocaleContentEditor.test.tsx +28 -18
- package/src/isolated/AdminFieldRenderer.isolated.tsx +5 -2
- package/src/isolated/AdminNestedArrayField.isolated.tsx +49 -36
- package/src/isolated/AdminObjectPicker.isolated.tsx +31 -26
- package/src/isolated/AdminRefField.isolated.tsx +4 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +24 -17
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +80 -63
- package/src/isolated/hooks.isolated.tsx +40 -33
- package/src/types.ts +34 -4
- package/src/useAdminApi.ts +21 -13
- package/src/useAdminConfig.ts +5 -4
- package/src/useAdminScripts.ts +9 -7
- package/src/useConfigurationApi.ts +26 -12
- package/src/useDocumentStorageApi.ts +12 -9
|
@@ -1,40 +1,47 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
3
5
|
import React from "react";
|
|
6
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
4
7
|
import {act} from "../../../ui/node_modules/@testing-library/react-native";
|
|
8
|
+
import type {AdminApi} from "../types";
|
|
5
9
|
|
|
6
10
|
// Mock @terreno/ui so the Modal renders its children inline. The real Modal
|
|
7
11
|
// portal isn't mounted by the test renderer, which hides the cancel button.
|
|
8
12
|
mock.module("@terreno/ui", () => {
|
|
9
13
|
const RN = require("react-native");
|
|
10
14
|
const ReactMod = require("react");
|
|
11
|
-
const Box = ({children, ...rest}:
|
|
12
|
-
|
|
15
|
+
const Box = ({children, ...rest}: Record<string, unknown>) =>
|
|
16
|
+
ReactMod.createElement(RN.View, rest, children);
|
|
17
|
+
const Button = ({text, onClick, testID}: Record<string, unknown>) =>
|
|
13
18
|
ReactMod.createElement(
|
|
14
19
|
RN.Pressable,
|
|
15
20
|
{onPress: onClick, testID},
|
|
16
21
|
ReactMod.createElement(RN.Text, {}, text)
|
|
17
22
|
);
|
|
18
|
-
const Heading = ({children}:
|
|
23
|
+
const Heading = ({children}: Record<string, unknown>) =>
|
|
24
|
+
ReactMod.createElement(RN.Text, {}, children);
|
|
19
25
|
const Icon = () => ReactMod.createElement(RN.View, {});
|
|
20
|
-
const Modal = ({children, visible}:
|
|
26
|
+
const Modal = ({children, visible}: Record<string, unknown>) => {
|
|
21
27
|
if (!visible) return null;
|
|
22
28
|
return ReactMod.createElement(RN.View, {testID: "mock-modal"}, children);
|
|
23
29
|
};
|
|
24
30
|
const Spinner = () => ReactMod.createElement(RN.View, {testID: "spinner"});
|
|
25
|
-
const Text = ({children, ...rest}:
|
|
31
|
+
const Text = ({children, ...rest}: Record<string, unknown>) =>
|
|
32
|
+
ReactMod.createElement(RN.Text, rest, children);
|
|
26
33
|
return {Box, Button, Heading, Icon, Modal, Spinner, Text};
|
|
27
34
|
});
|
|
28
35
|
|
|
29
36
|
interface TaskState {
|
|
30
|
-
data: {task:
|
|
31
|
-
error:
|
|
37
|
+
data: {task: Record<string, unknown>} | undefined;
|
|
38
|
+
error: unknown;
|
|
32
39
|
isLoading: boolean;
|
|
33
40
|
}
|
|
34
41
|
interface MockState {
|
|
35
42
|
task: TaskState;
|
|
36
|
-
runImpl: (arg:
|
|
37
|
-
cancelImpl: (arg:
|
|
43
|
+
runImpl: (arg: unknown) => {unwrap: () => Promise<unknown>};
|
|
44
|
+
cancelImpl: (arg: unknown) => {unwrap: () => Promise<unknown>};
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
const state: MockState = {
|
|
@@ -43,16 +50,16 @@ const state: MockState = {
|
|
|
43
50
|
task: {data: undefined, error: null, isLoading: false},
|
|
44
51
|
};
|
|
45
52
|
|
|
46
|
-
const runCalls:
|
|
47
|
-
const cancelCalls:
|
|
53
|
+
const runCalls: unknown[] = [];
|
|
54
|
+
const cancelCalls: unknown[] = [];
|
|
48
55
|
|
|
49
56
|
// Stable function references so useEffect deps are reference-equal across
|
|
50
57
|
// renders (avoids re-firing the auto-start effect on every setState).
|
|
51
|
-
const stableRunScript = (arg:
|
|
58
|
+
const stableRunScript = (arg: unknown): {unwrap: () => Promise<unknown>} => {
|
|
52
59
|
runCalls.push(arg);
|
|
53
60
|
return state.runImpl(arg);
|
|
54
61
|
};
|
|
55
|
-
const stableCancelTask = (arg:
|
|
62
|
+
const stableCancelTask = (arg: unknown): {unwrap: () => Promise<unknown>} => {
|
|
56
63
|
cancelCalls.push(arg);
|
|
57
64
|
return state.cancelImpl(arg);
|
|
58
65
|
};
|
|
@@ -69,7 +76,7 @@ mock.module("../useAdminScripts", () => ({
|
|
|
69
76
|
|
|
70
77
|
import {AdminScriptRunModal} from "../AdminScriptRunModal";
|
|
71
78
|
|
|
72
|
-
const mockApi = {} as
|
|
79
|
+
const mockApi = {} as unknown as AdminApi;
|
|
73
80
|
|
|
74
81
|
const waitTicks = async (ms = 40): Promise<void> => {
|
|
75
82
|
await act(async () => {
|
|
@@ -254,7 +261,7 @@ describe("AdminScriptRunModal", () => {
|
|
|
254
261
|
await act(async () => {
|
|
255
262
|
try {
|
|
256
263
|
const btn = getByTestId("admin-script-cancel-button");
|
|
257
|
-
(btn as
|
|
264
|
+
(btn as ReactTestInstance).props.onClick?.();
|
|
258
265
|
} catch {
|
|
259
266
|
/* accept missing testID */
|
|
260
267
|
}
|
|
@@ -280,11 +287,11 @@ describe("AdminScriptRunModal", () => {
|
|
|
280
287
|
);
|
|
281
288
|
await waitTicks();
|
|
282
289
|
const cancelBtns = UNSAFE_root.findAll(
|
|
283
|
-
(n:
|
|
290
|
+
(n: ReactTestInstance) => n.props?.testID === "admin-script-cancel-button"
|
|
284
291
|
);
|
|
285
292
|
if (cancelBtns.length > 0) {
|
|
286
293
|
await act(async () => {
|
|
287
|
-
(cancelBtns[0] as
|
|
294
|
+
(cancelBtns[0] as ReactTestInstance).props.onClick?.();
|
|
288
295
|
await new Promise((r) => setTimeout(r, 20));
|
|
289
296
|
});
|
|
290
297
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
// noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
3
5
|
import React from "react";
|
|
4
6
|
import {Platform} from "react-native";
|
|
7
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
5
8
|
import {act, fireEvent} from "../../../ui/node_modules/@testing-library/react-native";
|
|
9
|
+
import type {AdminApi} from "../types";
|
|
6
10
|
|
|
7
11
|
mock.module("react-native-webview", () => ({
|
|
8
|
-
WebView: (props:
|
|
12
|
+
WebView: (props: Record<string, unknown>) =>
|
|
13
|
+
React.createElement("WebView", {...props, testID: "mock-webview"}),
|
|
9
14
|
}));
|
|
10
15
|
|
|
11
16
|
// Mock @terreno/ui to render Modal children inline so we can interact with
|
|
@@ -13,16 +18,17 @@ mock.module("react-native-webview", () => ({
|
|
|
13
18
|
mock.module("@terreno/ui", () => {
|
|
14
19
|
const RN = require("react-native");
|
|
15
20
|
const ReactMod = require("react");
|
|
16
|
-
const Box = ({children, ...rest}:
|
|
17
|
-
|
|
21
|
+
const Box = ({children, ...rest}: Record<string, unknown>) =>
|
|
22
|
+
ReactMod.createElement(RN.View, rest, children);
|
|
23
|
+
const Button = ({text, onClick, iconName, testID}: Record<string, unknown>) =>
|
|
18
24
|
ReactMod.createElement(
|
|
19
25
|
RN.Pressable,
|
|
20
26
|
{onPress: onClick, testID: testID ?? `btn-${iconName ?? text}`},
|
|
21
27
|
ReactMod.createElement(RN.Text, {}, text)
|
|
22
28
|
);
|
|
23
|
-
const DataTable = ({data, customColumnComponentMap, columns}:
|
|
24
|
-
const rows = (data ?? []).map((row:
|
|
25
|
-
const cells = row.map((cell:
|
|
29
|
+
const DataTable = ({data, customColumnComponentMap, columns}: Record<string, unknown>) => {
|
|
30
|
+
const rows = ((data as unknown[]) ?? []).map((row: unknown[], rowIdx: number) => {
|
|
31
|
+
const cells = row.map((cell: unknown, cellIdx: number) => {
|
|
26
32
|
const col = columns[cellIdx];
|
|
27
33
|
const CustomComp = customColumnComponentMap?.[col.columnType];
|
|
28
34
|
if (CustomComp) {
|
|
@@ -42,12 +48,12 @@ mock.module("@terreno/ui", () => {
|
|
|
42
48
|
});
|
|
43
49
|
return ReactMod.createElement(RN.View, {testID: "mock-data-table"}, rows);
|
|
44
50
|
};
|
|
45
|
-
const IconButton = ({onClick, accessibilityLabel, testID}:
|
|
51
|
+
const IconButton = ({onClick, accessibilityLabel, testID}: Record<string, unknown>) =>
|
|
46
52
|
ReactMod.createElement(RN.Pressable, {
|
|
47
53
|
onPress: onClick,
|
|
48
54
|
testID: testID ?? `icon-${accessibilityLabel}`,
|
|
49
55
|
});
|
|
50
|
-
const Link = ({onClick, text, testID}:
|
|
56
|
+
const Link = ({onClick, text, testID}: Record<string, unknown>) =>
|
|
51
57
|
ReactMod.createElement(
|
|
52
58
|
RN.Pressable,
|
|
53
59
|
{onPress: onClick, testID: testID ?? `link-${text}`},
|
|
@@ -62,7 +68,7 @@ mock.module("@terreno/ui", () => {
|
|
|
62
68
|
secondaryButtonOnClick,
|
|
63
69
|
onDismiss,
|
|
64
70
|
title,
|
|
65
|
-
}:
|
|
71
|
+
}: Record<string, unknown>) => {
|
|
66
72
|
if (!visible) return null;
|
|
67
73
|
return ReactMod.createElement(RN.View, {testID: `modal-${title}`}, [
|
|
68
74
|
ReactMod.createElement(RN.Text, {key: "title"}, title),
|
|
@@ -100,14 +106,15 @@ mock.module("@terreno/ui", () => {
|
|
|
100
106
|
),
|
|
101
107
|
]);
|
|
102
108
|
};
|
|
103
|
-
const Page = ({children, title}:
|
|
109
|
+
const Page = ({children, title}: Record<string, unknown>) =>
|
|
104
110
|
ReactMod.createElement(RN.View, {testID: "mock-page"}, [
|
|
105
111
|
ReactMod.createElement(RN.Text, {key: "t"}, title),
|
|
106
112
|
...(Array.isArray(children) ? children : [children]),
|
|
107
113
|
]);
|
|
108
114
|
const Spinner = () => ReactMod.createElement(RN.View, {testID: "spinner"});
|
|
109
|
-
const Text = ({children, ...rest}:
|
|
110
|
-
|
|
115
|
+
const Text = ({children, ...rest}: Record<string, unknown>) =>
|
|
116
|
+
ReactMod.createElement(RN.Text, rest, children);
|
|
117
|
+
const TextField = ({value, onChange, testID, placeholder, title}: Record<string, unknown>) =>
|
|
111
118
|
ReactMod.createElement(RN.TextInput, {
|
|
112
119
|
onChangeText: onChange,
|
|
113
120
|
placeholder,
|
|
@@ -129,10 +136,10 @@ mock.module("@terreno/ui", () => {
|
|
|
129
136
|
});
|
|
130
137
|
|
|
131
138
|
interface ListState {
|
|
132
|
-
data:
|
|
139
|
+
data: unknown;
|
|
133
140
|
isLoading: boolean;
|
|
134
141
|
isError: boolean;
|
|
135
|
-
error:
|
|
142
|
+
error: unknown;
|
|
136
143
|
}
|
|
137
144
|
const listState: ListState = {
|
|
138
145
|
data: undefined,
|
|
@@ -141,21 +148,21 @@ const listState: ListState = {
|
|
|
141
148
|
isLoading: false,
|
|
142
149
|
};
|
|
143
150
|
const refetchMock = mock(() => {});
|
|
144
|
-
const uploadCalls:
|
|
151
|
+
const uploadCalls: unknown[] = [];
|
|
145
152
|
const deleteCalls: string[] = [];
|
|
146
153
|
const deleteFolderCalls: string[] = [];
|
|
147
|
-
const createFolderCalls:
|
|
154
|
+
const createFolderCalls: unknown[] = [];
|
|
148
155
|
const downloadCalls: string[] = [];
|
|
149
|
-
let uploadImpl: (body:
|
|
150
|
-
let deleteImpl: (p: string) => Promise<
|
|
151
|
-
let deleteFolderImpl: (p: string) => Promise<
|
|
152
|
-
let createFolderImpl: (body:
|
|
153
|
-
let downloadImpl: (p: string) => Promise<
|
|
156
|
+
let uploadImpl: (body: unknown) => Promise<unknown> = async () => ({});
|
|
157
|
+
let deleteImpl: (p: string) => Promise<unknown> = async () => ({});
|
|
158
|
+
let deleteFolderImpl: (p: string) => Promise<unknown> = async () => ({});
|
|
159
|
+
let createFolderImpl: (body: unknown) => Promise<unknown> = async () => ({});
|
|
160
|
+
let downloadImpl: (p: string) => Promise<unknown> = async () => new Blob(["hi"]);
|
|
154
161
|
|
|
155
162
|
mock.module("../useDocumentStorageApi", () => ({
|
|
156
163
|
useDocumentStorageApi: () => ({
|
|
157
164
|
useCreateFolderMutation: () => [
|
|
158
|
-
(body:
|
|
165
|
+
(body: unknown) => ({
|
|
159
166
|
unwrap: async () => {
|
|
160
167
|
createFolderCalls.push(body);
|
|
161
168
|
return createFolderImpl(body);
|
|
@@ -199,7 +206,7 @@ mock.module("../useDocumentStorageApi", () => ({
|
|
|
199
206
|
return {...listState, refetch: refetchMock};
|
|
200
207
|
},
|
|
201
208
|
useUploadMutation: () => [
|
|
202
|
-
(body:
|
|
209
|
+
(body: unknown) => ({
|
|
203
210
|
unwrap: async () => {
|
|
204
211
|
uploadCalls.push(body);
|
|
205
212
|
return uploadImpl(body);
|
|
@@ -212,7 +219,7 @@ mock.module("../useDocumentStorageApi", () => ({
|
|
|
212
219
|
|
|
213
220
|
import {DocumentStorageBrowser} from "../DocumentStorageBrowser";
|
|
214
221
|
|
|
215
|
-
const press = async (el:
|
|
222
|
+
const press = async (el: ReactTestInstance): Promise<void> => {
|
|
216
223
|
await act(async () => {
|
|
217
224
|
fireEvent.press(el);
|
|
218
225
|
await new Promise((r) => setTimeout(r, 150));
|
|
@@ -242,7 +249,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
242
249
|
it("creates a folder via primary button", async () => {
|
|
243
250
|
listState.data = {files: [], folders: []};
|
|
244
251
|
const {getByTestId} = renderWithTheme(
|
|
245
|
-
<DocumentStorageBrowser api={{} as
|
|
252
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
246
253
|
);
|
|
247
254
|
await press(getByTestId("document-new-folder-button"));
|
|
248
255
|
const input = getByTestId("new-folder-name-input");
|
|
@@ -260,7 +267,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
260
267
|
it("skips create on whitespace-only folder name", async () => {
|
|
261
268
|
listState.data = {files: [], folders: []};
|
|
262
269
|
const {getByTestId} = renderWithTheme(
|
|
263
|
-
<DocumentStorageBrowser api={{} as
|
|
270
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
264
271
|
);
|
|
265
272
|
await press(getByTestId("document-new-folder-button"));
|
|
266
273
|
const input = getByTestId("new-folder-name-input");
|
|
@@ -274,7 +281,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
274
281
|
it("dismisses new folder modal via secondary button", async () => {
|
|
275
282
|
listState.data = {files: [], folders: []};
|
|
276
283
|
const {getByTestId} = renderWithTheme(
|
|
277
|
-
<DocumentStorageBrowser api={{} as
|
|
284
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
278
285
|
);
|
|
279
286
|
await press(getByTestId("document-new-folder-button"));
|
|
280
287
|
await press(getByTestId("modal-secondary-New Folder"));
|
|
@@ -287,7 +294,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
287
294
|
throw new Error("boom");
|
|
288
295
|
};
|
|
289
296
|
const {getByTestId} = renderWithTheme(
|
|
290
|
-
<DocumentStorageBrowser api={{} as
|
|
297
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
291
298
|
);
|
|
292
299
|
await press(getByTestId("document-new-folder-button"));
|
|
293
300
|
const input = getByTestId("new-folder-name-input");
|
|
@@ -301,7 +308,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
301
308
|
it("navigates into a folder via DocumentNameCell Link", async () => {
|
|
302
309
|
listState.data = {files: [], folders: ["sub/"]};
|
|
303
310
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
304
|
-
<DocumentStorageBrowser api={{} as
|
|
311
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
305
312
|
);
|
|
306
313
|
const folderLink = getByTestId("link-sub/");
|
|
307
314
|
await press(folderLink);
|
|
@@ -324,7 +331,11 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
324
331
|
};
|
|
325
332
|
const onFileSelect = mock(() => undefined);
|
|
326
333
|
const {getByTestId} = renderWithTheme(
|
|
327
|
-
<DocumentStorageBrowser
|
|
334
|
+
<DocumentStorageBrowser
|
|
335
|
+
api={{} as unknown as AdminApi}
|
|
336
|
+
basePath="/documents"
|
|
337
|
+
onFileSelect={onFileSelect}
|
|
338
|
+
/>
|
|
328
339
|
);
|
|
329
340
|
await press(getByTestId("link-a.txt"));
|
|
330
341
|
expect(onFileSelect).toHaveBeenCalled();
|
|
@@ -347,16 +358,16 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
347
358
|
};
|
|
348
359
|
const createObjectURL = mock(() => "blob:123");
|
|
349
360
|
const revokeObjectURL = mock(() => undefined);
|
|
350
|
-
(globalThis as
|
|
351
|
-
(globalThis as
|
|
361
|
+
(globalThis as Record<string, unknown>).URL.createObjectURL = createObjectURL;
|
|
362
|
+
(globalThis as Record<string, unknown>).URL.revokeObjectURL = revokeObjectURL;
|
|
352
363
|
const appendChild = mock(() => undefined);
|
|
353
364
|
const removeChild = mock(() => undefined);
|
|
354
|
-
(globalThis as
|
|
365
|
+
(globalThis as Record<string, unknown>).document = {
|
|
355
366
|
body: {appendChild, removeChild},
|
|
356
367
|
createElement: () => ({click: () => {}, download: "", href: ""}),
|
|
357
368
|
};
|
|
358
369
|
const {getByTestId} = renderWithTheme(
|
|
359
|
-
<DocumentStorageBrowser api={{} as
|
|
370
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
360
371
|
);
|
|
361
372
|
await press(getByTestId("icon-Download"));
|
|
362
373
|
expect(downloadCalls.length).toBe(1);
|
|
@@ -380,7 +391,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
380
391
|
folders: [],
|
|
381
392
|
};
|
|
382
393
|
const {getByTestId} = renderWithTheme(
|
|
383
|
-
<DocumentStorageBrowser api={{} as
|
|
394
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
384
395
|
);
|
|
385
396
|
await press(getByTestId("icon-Download"));
|
|
386
397
|
expect(downloadCalls.length).toBe(1);
|
|
@@ -400,7 +411,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
400
411
|
folders: [],
|
|
401
412
|
};
|
|
402
413
|
const {getByTestId} = renderWithTheme(
|
|
403
|
-
<DocumentStorageBrowser api={{} as
|
|
414
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
404
415
|
);
|
|
405
416
|
await press(getByTestId("icon-Delete"));
|
|
406
417
|
expect(deleteCalls.length).toBe(1);
|
|
@@ -424,7 +435,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
424
435
|
folders: [],
|
|
425
436
|
};
|
|
426
437
|
const {getByTestId} = renderWithTheme(
|
|
427
|
-
<DocumentStorageBrowser api={{} as
|
|
438
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
428
439
|
);
|
|
429
440
|
await press(getByTestId("icon-Delete"));
|
|
430
441
|
expect(deleteCalls.length).toBe(1);
|
|
@@ -433,7 +444,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
433
444
|
it("deletes a folder via folder-level IconButton", async () => {
|
|
434
445
|
listState.data = {files: [], folders: ["folder1/"]};
|
|
435
446
|
const {getByTestId} = renderWithTheme(
|
|
436
|
-
<DocumentStorageBrowser api={{} as
|
|
447
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
437
448
|
);
|
|
438
449
|
await press(getByTestId("icon-Delete folder"));
|
|
439
450
|
expect(deleteFolderCalls.length).toBe(1);
|
|
@@ -446,7 +457,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
446
457
|
};
|
|
447
458
|
listState.data = {files: [], folders: ["folder1/"]};
|
|
448
459
|
const {getByTestId} = renderWithTheme(
|
|
449
|
-
<DocumentStorageBrowser api={{} as
|
|
460
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
450
461
|
);
|
|
451
462
|
await press(getByTestId("icon-Delete folder"));
|
|
452
463
|
expect(deleteFolderCalls.length).toBe(1);
|
|
@@ -466,7 +477,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
466
477
|
folders: [],
|
|
467
478
|
};
|
|
468
479
|
const {toJSON} = renderWithTheme(
|
|
469
|
-
<DocumentStorageBrowser api={{} as
|
|
480
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
470
481
|
);
|
|
471
482
|
expect(toJSON()).toBeDefined();
|
|
472
483
|
});
|
|
@@ -486,7 +497,11 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
486
497
|
folders: ["f/"],
|
|
487
498
|
};
|
|
488
499
|
const {queryByTestId, toJSON} = renderWithTheme(
|
|
489
|
-
<DocumentStorageBrowser
|
|
500
|
+
<DocumentStorageBrowser
|
|
501
|
+
allowDelete={false}
|
|
502
|
+
api={{} as unknown as AdminApi}
|
|
503
|
+
basePath="/documents"
|
|
504
|
+
/>
|
|
490
505
|
);
|
|
491
506
|
expect(queryByTestId("icon-Delete")).toBeNull();
|
|
492
507
|
expect(queryByTestId("icon-Delete folder")).toBeNull();
|
|
@@ -496,15 +511,15 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
496
511
|
it("uploads file via hidden input onChange", async () => {
|
|
497
512
|
listState.data = {files: [], folders: []};
|
|
498
513
|
const {UNSAFE_root} = renderWithTheme(
|
|
499
|
-
<DocumentStorageBrowser api={{} as
|
|
514
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
500
515
|
);
|
|
501
516
|
const fileInputs = UNSAFE_root.findAll(
|
|
502
|
-
(node:
|
|
517
|
+
(node: ReactTestInstance) => node.type === "input" && node.props?.type === "file"
|
|
503
518
|
);
|
|
504
519
|
expect(fileInputs.length).toBe(1);
|
|
505
520
|
const fakeFile = new File(["x"], "x.txt", {type: "text/plain"});
|
|
506
521
|
await act(async () => {
|
|
507
|
-
(fileInputs[0] as
|
|
522
|
+
(fileInputs[0] as ReactTestInstance).props.onChange({
|
|
508
523
|
target: {files: [fakeFile], value: ""},
|
|
509
524
|
});
|
|
510
525
|
await new Promise((r) => setTimeout(r, 30));
|
|
@@ -518,14 +533,14 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
518
533
|
};
|
|
519
534
|
listState.data = {files: [], folders: []};
|
|
520
535
|
const {UNSAFE_root} = renderWithTheme(
|
|
521
|
-
<DocumentStorageBrowser api={{} as
|
|
536
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
522
537
|
);
|
|
523
538
|
const fileInputs = UNSAFE_root.findAll(
|
|
524
|
-
(node:
|
|
539
|
+
(node: ReactTestInstance) => node.type === "input" && node.props?.type === "file"
|
|
525
540
|
);
|
|
526
541
|
const fakeFile = new File(["x"], "x.txt", {type: "text/plain"});
|
|
527
542
|
await act(async () => {
|
|
528
|
-
(fileInputs[0] as
|
|
543
|
+
(fileInputs[0] as ReactTestInstance).props.onChange({
|
|
529
544
|
target: {files: [fakeFile], value: ""},
|
|
530
545
|
});
|
|
531
546
|
await new Promise((r) => setTimeout(r, 30));
|
|
@@ -536,13 +551,13 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
536
551
|
it("ignores upload when no file selected", async () => {
|
|
537
552
|
listState.data = {files: [], folders: []};
|
|
538
553
|
const {UNSAFE_root} = renderWithTheme(
|
|
539
|
-
<DocumentStorageBrowser api={{} as
|
|
554
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
540
555
|
);
|
|
541
556
|
const fileInputs = UNSAFE_root.findAll(
|
|
542
|
-
(node:
|
|
557
|
+
(node: ReactTestInstance) => node.type === "input" && node.props?.type === "file"
|
|
543
558
|
);
|
|
544
559
|
await act(async () => {
|
|
545
|
-
(fileInputs[0] as
|
|
560
|
+
(fileInputs[0] as ReactTestInstance).props.onChange({target: {files: []}});
|
|
546
561
|
await new Promise((r) => setTimeout(r, 10));
|
|
547
562
|
});
|
|
548
563
|
expect(uploadCalls.length).toBe(0);
|
|
@@ -551,7 +566,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
551
566
|
it("renders breadcrumb links after navigating into a folder", async () => {
|
|
552
567
|
listState.data = {files: [], folders: ["dir-a/"]};
|
|
553
568
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
554
|
-
<DocumentStorageBrowser api={{} as
|
|
569
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
555
570
|
);
|
|
556
571
|
await press(getByTestId("link-dir-a/"));
|
|
557
572
|
// Back to Root: breadcrumb should include Root link
|
|
@@ -568,7 +583,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
568
583
|
const onSettingsPress = mock(() => undefined);
|
|
569
584
|
const {getByText} = renderWithTheme(
|
|
570
585
|
<DocumentStorageBrowser
|
|
571
|
-
api={{} as
|
|
586
|
+
api={{} as unknown as AdminApi}
|
|
572
587
|
basePath="/documents"
|
|
573
588
|
onSettingsPress={onSettingsPress}
|
|
574
589
|
/>
|
|
@@ -580,7 +595,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
580
595
|
it("refetches via refresh button when data is loaded", async () => {
|
|
581
596
|
listState.data = {files: [], folders: []};
|
|
582
597
|
const {getByTestId} = renderWithTheme(
|
|
583
|
-
<DocumentStorageBrowser api={{} as
|
|
598
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
584
599
|
);
|
|
585
600
|
await press(getByTestId("document-refresh-button"));
|
|
586
601
|
expect(refetchMock).toHaveBeenCalled();
|
|
@@ -590,7 +605,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
590
605
|
listState.isError = true;
|
|
591
606
|
listState.error = {status: 503};
|
|
592
607
|
const {getByTestId} = renderWithTheme(
|
|
593
|
-
<DocumentStorageBrowser api={{} as
|
|
608
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
594
609
|
);
|
|
595
610
|
await act(async () => {
|
|
596
611
|
await new Promise((r) => setTimeout(r, 30));
|
|
@@ -605,7 +620,7 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
605
620
|
const onSettingsPress = mock(() => undefined);
|
|
606
621
|
const {getByText} = renderWithTheme(
|
|
607
622
|
<DocumentStorageBrowser
|
|
608
|
-
api={{} as
|
|
623
|
+
api={{} as unknown as AdminApi}
|
|
609
624
|
basePath="/documents"
|
|
610
625
|
onSettingsPress={onSettingsPress}
|
|
611
626
|
/>
|
|
@@ -618,16 +633,16 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
618
633
|
listState.data = {files: [], folders: []};
|
|
619
634
|
const clickMock = mock(() => undefined);
|
|
620
635
|
const {UNSAFE_root, getByTestId} = renderWithTheme(
|
|
621
|
-
<DocumentStorageBrowser api={{} as
|
|
636
|
+
<DocumentStorageBrowser api={{} as unknown as AdminApi} basePath="/documents" />
|
|
622
637
|
);
|
|
623
638
|
// Locate the hidden file input and inject a click spy to verify the
|
|
624
639
|
// button's handler reaches the underlying DOM ref.
|
|
625
640
|
const fileInputs = UNSAFE_root.findAll(
|
|
626
|
-
(node:
|
|
641
|
+
(node: ReactTestInstance) => node.type === "input" && node.props?.type === "file"
|
|
627
642
|
);
|
|
628
643
|
expect(fileInputs.length).toBe(1);
|
|
629
644
|
// Manually override instance.click since the test renderer doesn't execute DOM methods.
|
|
630
|
-
const instance = fileInputs[0] as
|
|
645
|
+
const instance = fileInputs[0] as ReactTestInstance & {instance?: {click: () => void}};
|
|
631
646
|
if (instance.instance) {
|
|
632
647
|
instance.instance.click = clickMock;
|
|
633
648
|
}
|
|
@@ -641,8 +656,8 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
641
656
|
downloadImpl = async () => blob;
|
|
642
657
|
const createObjectURL = mock(() => "blob:img-123");
|
|
643
658
|
const revokeObjectURL = mock(() => undefined);
|
|
644
|
-
(globalThis as
|
|
645
|
-
(globalThis as
|
|
659
|
+
(globalThis as Record<string, unknown>).URL.createObjectURL = createObjectURL;
|
|
660
|
+
(globalThis as Record<string, unknown>).URL.revokeObjectURL = revokeObjectURL;
|
|
646
661
|
listState.data = {
|
|
647
662
|
files: [
|
|
648
663
|
{
|
|
@@ -660,10 +675,10 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
660
675
|
// commented out), so we reach through the ActionsCell to find a node
|
|
661
676
|
// whose onClick navigates to handleViewFile. If not found, invoke
|
|
662
677
|
// handleViewFile by seeking props that match the pattern.
|
|
663
|
-
const captured:
|
|
678
|
+
const captured: unknown[] = [];
|
|
664
679
|
const {UNSAFE_root, unmount} = renderWithTheme(
|
|
665
680
|
<DocumentStorageBrowser
|
|
666
|
-
api={{} as
|
|
681
|
+
api={{} as unknown as AdminApi}
|
|
667
682
|
basePath="/documents"
|
|
668
683
|
onFileSelect={(file) => {
|
|
669
684
|
captured.push(file);
|
|
@@ -671,7 +686,9 @@ describe("DocumentStorageBrowser (isolated)", () => {
|
|
|
671
686
|
/>
|
|
672
687
|
);
|
|
673
688
|
// Use the fact that onFileSelect is provided → Link wrapper exists.
|
|
674
|
-
const fileLink = UNSAFE_root.findAll(
|
|
689
|
+
const fileLink = UNSAFE_root.findAll(
|
|
690
|
+
(n: ReactTestInstance) => n.props?.testID === "link-img.png"
|
|
691
|
+
);
|
|
675
692
|
expect(fileLink.length).toBeGreaterThan(0);
|
|
676
693
|
await press(fileLink[0]);
|
|
677
694
|
expect(captured.length).toBe(1);
|