@terreno/ui 57.21.0 → 58.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/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +43 -0
- package/dist/ActionSheet.d.ts +9 -9
- package/dist/ActionSheet.d.ts.map +1 -1
- package/dist/ActionSheet.js +11 -4
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AnnouncementNavigator.d.ts +7 -1
- package/dist/AnnouncementNavigator.d.ts.map +1 -1
- package/dist/AnnouncementNavigator.js +15 -16
- package/dist/AnnouncementNavigator.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +1 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +3 -1
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +16 -12
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -3
- package/dist/ConsentNavigator.d.ts.map +1 -1
- package/dist/ConsentNavigator.js +4 -4
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DataTable.d.ts.map +1 -1
- package/dist/DataTable.js +37 -12
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DropdownPanel.d.ts +0 -5
- package/dist/DropdownPanel.d.ts.map +1 -1
- package/dist/DropdownPanel.js +0 -5
- package/dist/DropdownPanel.js.map +1 -1
- package/dist/FilterAccordion.d.ts.map +1 -1
- package/dist/FilterAccordion.js.map +1 -1
- package/dist/FilterBoolean.d.ts.map +1 -1
- package/dist/FilterBoolean.js.map +1 -1
- package/dist/FilterSelectMenu.js +1 -1
- package/dist/FilterSelectMenu.js.map +1 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +6 -12
- package/dist/Heading.js.map +1 -1
- package/dist/HeightField.d.ts.map +1 -1
- package/dist/HeightField.js +1 -1
- package/dist/HeightField.js.map +1 -1
- package/dist/Hyperlink.d.ts.map +1 -1
- package/dist/Hyperlink.js +6 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/MarkdownEditorField.d.ts.map +1 -1
- package/dist/MarkdownEditorField.js +1 -1
- package/dist/MarkdownEditorField.js.map +1 -1
- package/dist/OfflineBanner.d.ts +3 -2
- package/dist/OfflineBanner.d.ts.map +1 -1
- package/dist/OfflineBanner.js +3 -2
- package/dist/OfflineBanner.js.map +1 -1
- package/dist/OtpField.d.ts.map +1 -1
- package/dist/OtpField.js.map +1 -1
- package/dist/PickerSelect.d.ts +4 -4
- package/dist/PickerSelect.d.ts.map +1 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/ProvisionalConsentSigner.d.ts +3 -2
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -1
- package/dist/ProvisionalConsentSigner.js +2 -2
- package/dist/ProvisionalConsentSigner.js.map +1 -1
- package/dist/SidebarNavigation.js +2 -2
- package/dist/SidebarNavigation.js.map +1 -1
- package/dist/SidebarNavigation.native.js +2 -2
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/Skeleton.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +27 -50
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js.map +1 -1
- package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
- package/dist/ThumbsUpDownFeedback.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +1 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +3 -3
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +1 -1
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/announcementPlatform.d.ts +5 -0
- package/dist/announcementPlatform.d.ts.map +1 -1
- package/dist/announcementPlatform.js +9 -0
- package/dist/announcementPlatform.js.map +1 -1
- package/dist/asks/AskCard.d.ts +2 -2
- package/dist/asks/AskCard.d.ts.map +1 -1
- package/dist/dataTableColumnWidths.d.ts +76 -0
- package/dist/dataTableColumnWidths.d.ts.map +1 -0
- package/dist/dataTableColumnWidths.js +181 -0
- package/dist/dataTableColumnWidths.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/requestClient.d.ts +71 -0
- package/dist/requestClient.d.ts.map +1 -0
- package/dist/requestClient.js +139 -0
- package/dist/requestClient.js.map +1 -0
- package/dist/security/PasswordCard.d.ts.map +1 -1
- package/dist/security/PasswordCard.js.map +1 -1
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -1
- package/dist/security/TwoFactorSettingsCard.js +1 -1
- package/dist/security/TwoFactorSettingsCard.js.map +1 -1
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/table/Table.d.ts.map +1 -1
- package/dist/table/Table.js.map +1 -1
- package/dist/table/TableTitle.d.ts.map +1 -1
- package/dist/table/TableTitle.js +2 -1
- package/dist/table/TableTitle.js.map +1 -1
- package/dist/textFontSizes.d.ts +12 -0
- package/dist/textFontSizes.d.ts.map +1 -0
- package/dist/textFontSizes.js +21 -0
- package/dist/textFontSizes.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +8 -63
- package/dist/useAcknowledgeAnnouncement.d.ts.map +1 -1
- package/dist/useAcknowledgeAnnouncement.js +31 -80
- package/dist/useAcknowledgeAnnouncement.js.map +1 -1
- package/dist/useAnnouncements.d.ts +14 -47
- package/dist/useAnnouncements.d.ts.map +1 -1
- package/dist/useAnnouncements.js +30 -57
- package/dist/useAnnouncements.js.map +1 -1
- package/dist/useConsentForms.d.ts +6 -38
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +25 -48
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +7 -58
- package/dist/useProvisionalConsent.d.ts.map +1 -1
- package/dist/useProvisionalConsent.js +57 -67
- package/dist/useProvisionalConsent.js.map +1 -1
- package/dist/useSubmitConsent.d.ts +9 -39
- package/dist/useSubmitConsent.d.ts.map +1 -1
- package/dist/useSubmitConsent.js +10 -39
- package/dist/useSubmitConsent.js.map +1 -1
- package/package.json +38 -38
- package/src/ActionSheet.test.tsx +4 -4
- package/src/ActionSheet.tsx +18 -5
- package/src/AnnouncementNavigator.test.tsx +215 -315
- package/src/AnnouncementNavigator.tsx +25 -20
- package/src/Avatar.tsx +2 -9
- package/src/Box.test.tsx +3 -3
- package/src/Box.tsx +4 -2
- package/src/Common.ts +19 -15
- package/src/ConsentFormScreen.tsx +2 -1
- package/src/ConsentNavigator.test.tsx +166 -242
- package/src/ConsentNavigator.tsx +9 -13
- package/src/CustomSelectField.tsx +3 -3
- package/src/DataTable.test.tsx +69 -1
- package/src/DataTable.tsx +72 -19
- package/src/DateTimeField.tsx +4 -4
- package/src/DropdownPanel.tsx +0 -6
- package/src/FilterAccordion.tsx +3 -3
- package/src/FilterBoolean.tsx +3 -3
- package/src/FilterSelectMenu.tsx +1 -1
- package/src/GPTChat.tsx +10 -9
- package/src/Heading.tsx +7 -14
- package/src/HeightField.tsx +9 -2
- package/src/Hyperlink.tsx +6 -3
- package/src/Link.test.tsx +2 -2
- package/src/MarkdownEditorField.tsx +10 -2
- package/src/MarkdownView.test.tsx +10 -6
- package/src/Modal.test.tsx +3 -1
- package/src/ModalSheet.test.tsx +6 -6
- package/src/OfflineBanner.tsx +3 -2
- package/src/OtpField.tsx +2 -1
- package/src/PickerSelect.tsx +3 -2
- package/src/ProvisionalConsentSigner.test.tsx +140 -113
- package/src/ProvisionalConsentSigner.tsx +5 -4
- package/src/SidebarNavigation.native.tsx +2 -2
- package/src/SidebarNavigation.tsx +2 -2
- package/src/Skeleton.tsx +1 -1
- package/src/TapToEdit.test.tsx +2 -2
- package/src/Text.test.tsx +1 -1
- package/src/Text.tsx +25 -51
- package/src/TextField.tsx +2 -1
- package/src/ThumbsUpDownFeedback.tsx +3 -3
- package/src/ToastNotifications.tsx +3 -2
- package/src/ToastNotifications.webModal.test.tsx +4 -1
- package/src/Tooltip.tsx +2 -1
- package/src/UserInactivity.test.tsx +2 -3
- package/src/WebAddressAutocomplete.tsx +3 -3
- package/src/WebDropdownMenu.tsx +16 -5
- package/src/__snapshots__/DataTable.test.tsx.snap +13 -0
- package/src/announcementPlatform.ts +10 -0
- package/src/asks/AskCard.test.tsx +14 -12
- package/src/asks/AskCard.tsx +2 -2
- package/src/bunSetup.ts +42 -0
- package/src/dataTableColumnWidths.test.ts +266 -0
- package/src/dataTableColumnWidths.ts +272 -0
- package/src/index.tsx +9 -2
- package/src/login/LoginScreen.tsx +2 -2
- package/src/requestClient.test.ts +288 -0
- package/src/requestClient.ts +228 -0
- package/src/security/PasswordCard.tsx +7 -5
- package/src/security/TwoFactorSettingsCard.tsx +10 -3
- package/src/signUp/SignUpScreen.tsx +2 -2
- package/src/table/Table.tsx +1 -2
- package/src/table/TableTitle.tsx +2 -1
- package/src/test-utils.tsx +76 -0
- package/src/textFontSizes.ts +31 -0
- package/src/useAcknowledgeAnnouncement.test.ts +101 -193
- package/src/useAcknowledgeAnnouncement.ts +69 -147
- package/src/useAnnouncements.test.ts +122 -186
- package/src/useAnnouncements.ts +49 -105
- package/src/useConsentForms.test.ts +59 -112
- package/src/useConsentForms.ts +37 -87
- package/src/useProvisionalConsent.test.ts +74 -150
- package/src/useProvisionalConsent.ts +79 -125
- package/src/useSubmitConsent.test.ts +59 -85
- package/src/useSubmitConsent.ts +22 -77
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import type React from "react";
|
|
3
4
|
import {Pressable} from "react-native";
|
|
4
5
|
import {Box} from "./Box";
|
|
5
6
|
import {ConsentNavigator} from "./ConsentNavigator";
|
|
6
7
|
import {Text} from "./Text";
|
|
7
|
-
import {renderWithTheme} from "./test-utils";
|
|
8
|
+
import {createFakeRequestClient, fakeHttpError, renderWithTheme} from "./test-utils";
|
|
8
9
|
import type {ConsentFormPublic} from "./useConsentForms";
|
|
9
10
|
|
|
10
11
|
const makeForm = (overrides: Partial<ConsentFormPublic> = {}): ConsentFormPublic => ({
|
|
@@ -27,49 +28,38 @@ const makeForm = (overrides: Partial<ConsentFormPublic> = {}): ConsentFormPublic
|
|
|
27
28
|
...overrides,
|
|
28
29
|
});
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
/** Fake client serving `forms` from GET /consents/pending; submissions remove the form. */
|
|
32
|
+
const createConsentClient = (
|
|
33
|
+
initialForms: ConsentFormPublic[],
|
|
34
|
+
{
|
|
35
|
+
pending,
|
|
36
|
+
respond,
|
|
37
|
+
}: {
|
|
38
|
+
pending?: () => unknown;
|
|
39
|
+
respond?: (body: Record<string, unknown>) => unknown;
|
|
40
|
+
} = {}
|
|
41
|
+
): ReturnType<typeof createFakeRequestClient> & {forms: () => ConsentFormPublic[]} => {
|
|
42
|
+
let forms = [...initialForms];
|
|
43
|
+
const fake = createFakeRequestClient({
|
|
44
|
+
"GET /consents/pending": () => (pending ? pending() : {data: forms}),
|
|
45
|
+
"POST /consents/respond": (args) => {
|
|
46
|
+
const body = (args.body ?? {}) as Record<string, unknown>;
|
|
47
|
+
if (respond) {
|
|
48
|
+
return respond(body);
|
|
49
|
+
}
|
|
50
|
+
forms = forms.filter((form) => form.id !== body.consentFormId);
|
|
51
|
+
return {agreed: body.agreed, id: "response-1"};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return {...fake, forms: () => forms};
|
|
52
55
|
};
|
|
53
56
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
isLoading: true,
|
|
61
|
-
refetch: mock(() => Promise.resolve()),
|
|
62
|
-
})),
|
|
63
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
64
|
-
mock(() => ({unwrap: mock(() => Promise.resolve({}))})),
|
|
65
|
-
{error: undefined, isLoading: false},
|
|
66
|
-
]),
|
|
67
|
-
})),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
enhanceEndpoints: mock((_config: unknown) => innerApi),
|
|
72
|
-
};
|
|
57
|
+
const renderNavigator = async (
|
|
58
|
+
element: React.ReactElement
|
|
59
|
+
): Promise<ReturnType<typeof renderWithTheme>> => {
|
|
60
|
+
const result = renderWithTheme(element);
|
|
61
|
+
await waitFor(() => expect(result.queryByTestId("consent-navigator-loading")).toBeNull());
|
|
62
|
+
return result;
|
|
73
63
|
};
|
|
74
64
|
|
|
75
65
|
const ExtraScreen: React.FC<{onNext?: () => void}> = ({onNext}) => (
|
|
@@ -83,9 +73,9 @@ const ExtraScreen: React.FC<{onNext?: () => void}> = ({onNext}) => (
|
|
|
83
73
|
|
|
84
74
|
describe("ConsentNavigator", () => {
|
|
85
75
|
it("renders children when there are no pending consent forms", async () => {
|
|
86
|
-
const
|
|
87
|
-
const {getByText} =
|
|
88
|
-
<ConsentNavigator
|
|
76
|
+
const {client} = createConsentClient([]);
|
|
77
|
+
const {getByText} = await renderNavigator(
|
|
78
|
+
<ConsentNavigator client={client}>
|
|
89
79
|
<Text>App Content</Text>
|
|
90
80
|
</ConsentNavigator>
|
|
91
81
|
);
|
|
@@ -94,11 +84,10 @@ describe("ConsentNavigator", () => {
|
|
|
94
84
|
});
|
|
95
85
|
|
|
96
86
|
it("shows ConsentFormScreen when there are pending forms", async () => {
|
|
97
|
-
const
|
|
98
|
-
const api = createMockApi([form]);
|
|
87
|
+
const {client} = createConsentClient([makeForm()]);
|
|
99
88
|
|
|
100
|
-
const {getByTestId} =
|
|
101
|
-
<ConsentNavigator
|
|
89
|
+
const {getByTestId} = await renderNavigator(
|
|
90
|
+
<ConsentNavigator client={client}>
|
|
102
91
|
<Text>App Content</Text>
|
|
103
92
|
</ConsentNavigator>
|
|
104
93
|
);
|
|
@@ -107,11 +96,24 @@ describe("ConsentNavigator", () => {
|
|
|
107
96
|
expect(getByTestId("consent-form-agree-button")).toBeTruthy();
|
|
108
97
|
});
|
|
109
98
|
|
|
110
|
-
it("
|
|
111
|
-
const
|
|
99
|
+
it("requests pending consents under baseUrl", async () => {
|
|
100
|
+
const {client, calls} = createFakeRequestClient({
|
|
101
|
+
"GET /api/consents/pending": () => [],
|
|
102
|
+
});
|
|
103
|
+
const {getByText} = await renderNavigator(
|
|
104
|
+
<ConsentNavigator baseUrl="/api" client={client}>
|
|
105
|
+
<Text>App Content</Text>
|
|
106
|
+
</ConsentNavigator>
|
|
107
|
+
);
|
|
108
|
+
expect(getByText("App Content")).toBeTruthy();
|
|
109
|
+
expect(calls[0]?.url).toBe("/api/consents/pending");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("shows loading spinner while fetching consent forms", () => {
|
|
113
|
+
const {client} = createConsentClient([], {pending: () => new Promise(() => {})});
|
|
112
114
|
|
|
113
115
|
const {getByTestId} = renderWithTheme(
|
|
114
|
-
<ConsentNavigator
|
|
116
|
+
<ConsentNavigator client={client}>
|
|
115
117
|
<Text>App Content</Text>
|
|
116
118
|
</ConsentNavigator>
|
|
117
119
|
);
|
|
@@ -120,10 +122,10 @@ describe("ConsentNavigator", () => {
|
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
it("shows extra screens after consent forms are completed", async () => {
|
|
123
|
-
const
|
|
125
|
+
const {client} = createConsentClient([]);
|
|
124
126
|
|
|
125
|
-
const {getByTestId, queryByText} =
|
|
126
|
-
<ConsentNavigator
|
|
127
|
+
const {getByTestId, queryByText} = await renderNavigator(
|
|
128
|
+
<ConsentNavigator client={client} extraScreens={[<ExtraScreen key="extra" />]}>
|
|
127
129
|
<Text>App Content</Text>
|
|
128
130
|
</ConsentNavigator>
|
|
129
131
|
);
|
|
@@ -133,11 +135,10 @@ describe("ConsentNavigator", () => {
|
|
|
133
135
|
});
|
|
134
136
|
|
|
135
137
|
it("shows children after all extra screens are dismissed", async () => {
|
|
136
|
-
const
|
|
137
|
-
const {act, fireEvent, waitFor} = await import("@testing-library/react-native");
|
|
138
|
+
const {client} = createConsentClient([]);
|
|
138
139
|
|
|
139
|
-
const {getByTestId, getByText} =
|
|
140
|
-
<ConsentNavigator
|
|
140
|
+
const {getByTestId, getByText} = await renderNavigator(
|
|
141
|
+
<ConsentNavigator client={client} extraScreens={[<ExtraScreen key="extra" />]}>
|
|
141
142
|
<Text>App Content</Text>
|
|
142
143
|
</ConsentNavigator>
|
|
143
144
|
);
|
|
@@ -152,10 +153,10 @@ describe("ConsentNavigator", () => {
|
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
it("injects onNext prop into extra screen elements", async () => {
|
|
155
|
-
const
|
|
156
|
+
const {client} = createConsentClient([]);
|
|
156
157
|
|
|
157
|
-
const {getByTestId} =
|
|
158
|
-
<ConsentNavigator
|
|
158
|
+
const {getByTestId} = await renderNavigator(
|
|
159
|
+
<ConsentNavigator client={client} extraScreens={[<ExtraScreen key="extra" />]}>
|
|
159
160
|
<Text>App Content</Text>
|
|
160
161
|
</ConsentNavigator>
|
|
161
162
|
);
|
|
@@ -164,124 +165,96 @@ describe("ConsentNavigator", () => {
|
|
|
164
165
|
expect(getByTestId("extra-screen-next")).toBeTruthy();
|
|
165
166
|
});
|
|
166
167
|
|
|
167
|
-
it("renders children when error is auth (401)", () => {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
178
|
-
mock(() => ({unwrap: mock(() => Promise.resolve({}))})),
|
|
179
|
-
{error: undefined, isLoading: false},
|
|
180
|
-
]),
|
|
181
|
-
})),
|
|
182
|
-
})),
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const {getByText} = renderWithTheme(
|
|
186
|
-
<ConsentNavigator api={api}>
|
|
168
|
+
it("renders children when error is auth (401)", async () => {
|
|
169
|
+
const onError = mock(() => {});
|
|
170
|
+
const {client} = createConsentClient([], {
|
|
171
|
+
pending: () => {
|
|
172
|
+
throw fakeHttpError(401);
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const {getByText} = await renderNavigator(
|
|
177
|
+
<ConsentNavigator client={client} onError={onError}>
|
|
187
178
|
<Text>App Content</Text>
|
|
188
179
|
</ConsentNavigator>
|
|
189
180
|
);
|
|
190
|
-
expect(getByText("App Content")).toBeTruthy();
|
|
181
|
+
await waitFor(() => expect(getByText("App Content")).toBeTruthy());
|
|
182
|
+
expect(onError).not.toHaveBeenCalled();
|
|
191
183
|
});
|
|
192
184
|
|
|
193
|
-
it("renders children when error is auth (403)", () => {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})),
|
|
203
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
204
|
-
mock(() => ({unwrap: mock(() => Promise.resolve({}))})),
|
|
205
|
-
{error: undefined, isLoading: false},
|
|
206
|
-
]),
|
|
207
|
-
})),
|
|
208
|
-
})),
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const {getByText} = renderWithTheme(
|
|
212
|
-
<ConsentNavigator api={api}>
|
|
185
|
+
it("renders children when error is auth (403 originalStatus)", async () => {
|
|
186
|
+
const {client} = createConsentClient([], {
|
|
187
|
+
pending: () => {
|
|
188
|
+
throw Object.assign(new Error("Forbidden"), {originalStatus: 403});
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const {getByText} = await renderNavigator(
|
|
193
|
+
<ConsentNavigator client={client}>
|
|
213
194
|
<Text>App Content</Text>
|
|
214
195
|
</ConsentNavigator>
|
|
215
196
|
);
|
|
216
|
-
expect(getByText("App Content")).toBeTruthy();
|
|
197
|
+
await waitFor(() => expect(getByText("App Content")).toBeTruthy());
|
|
217
198
|
});
|
|
218
199
|
|
|
219
|
-
it("renders error screen with retry button for non-auth errors", () => {
|
|
200
|
+
it("renders error screen with retry button for non-auth errors", async () => {
|
|
220
201
|
const onError = mock(() => {});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
]),
|
|
234
|
-
})),
|
|
235
|
-
})),
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
const {getByTestId, getByText} = renderWithTheme(
|
|
239
|
-
<ConsentNavigator api={api} onError={onError}>
|
|
202
|
+
let shouldFail = true;
|
|
203
|
+
const {client, callsTo} = createConsentClient([], {
|
|
204
|
+
pending: () => {
|
|
205
|
+
if (shouldFail) {
|
|
206
|
+
throw fakeHttpError(500, "Server error");
|
|
207
|
+
}
|
|
208
|
+
return [];
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const {getByTestId, getByText} = await renderNavigator(
|
|
213
|
+
<ConsentNavigator client={client} onError={onError}>
|
|
240
214
|
<Text>App Content</Text>
|
|
241
215
|
</ConsentNavigator>
|
|
242
216
|
);
|
|
243
|
-
expect(getByTestId("consent-navigator-error")).toBeTruthy();
|
|
217
|
+
await waitFor(() => expect(getByTestId("consent-navigator-error")).toBeTruthy());
|
|
244
218
|
expect(getByText("Failed to load consent forms")).toBeTruthy();
|
|
245
219
|
expect(onError).toHaveBeenCalled();
|
|
220
|
+
|
|
221
|
+
shouldFail = false;
|
|
222
|
+
await act(async () => {
|
|
223
|
+
fireEvent.press(getByText("Retry"));
|
|
224
|
+
});
|
|
225
|
+
await waitFor(() => expect(getByText("App Content")).toBeTruthy());
|
|
226
|
+
expect(callsTo("GET /consents/pending")).toHaveLength(2);
|
|
246
227
|
});
|
|
247
228
|
|
|
248
|
-
it("
|
|
249
|
-
const
|
|
229
|
+
it("submits and shows the app once the last form is agreed to", async () => {
|
|
230
|
+
const {client, callsTo} = createConsentClient([makeForm()]);
|
|
250
231
|
|
|
251
|
-
const {getByText} =
|
|
252
|
-
<ConsentNavigator
|
|
232
|
+
const {getByTestId, getByText} = await renderNavigator(
|
|
233
|
+
<ConsentNavigator client={client}>
|
|
253
234
|
<Text>App Content</Text>
|
|
254
235
|
</ConsentNavigator>
|
|
255
236
|
);
|
|
256
237
|
|
|
257
|
-
|
|
238
|
+
await act(async () => {
|
|
239
|
+
fireEvent.press(getByTestId("consent-form-agree-button"));
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
await waitFor(() => expect(getByText("App Content")).toBeTruthy());
|
|
243
|
+
const [submission] = callsTo("POST /consents/respond");
|
|
244
|
+
expect(submission?.body).toMatchObject({agreed: true, consentFormId: "form-1"});
|
|
245
|
+
// One initial load plus one refetch: the post-submit invalidation and the explicit
|
|
246
|
+
// refetch share a request.
|
|
247
|
+
expect(callsTo("GET /consents/pending")).toHaveLength(2);
|
|
258
248
|
});
|
|
259
249
|
|
|
260
|
-
it("
|
|
261
|
-
const {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const refetch = mock(() => Promise.resolve());
|
|
266
|
-
const api = {
|
|
267
|
-
enhanceEndpoints: mock(() => ({
|
|
268
|
-
injectEndpoints: mock(() => ({
|
|
269
|
-
useGetPendingConsentsQuery: mock(() => ({
|
|
270
|
-
data: {data: [form]},
|
|
271
|
-
error: undefined,
|
|
272
|
-
isLoading: false,
|
|
273
|
-
refetch,
|
|
274
|
-
})),
|
|
275
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
276
|
-
submitMutation,
|
|
277
|
-
{error: undefined, isLoading: false},
|
|
278
|
-
]),
|
|
279
|
-
})),
|
|
280
|
-
})),
|
|
281
|
-
};
|
|
250
|
+
it("advances to the next pending form after agreeing", async () => {
|
|
251
|
+
const {client} = createConsentClient([
|
|
252
|
+
makeForm(),
|
|
253
|
+
makeForm({id: "form-2", slug: "privacy", title: "Privacy Policy"}),
|
|
254
|
+
]);
|
|
282
255
|
|
|
283
|
-
const {getByTestId} =
|
|
284
|
-
<ConsentNavigator
|
|
256
|
+
const {getByTestId, findByText} = await renderNavigator(
|
|
257
|
+
<ConsentNavigator client={client}>
|
|
285
258
|
<Text>App Content</Text>
|
|
286
259
|
</ConsentNavigator>
|
|
287
260
|
);
|
|
@@ -290,35 +263,20 @@ describe("ConsentNavigator", () => {
|
|
|
290
263
|
fireEvent.press(getByTestId("consent-form-agree-button"));
|
|
291
264
|
});
|
|
292
265
|
|
|
293
|
-
expect(
|
|
266
|
+
expect(await findByText("Privacy Policy")).toBeTruthy();
|
|
294
267
|
});
|
|
295
268
|
|
|
296
269
|
it("invokes onError when consent submission fails on agree", async () => {
|
|
297
|
-
const {act, fireEvent} = await import("@testing-library/react-native");
|
|
298
|
-
const form = makeForm();
|
|
299
270
|
const onError = mock(() => {});
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
useGetPendingConsentsQuery: mock(() => ({
|
|
307
|
-
data: {data: [form]},
|
|
308
|
-
error: undefined,
|
|
309
|
-
isLoading: false,
|
|
310
|
-
refetch,
|
|
311
|
-
})),
|
|
312
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
313
|
-
submitMutation,
|
|
314
|
-
{error: undefined, isLoading: false},
|
|
315
|
-
]),
|
|
316
|
-
})),
|
|
317
|
-
})),
|
|
318
|
-
};
|
|
271
|
+
const submitError = fakeHttpError(500, "submit failed");
|
|
272
|
+
const {client, callsTo} = createConsentClient([makeForm()], {
|
|
273
|
+
respond: () => {
|
|
274
|
+
throw submitError;
|
|
275
|
+
},
|
|
276
|
+
});
|
|
319
277
|
|
|
320
|
-
const {getByTestId} =
|
|
321
|
-
<ConsentNavigator
|
|
278
|
+
const {getByTestId} = await renderNavigator(
|
|
279
|
+
<ConsentNavigator client={client} onError={onError}>
|
|
322
280
|
<Text>App Content</Text>
|
|
323
281
|
</ConsentNavigator>
|
|
324
282
|
);
|
|
@@ -327,76 +285,45 @@ describe("ConsentNavigator", () => {
|
|
|
327
285
|
fireEvent.press(getByTestId("consent-form-agree-button"));
|
|
328
286
|
});
|
|
329
287
|
|
|
330
|
-
await
|
|
331
|
-
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
expect(onError).toHaveBeenCalled();
|
|
288
|
+
await waitFor(() => expect(onError).toHaveBeenCalledWith(submitError));
|
|
289
|
+
expect(callsTo("GET /consents/pending")).toHaveLength(1);
|
|
335
290
|
});
|
|
336
291
|
|
|
337
292
|
it("calls submit with agreed=false when user declines an optional consent form", async () => {
|
|
338
|
-
const {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const submitMutation = mock(() => ({unwrap}));
|
|
342
|
-
const refetch = mock(() => Promise.resolve());
|
|
343
|
-
const api = {
|
|
344
|
-
enhanceEndpoints: mock(() => ({
|
|
345
|
-
injectEndpoints: mock(() => ({
|
|
346
|
-
useGetPendingConsentsQuery: mock(() => ({
|
|
347
|
-
data: {data: [form]},
|
|
348
|
-
error: undefined,
|
|
349
|
-
isLoading: false,
|
|
350
|
-
refetch,
|
|
351
|
-
})),
|
|
352
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
353
|
-
submitMutation,
|
|
354
|
-
{error: undefined, isLoading: false},
|
|
355
|
-
]),
|
|
356
|
-
})),
|
|
357
|
-
})),
|
|
358
|
-
};
|
|
293
|
+
const {client, callsTo} = createConsentClient([
|
|
294
|
+
makeForm({allowDecline: true, required: false}),
|
|
295
|
+
]);
|
|
359
296
|
|
|
360
|
-
const {getByTestId} =
|
|
361
|
-
<ConsentNavigator
|
|
297
|
+
const {getByTestId, getByText} = await renderNavigator(
|
|
298
|
+
<ConsentNavigator client={client}>
|
|
362
299
|
<Text>App Content</Text>
|
|
363
300
|
</ConsentNavigator>
|
|
364
301
|
);
|
|
365
302
|
|
|
366
|
-
const declineBtn = getByTestId("consent-form-decline-button");
|
|
367
303
|
await act(async () => {
|
|
368
|
-
fireEvent.press(
|
|
304
|
+
fireEvent.press(getByTestId("consent-form-decline-button"));
|
|
305
|
+
});
|
|
306
|
+
await waitFor(() => expect(getByText("App Content")).toBeTruthy());
|
|
307
|
+
expect(callsTo("POST /consents/respond")[0]?.body).toMatchObject({
|
|
308
|
+
agreed: false,
|
|
309
|
+
consentFormId: "form-1",
|
|
369
310
|
});
|
|
370
|
-
expect(submitMutation).toHaveBeenCalled();
|
|
371
311
|
});
|
|
372
312
|
|
|
373
313
|
it("invokes onError when consent submission fails on decline", async () => {
|
|
374
|
-
const {act, fireEvent} = await import("@testing-library/react-native");
|
|
375
|
-
const form = makeForm({allowDecline: true, required: false});
|
|
376
314
|
const onError = mock(() => {});
|
|
377
|
-
const declineError =
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
error: undefined,
|
|
387
|
-
isLoading: false,
|
|
388
|
-
refetch,
|
|
389
|
-
})),
|
|
390
|
-
useSubmitConsentResponseMutation: mock(() => [
|
|
391
|
-
submitMutation,
|
|
392
|
-
{error: undefined, isLoading: false},
|
|
393
|
-
]),
|
|
394
|
-
})),
|
|
395
|
-
})),
|
|
396
|
-
};
|
|
315
|
+
const declineError = fakeHttpError(500, "decline failed");
|
|
316
|
+
const {client, callsTo} = createConsentClient(
|
|
317
|
+
[makeForm({allowDecline: true, required: false})],
|
|
318
|
+
{
|
|
319
|
+
respond: () => {
|
|
320
|
+
throw declineError;
|
|
321
|
+
},
|
|
322
|
+
}
|
|
323
|
+
);
|
|
397
324
|
|
|
398
|
-
const {getByTestId} =
|
|
399
|
-
<ConsentNavigator
|
|
325
|
+
const {getByTestId} = await renderNavigator(
|
|
326
|
+
<ConsentNavigator client={client} onError={onError}>
|
|
400
327
|
<Text>App Content</Text>
|
|
401
328
|
</ConsentNavigator>
|
|
402
329
|
);
|
|
@@ -404,19 +331,16 @@ describe("ConsentNavigator", () => {
|
|
|
404
331
|
await act(async () => {
|
|
405
332
|
fireEvent.press(getByTestId("consent-form-decline-button"));
|
|
406
333
|
});
|
|
407
|
-
await act(async () => {
|
|
408
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
409
|
-
});
|
|
410
334
|
|
|
411
|
-
expect(onError).toHaveBeenCalledWith(declineError);
|
|
412
|
-
expect(
|
|
335
|
+
await waitFor(() => expect(onError).toHaveBeenCalledWith(declineError));
|
|
336
|
+
expect(callsTo("GET /consents/pending")).toHaveLength(1);
|
|
413
337
|
});
|
|
414
338
|
|
|
415
339
|
it("renders non-element extra screens as-is without injecting onNext", async () => {
|
|
416
|
-
const
|
|
340
|
+
const {client} = createConsentClient([]);
|
|
417
341
|
|
|
418
|
-
const {queryByText, toJSON} =
|
|
419
|
-
<ConsentNavigator
|
|
342
|
+
const {queryByText, toJSON} = await renderNavigator(
|
|
343
|
+
<ConsentNavigator client={client} extraScreens={[null]}>
|
|
420
344
|
<Text>App Content</Text>
|
|
421
345
|
</ConsentNavigator>
|
|
422
346
|
);
|
package/src/ConsentNavigator.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import React, {useState} from "react";
|
|
|
3
3
|
import {Box} from "./Box";
|
|
4
4
|
import {Button} from "./Button";
|
|
5
5
|
import {ConsentFormScreen} from "./ConsentFormScreen";
|
|
6
|
+
import type {TerrenoRequestClient} from "./requestClient";
|
|
6
7
|
import {Spinner} from "./Spinner";
|
|
7
8
|
import {Text} from "./Text";
|
|
8
9
|
import {detectLocale, useConsentForms} from "./useConsentForms";
|
|
@@ -11,10 +12,11 @@ import {useSubmitConsent} from "./useSubmitConsent";
|
|
|
11
12
|
|
|
12
13
|
interface ConsentNavigatorProps {
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Request client for the consent routes, usually the app's `@terreno/syncdb/api` client
|
|
16
|
+
* (`createApiClient(...)`). Any object with a matching `request` method works.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
client: TerrenoRequestClient;
|
|
19
|
+
/** Path prefixed to the consent routes (for example `/api`); defaults to none. */
|
|
18
20
|
baseUrl?: string;
|
|
19
21
|
children: React.ReactNode;
|
|
20
22
|
extraScreens?: React.ReactNode[];
|
|
@@ -23,7 +25,7 @@ interface ConsentNavigatorProps {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export const ConsentNavigator: React.FC<ConsentNavigatorProps> = ({
|
|
26
|
-
|
|
28
|
+
client,
|
|
27
29
|
baseUrl,
|
|
28
30
|
children,
|
|
29
31
|
extraScreens,
|
|
@@ -32,14 +34,8 @@ export const ConsentNavigator: React.FC<ConsentNavigatorProps> = ({
|
|
|
32
34
|
}) => {
|
|
33
35
|
const [currentIndex, setCurrentIndex] = useState(0);
|
|
34
36
|
const [extraScreenIndex, setExtraScreenIndex] = useState(0);
|
|
35
|
-
const {forms, isLoading, error, refetch} = useConsentForms(
|
|
36
|
-
|
|
37
|
-
baseUrl
|
|
38
|
-
);
|
|
39
|
-
const {submit, isSubmitting} = useSubmitConsent(
|
|
40
|
-
api as Parameters<typeof useSubmitConsent>[0],
|
|
41
|
-
baseUrl
|
|
42
|
-
);
|
|
37
|
+
const {forms, isLoading, error, refetch} = useConsentForms(client, baseUrl);
|
|
38
|
+
const {submit, isSubmitting} = useSubmitConsent(client, baseUrl);
|
|
43
39
|
const locale = detectLocale();
|
|
44
40
|
const validExtraScreens = extraScreens ?? [];
|
|
45
41
|
|
|
@@ -122,7 +118,7 @@ export const ConsentNavigator: React.FC<ConsentNavigatorProps> = ({
|
|
|
122
118
|
try {
|
|
123
119
|
await submit(body);
|
|
124
120
|
// Always refetch and reset so we pick up the updated pending list.
|
|
125
|
-
// Advancing currentIndex is racy because
|
|
121
|
+
// Advancing currentIndex is racy because the submit invalidation shrinks
|
|
126
122
|
// the forms array in the background.
|
|
127
123
|
setCurrentIndex(0);
|
|
128
124
|
await refetch();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {type FC, useEffect, useMemo, useRef, useState} from "react";
|
|
2
|
-
import {type
|
|
2
|
+
import {type TextInputInstance, View} from "react-native";
|
|
3
3
|
|
|
4
4
|
import type {CustomSelectFieldProps} from "./Common";
|
|
5
5
|
import {FieldHelperText} from "./fieldElements/FieldHelperText";
|
|
@@ -22,7 +22,7 @@ export const CustomSelectField: FC<CustomSelectFieldProps> = ({
|
|
|
22
22
|
}) => {
|
|
23
23
|
const [currentValue, setCurrentValue] = useState(value);
|
|
24
24
|
const [showCustomInput, setShowCustomInput] = useState(false);
|
|
25
|
-
const textInputRef = useRef<
|
|
25
|
+
const textInputRef = useRef<TextInputInstance | null>(null);
|
|
26
26
|
const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
|
|
27
27
|
|
|
28
28
|
// Boolean that checks if currentValue is a value from the
|
|
@@ -109,7 +109,7 @@ export const CustomSelectField: FC<CustomSelectFieldProps> = ({
|
|
|
109
109
|
<TextField
|
|
110
110
|
disabled={disabled}
|
|
111
111
|
id="customOptions"
|
|
112
|
-
inputRef={(ref:
|
|
112
|
+
inputRef={(ref: TextInputInstance | null) => {
|
|
113
113
|
textInputRef.current = ref;
|
|
114
114
|
}}
|
|
115
115
|
onChange={onChange}
|