@terreno/admin-frontend 0.31.0 → 57.0.0-beta.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/AdminShell.d.ts +5 -0
- package/dist/AdminShell.js +100 -31
- package/dist/AdminShell.js.map +1 -1
- package/dist/ConsentHistory.d.ts +9 -0
- package/dist/ConsentHistory.js +61 -0
- package/dist/ConsentHistory.js.map +1 -0
- package/dist/generateConsentHistoryPdf.d.ts +2 -0
- package/dist/generateConsentHistoryPdf.js +225 -0
- package/dist/generateConsentHistoryPdf.js.map +1 -0
- package/dist/generateConsentPdf.js +75 -28
- package/dist/generateConsentPdf.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/pdfUtils.d.ts +9 -0
- package/dist/pdfUtils.js +25 -0
- package/dist/pdfUtils.js.map +1 -0
- package/dist/useAdminBackgroundTask.js.map +1 -1
- package/dist/useConsentHistory.d.ts +63 -0
- package/dist/useConsentHistory.js +40 -0
- package/dist/useConsentHistory.js.map +1 -0
- package/package.json +11 -9
- package/src/AdminModelForm.test.tsx +1 -1
- package/src/AdminModelList.test.tsx +1 -1
- package/src/AdminModelTable.test.tsx +1 -1
- package/src/AdminPrimitiveArrayField.test.tsx +1 -1
- package/src/AdminScriptList.test.tsx +1 -1
- package/src/AdminShell.test.tsx +191 -0
- package/src/AdminShell.tsx +331 -144
- package/src/AdminVersionConfig.test.tsx +1 -1
- package/src/CheckboxListEditor.test.tsx +1 -1
- package/src/ConfigurationScreen.test.tsx +1 -1
- package/src/ConsentFormEditor.test.tsx +1 -1
- package/src/ConsentFormList.test.tsx +1 -1
- package/src/ConsentHistory.test.tsx +161 -0
- package/src/ConsentHistory.tsx +251 -0
- package/src/ConsentResponseViewer.test.tsx +1 -1
- package/src/DocumentStorageBrowser.test.tsx +1 -1
- package/src/LocaleContentEditor.test.tsx +1 -1
- package/src/generateConsentHistoryPdf.ts +259 -0
- package/src/generateConsentPdf.ts +96 -31
- package/src/index.tsx +3 -0
- package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -1
- package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -1
- package/src/isolated/AdminObjectPicker.isolated.tsx +1 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -1
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -1
- package/src/isolated/generateConsentPdf.isolated.ts +5 -0
- package/src/pdfUtils.ts +28 -0
- package/src/useAdminBackgroundTask.ts +1 -0
- package/src/useConsentHistory.test.ts +106 -0
- package/src/useConsentHistory.ts +94 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// noExplicitAny: test harness doubles
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test harness doubles
|
|
3
|
+
import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
4
|
+
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
5
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import type {ScaledSize} from "react-native";
|
|
8
|
+
import {useWindowDimensions} from "react-native";
|
|
9
|
+
import {SafeAreaView} from "react-native-safe-area-context";
|
|
10
|
+
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
11
|
+
|
|
12
|
+
const mockRouterPush = mock((_href: string) => {});
|
|
13
|
+
|
|
14
|
+
mock.module("expo-router", () => ({
|
|
15
|
+
router: {push: mockRouterPush},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const configState: {
|
|
19
|
+
config: AdminConfigResponse | null;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
} = {
|
|
23
|
+
config: null,
|
|
24
|
+
error: null,
|
|
25
|
+
isLoading: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
mock.module("./useAdminConfig", () => ({
|
|
29
|
+
useAdminConfig: () => ({
|
|
30
|
+
config: configState.config,
|
|
31
|
+
error: configState.error,
|
|
32
|
+
isLoading: configState.isLoading,
|
|
33
|
+
}),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
import {AdminShell} from "./AdminShell";
|
|
37
|
+
|
|
38
|
+
type WindowDimensionsImpl = () => ScaledSize;
|
|
39
|
+
type MockableUseWindowDimensions = WindowDimensionsImpl & {
|
|
40
|
+
mockImplementation?: (impl: WindowDimensionsImpl) => void;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const getScaledSize =
|
|
44
|
+
(width: number): WindowDimensionsImpl =>
|
|
45
|
+
(): ScaledSize => ({
|
|
46
|
+
fontScale: 1,
|
|
47
|
+
height: 1000,
|
|
48
|
+
scale: 2,
|
|
49
|
+
width,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const setWindowWidth = (width: number): (() => void) => {
|
|
53
|
+
const useWindowDimensionsMock = useWindowDimensions as MockableUseWindowDimensions;
|
|
54
|
+
const dimensionsImpl = getScaledSize(width);
|
|
55
|
+
|
|
56
|
+
if (typeof useWindowDimensionsMock.mockImplementation === "function") {
|
|
57
|
+
useWindowDimensionsMock.mockImplementation(dimensionsImpl);
|
|
58
|
+
|
|
59
|
+
return (): void => {
|
|
60
|
+
useWindowDimensionsMock.mockImplementation(getScaledSize(375));
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (): void => {};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const buildConfig = (): AdminConfigResponse => ({
|
|
68
|
+
customScreens: [],
|
|
69
|
+
models: [
|
|
70
|
+
{
|
|
71
|
+
defaultSort: "-created",
|
|
72
|
+
displayName: "Todos",
|
|
73
|
+
fields: {title: {required: true, type: "string"}},
|
|
74
|
+
listFields: ["title"],
|
|
75
|
+
name: "Todo",
|
|
76
|
+
routePath: "/admin/todos",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
scripts: [{description: "Seed", name: "seed"}],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const mockApi = {} as unknown as AdminApi;
|
|
83
|
+
|
|
84
|
+
describe("AdminShell", () => {
|
|
85
|
+
let restoreWindowWidth: (() => void) | undefined;
|
|
86
|
+
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
configState.config = buildConfig();
|
|
89
|
+
configState.error = null;
|
|
90
|
+
configState.isLoading = false;
|
|
91
|
+
mockRouterPush.mockClear();
|
|
92
|
+
restoreWindowWidth = setWindowWidth(375);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
restoreWindowWidth?.();
|
|
97
|
+
restoreWindowWidth = undefined;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("shows the fixed sidebar on desktop widths", () => {
|
|
101
|
+
restoreWindowWidth?.();
|
|
102
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
103
|
+
|
|
104
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
105
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
106
|
+
<React.Fragment />
|
|
107
|
+
</AdminShell>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(getByTestId("admin-shell-sidebar")).toBeTruthy();
|
|
111
|
+
expect(queryByTestId("admin-shell-menu-button")).toBeNull();
|
|
112
|
+
expect(queryByTestId("admin-shell-mobile-header")).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("hides the fixed sidebar and shows a hamburger header below 768px", () => {
|
|
116
|
+
const {getByTestId, getByLabelText, queryByTestId, UNSAFE_root} = renderWithTheme(
|
|
117
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
118
|
+
<React.Fragment />
|
|
119
|
+
</AdminShell>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(queryByTestId("admin-shell-sidebar")).toBeNull();
|
|
123
|
+
expect(getByTestId("admin-shell-mobile-header")).toBeTruthy();
|
|
124
|
+
expect(getByTestId("admin-shell-menu-button-clickable")).toBeTruthy();
|
|
125
|
+
expect(getByLabelText("Open navigation menu")).toBeTruthy();
|
|
126
|
+
expect(UNSAFE_root.findAllByType(SafeAreaView)).toHaveLength(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("opens and closes the navigation drawer from the hamburger menu", async () => {
|
|
130
|
+
const {getByTestId, getByLabelText, queryByTestId} = renderWithTheme(
|
|
131
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
132
|
+
<React.Fragment />
|
|
133
|
+
</AdminShell>
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(queryByTestId("admin-shell-drawer")).toBeNull();
|
|
137
|
+
|
|
138
|
+
await act(async () => {
|
|
139
|
+
fireEvent.press(getByTestId("admin-shell-menu-button-clickable"));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
expect(getByTestId("admin-shell-drawer")).toBeTruthy();
|
|
143
|
+
expect(getByTestId("admin-shell-drawer-backdrop-clickable")).toBeTruthy();
|
|
144
|
+
expect(getByLabelText("Close navigation menu")).toBeTruthy();
|
|
145
|
+
|
|
146
|
+
await act(async () => {
|
|
147
|
+
fireEvent.press(getByTestId("admin-shell-drawer-close-clickable"));
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
expect(queryByTestId("admin-shell-drawer")).toBeNull();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("closes the drawer when the backdrop is pressed", async () => {
|
|
154
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
155
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
156
|
+
<React.Fragment />
|
|
157
|
+
</AdminShell>
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
await act(async () => {
|
|
161
|
+
fireEvent.press(getByTestId("admin-shell-menu-button-clickable"));
|
|
162
|
+
});
|
|
163
|
+
expect(getByTestId("admin-shell-drawer")).toBeTruthy();
|
|
164
|
+
|
|
165
|
+
await act(async () => {
|
|
166
|
+
fireEvent.press(getByTestId("admin-shell-drawer-backdrop-clickable"));
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(queryByTestId("admin-shell-drawer")).toBeNull();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("closes the drawer after selecting a navigation item", async () => {
|
|
173
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
174
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
175
|
+
<React.Fragment />
|
|
176
|
+
</AdminShell>
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
await act(async () => {
|
|
180
|
+
fireEvent.press(getByTestId("admin-shell-menu-button-clickable"));
|
|
181
|
+
});
|
|
182
|
+
expect(getByTestId("admin-shell-drawer")).toBeTruthy();
|
|
183
|
+
|
|
184
|
+
await act(async () => {
|
|
185
|
+
fireEvent.press(getByTestId("admin-shell-nav-home-clickable"));
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(mockRouterPush).toHaveBeenCalled();
|
|
189
|
+
expect(queryByTestId("admin-shell-drawer")).toBeNull();
|
|
190
|
+
});
|
|
191
|
+
});
|