@terreno/ui 0.30.0 → 56.0.0-beta.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/dist/ActionSheet.d.ts +1 -1
- package/dist/Avatar.js +1 -4
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.js +45 -9
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +21 -0
- package/dist/Common.js.map +1 -1
- package/dist/ConflictSheet.d.ts +53 -0
- package/dist/ConflictSheet.js +132 -0
- package/dist/ConflictSheet.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -1
- package/dist/DecimalRangeActionSheet.d.ts +1 -1
- package/dist/EmojiSelector.d.ts +1 -1
- package/dist/ErrorPage.d.ts +1 -1
- package/dist/HeightActionSheet.d.ts +1 -1
- package/dist/Hyperlink.d.ts +2 -1
- package/dist/Hyperlink.js +2 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/ImageBackground.d.ts +1 -1
- package/dist/MobileAddressAutoComplete.d.ts +1 -1
- package/dist/NumberPickerActionSheet.d.ts +1 -1
- package/dist/Page.d.ts +3 -3
- package/dist/PickerSelect.d.ts +1 -1
- package/dist/SidebarNavigation.js +1 -1
- package/dist/SidebarNavigation.js.map +1 -1
- package/dist/SidebarNavigation.native.js +1 -1
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.js +1 -4
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +1 -1
- package/dist/SyncStatusBanner.d.ts +46 -0
- package/dist/SyncStatusBanner.js +29 -0
- package/dist/SyncStatusBanner.js.map +1 -0
- package/dist/Theme.d.ts +1 -1
- package/dist/Toast.d.ts +9 -1
- package/dist/Toast.js +20 -7
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.js +23 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/UnifiedAddressAutoComplete.d.ts +1 -1
- package/dist/Unifier.js +1 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/conflictFieldDiff.d.ts +14 -0
- package/dist/conflictFieldDiff.js +62 -0
- package/dist/conflictFieldDiff.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +1 -1
- package/dist/icons/OnlineIcon.d.ts +1 -1
- package/dist/icons/OutOfficeIcon.d.ts +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +30 -0
- package/dist/pdfHtmlTemplate.js +170 -0
- package/dist/pdfHtmlTemplate.js.map +1 -0
- package/dist/table/TableTitle.js +1 -3
- package/dist/table/TableTitle.js.map +1 -1
- package/dist/useAppLaunchOrForeground.d.ts +9 -0
- package/dist/useAppLaunchOrForeground.js +27 -0
- package/dist/useAppLaunchOrForeground.js.map +1 -0
- package/package.json +44 -37
- package/src/Box.test.tsx +39 -9
- package/src/Box.tsx +46 -7
- package/src/Common.ts +21 -3
- package/src/ConflictSheet.test.tsx +461 -0
- package/src/ConflictSheet.tsx +399 -0
- package/src/DataTable.test.tsx +15 -21
- package/src/Hyperlink.tsx +1 -1
- package/src/SidebarNavigation.native.tsx +1 -1
- package/src/SidebarNavigation.tsx +1 -1
- package/src/SyncStatusBanner.test.tsx +204 -0
- package/src/SyncStatusBanner.tsx +148 -0
- package/src/TapToEdit.test.tsx +8 -14
- package/src/TerrenoProvider.test.tsx +3 -4
- package/src/Toast.test.tsx +60 -0
- package/src/Toast.tsx +46 -1
- package/src/ToastNotifications.test.tsx +82 -0
- package/src/ToastNotifications.tsx +25 -1
- package/src/Tooltip.test.tsx +1 -0
- package/src/Unifier.ts +1 -1
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +0 -3
- package/src/__snapshots__/Body.test.tsx.snap +0 -16
- package/src/__snapshots__/Box.test.tsx.snap +4 -13
- package/src/__snapshots__/Page.test.tsx.snap +0 -84
- package/src/__snapshots__/SplitPage.test.tsx.snap +24 -120
- package/src/__snapshots__/TapToEdit.test.tsx.snap +5 -16
- package/src/__snapshots__/Toast.test.tsx.snap +4 -2
- package/src/bunSetup.ts +19 -0
- package/src/conflictFieldDiff.test.ts +26 -0
- package/src/conflictFieldDiff.ts +78 -0
- package/src/index.tsx +5 -2
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +0 -9
- package/src/pdfHtmlTemplate.ts +219 -0
- package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +0 -1
- package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +2 -16
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +1 -17
- package/src/signUp/__snapshots__/Swiper.test.tsx.snap +0 -1
- package/src/table/__snapshots__/Table.test.tsx.snap +22 -87
- package/src/table/__snapshots__/TableHeader.test.tsx.snap +10 -50
- package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +10 -84
- package/src/table/__snapshots__/TableRow.test.tsx.snap +12 -77
- package/src/useAppLaunchOrForeground.test.tsx +54 -0
- package/src/useAppLaunchOrForeground.ts +30 -0
- package/dist/ConsentHistory.d.ts +0 -9
- package/dist/ConsentHistory.js +0 -70
- package/dist/ConsentHistory.js.map +0 -1
- package/dist/generateConsentHistoryPdf.d.ts +0 -2
- package/dist/generateConsentHistoryPdf.js +0 -185
- package/dist/generateConsentHistoryPdf.js.map +0 -1
- package/dist/useConsentHistory.d.ts +0 -63
- package/dist/useConsentHistory.js +0 -40
- package/dist/useConsentHistory.js.map +0 -1
- package/src/ConsentHistory.test.tsx +0 -161
- package/src/ConsentHistory.tsx +0 -249
- package/src/generateConsentHistoryPdf.ts +0 -211
- package/src/useConsentHistory.test.ts +0 -106
- package/src/useConsentHistory.ts +0 -94
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {fireEvent} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {SyncStatusBanner} from "./SyncStatusBanner";
|
|
5
|
+
import {renderWithTheme} from "./test-utils";
|
|
6
|
+
|
|
7
|
+
describe("SyncStatusBanner", () => {
|
|
8
|
+
it("renders the offline indicator when offline", () => {
|
|
9
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
10
|
+
<SyncStatusBanner conflictCount={0} isOnline={false} isSyncing={false} queuedCount={0} />
|
|
11
|
+
);
|
|
12
|
+
expect(getByTestId("sync-offline-indicator")).toBeTruthy();
|
|
13
|
+
expect(queryByTestId("sync-syncing-indicator")).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("hides the offline indicator when online", () => {
|
|
17
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
18
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
19
|
+
);
|
|
20
|
+
expect(queryByTestId("sync-offline-indicator")).toBeNull();
|
|
21
|
+
expect(getByTestId("sync-status-banner").props.style).toMatchObject({minHeight: 20});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("renders the queued count when there are queued mutations", () => {
|
|
25
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
26
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={3} />
|
|
27
|
+
);
|
|
28
|
+
expect(getByTestId("sync-queued-count")).toBeTruthy();
|
|
29
|
+
|
|
30
|
+
const {queryByTestId: queryEmpty} = renderWithTheme(
|
|
31
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
32
|
+
);
|
|
33
|
+
expect(queryEmpty("sync-queued-count")).toBeNull();
|
|
34
|
+
expect(queryByTestId("sync-queued-count")).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("does not render a syncing indicator (initial sync is toast-only)", () => {
|
|
38
|
+
const {queryByTestId} = renderWithTheme(
|
|
39
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={true} queuedCount={0} />
|
|
40
|
+
);
|
|
41
|
+
expect(queryByTestId("sync-syncing-indicator")).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("renders a pressable conflict badge and calls onOpenConflicts when pressed", async () => {
|
|
45
|
+
const onOpenConflicts = mock(() => {});
|
|
46
|
+
const {getByTestId} = renderWithTheme(
|
|
47
|
+
<SyncStatusBanner
|
|
48
|
+
conflictCount={2}
|
|
49
|
+
isOnline={true}
|
|
50
|
+
isSyncing={false}
|
|
51
|
+
onOpenConflicts={onOpenConflicts}
|
|
52
|
+
queuedCount={0}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
// A Box with onClick renders a Pressable whose testID gets a `-clickable` suffix. The press
|
|
56
|
+
// handler awaits haptics before invoking onClick, so flush microtasks before asserting.
|
|
57
|
+
const badge = getByTestId("sync-conflict-badge-clickable");
|
|
58
|
+
expect(badge).toBeTruthy();
|
|
59
|
+
fireEvent.press(badge);
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
61
|
+
expect(onOpenConflicts).toHaveBeenCalledTimes(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("gives the conflict badge an explicit accessibilityRole of button (E6)", () => {
|
|
65
|
+
const {getByTestId} = renderWithTheme(
|
|
66
|
+
<SyncStatusBanner conflictCount={1} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
67
|
+
);
|
|
68
|
+
const badge = getByTestId("sync-conflict-badge-clickable");
|
|
69
|
+
expect(badge.props.accessibilityRole).toBe("button");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("hides the conflict badge when there are no conflicts", () => {
|
|
73
|
+
const {queryByTestId} = renderWithTheme(
|
|
74
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
75
|
+
);
|
|
76
|
+
expect(queryByTestId("sync-conflict-badge")).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("renders a pressable paused-for-auth indicator and calls onAuthRequired when pressed", async () => {
|
|
80
|
+
const onAuthRequired = mock(() => {});
|
|
81
|
+
const {getByTestId} = renderWithTheme(
|
|
82
|
+
<SyncStatusBanner
|
|
83
|
+
conflictCount={0}
|
|
84
|
+
isOnline={true}
|
|
85
|
+
isSyncing={false}
|
|
86
|
+
onAuthRequired={onAuthRequired}
|
|
87
|
+
paused="auth"
|
|
88
|
+
queuedCount={0}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
const badge = getByTestId("sync-paused-auth-indicator-clickable");
|
|
92
|
+
expect(badge).toBeTruthy();
|
|
93
|
+
fireEvent.press(badge);
|
|
94
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
95
|
+
expect(onAuthRequired).toHaveBeenCalledTimes(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("gives the paused-for-auth indicator an explicit accessibilityRole of button", () => {
|
|
99
|
+
const {getByTestId} = renderWithTheme(
|
|
100
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} paused="auth" queuedCount={0} />
|
|
101
|
+
);
|
|
102
|
+
expect(getByTestId("sync-paused-auth-indicator-clickable").props.accessibilityRole).toBe(
|
|
103
|
+
"button"
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("gives the failed badge an explicit accessibilityRole of button", () => {
|
|
108
|
+
const {getByTestId} = renderWithTheme(
|
|
109
|
+
<SyncStatusBanner conflictCount={0} failedCount={3} isOnline={true} queuedCount={0} />
|
|
110
|
+
);
|
|
111
|
+
expect(getByTestId("sync-failed-badge-clickable").props.accessibilityRole).toBe("button");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("renders without the deprecated isSyncing prop", () => {
|
|
115
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
116
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} queuedCount={2} />
|
|
117
|
+
);
|
|
118
|
+
expect(getByTestId("sync-queued-count")).toBeTruthy();
|
|
119
|
+
expect(queryByTestId("sync-syncing-indicator")).toBeNull();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("hides the paused-for-auth indicator when not paused", () => {
|
|
123
|
+
const {queryByTestId} = renderWithTheme(
|
|
124
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
125
|
+
);
|
|
126
|
+
expect(queryByTestId("sync-paused-auth-indicator")).toBeNull();
|
|
127
|
+
expect(queryByTestId("sync-paused-auth-indicator-clickable")).toBeNull();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("renders a pressable failed badge and calls onOpenFailed when pressed", async () => {
|
|
131
|
+
const onOpenFailed = mock(() => {});
|
|
132
|
+
const {getByTestId} = renderWithTheme(
|
|
133
|
+
<SyncStatusBanner
|
|
134
|
+
conflictCount={0}
|
|
135
|
+
failedCount={2}
|
|
136
|
+
isOnline={true}
|
|
137
|
+
isSyncing={false}
|
|
138
|
+
onOpenFailed={onOpenFailed}
|
|
139
|
+
queuedCount={0}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
const badge = getByTestId("sync-failed-badge-clickable");
|
|
143
|
+
expect(badge).toBeTruthy();
|
|
144
|
+
fireEvent.press(badge);
|
|
145
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
146
|
+
expect(onOpenFailed).toHaveBeenCalledTimes(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("hides the failed badge when there are no failed mutations", () => {
|
|
150
|
+
const {queryByTestId} = renderWithTheme(
|
|
151
|
+
<SyncStatusBanner conflictCount={0} isOnline={true} isSyncing={false} queuedCount={0} />
|
|
152
|
+
);
|
|
153
|
+
expect(queryByTestId("sync-failed-badge")).toBeNull();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("shows queued count when queued is at or below the progress threshold, even while draining", () => {
|
|
157
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
158
|
+
<SyncStatusBanner
|
|
159
|
+
conflictCount={0}
|
|
160
|
+
draining={true}
|
|
161
|
+
isOnline={true}
|
|
162
|
+
isSyncing={true}
|
|
163
|
+
queuedCount={5}
|
|
164
|
+
sentThisDrain={1}
|
|
165
|
+
totalThisDrain={5}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
expect(getByTestId("sync-queued-count")).toBeTruthy();
|
|
169
|
+
expect(queryByTestId("sync-drain-progress")).toBeNull();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("switches to numeric drain progress once queued exceeds the progress threshold while draining", () => {
|
|
173
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
174
|
+
<SyncStatusBanner
|
|
175
|
+
conflictCount={0}
|
|
176
|
+
draining={true}
|
|
177
|
+
isOnline={true}
|
|
178
|
+
isSyncing={true}
|
|
179
|
+
queuedCount={40}
|
|
180
|
+
sentThisDrain={12}
|
|
181
|
+
totalThisDrain={40}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
const progress = getByTestId("sync-drain-progress");
|
|
185
|
+
expect(progress).toBeTruthy();
|
|
186
|
+
expect(queryByTestId("sync-queued-count")).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("does not show drain progress when queued is large but not currently draining", () => {
|
|
190
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
191
|
+
<SyncStatusBanner
|
|
192
|
+
conflictCount={0}
|
|
193
|
+
draining={false}
|
|
194
|
+
isOnline={true}
|
|
195
|
+
isSyncing={false}
|
|
196
|
+
queuedCount={40}
|
|
197
|
+
sentThisDrain={0}
|
|
198
|
+
totalThisDrain={0}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
expect(getByTestId("sync-queued-count")).toBeTruthy();
|
|
202
|
+
expect(queryByTestId("sync-drain-progress")).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {useCallback} from "react";
|
|
3
|
+
|
|
4
|
+
import {Badge} from "./Badge";
|
|
5
|
+
import {Box} from "./Box";
|
|
6
|
+
|
|
7
|
+
/** Queued count above which the banner switches to a numeric drain-progress display. */
|
|
8
|
+
const PROGRESS_THRESHOLD = 20;
|
|
9
|
+
|
|
10
|
+
export interface SyncStatusBannerProps {
|
|
11
|
+
/** Whether the client currently has connectivity. */
|
|
12
|
+
isOnline: boolean;
|
|
13
|
+
/** Number of mutations waiting in the durable outbox. */
|
|
14
|
+
queuedCount: number;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Accepted and ignored. Initial bootstrap syncing is surfaced as a
|
|
17
|
+
* one-shot toast (see SyncHealthToast), not in this banner, and ongoing drain
|
|
18
|
+
* progress is driven by `draining`/`sentThisDrain`/`totalThisDrain`. Passing it
|
|
19
|
+
* has no effect; the prop stays only so existing call sites keep compiling.
|
|
20
|
+
*/
|
|
21
|
+
isSyncing?: boolean;
|
|
22
|
+
/** Number of unresolved conflicts. */
|
|
23
|
+
conflictCount: number;
|
|
24
|
+
/**
|
|
25
|
+
* Set when replay is paused pending re-authentication (B4/INV-2). Tapping
|
|
26
|
+
* the paused indicator invokes `onAuthRequired`.
|
|
27
|
+
*/
|
|
28
|
+
paused?: "auth";
|
|
29
|
+
/** Count of mutations in the terminal `failed` state (B5). */
|
|
30
|
+
failedCount?: number;
|
|
31
|
+
/** True while a batched drain is actively in flight (B5). */
|
|
32
|
+
draining?: boolean;
|
|
33
|
+
/** Mutations attempted so far in the current (or most recent) drain (B5). */
|
|
34
|
+
sentThisDrain?: number;
|
|
35
|
+
/** Queue length observed when the current (or most recent) drain began (B5). */
|
|
36
|
+
totalThisDrain?: number;
|
|
37
|
+
/** Opens the conflict resolution UI; wired to the pressable conflict badge. */
|
|
38
|
+
onOpenConflicts?: () => void;
|
|
39
|
+
/** Invoked when the paused-for-auth indicator is tapped, to prompt re-login. */
|
|
40
|
+
onAuthRequired?: () => void;
|
|
41
|
+
/** Opens a failed-mutations detail view; wired to the pressable failed badge. */
|
|
42
|
+
onOpenFailed?: () => void;
|
|
43
|
+
testID?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Compact, presentational sync-state banner for local-first (e.g. @terreno/syncdb) screens:
|
|
48
|
+
* offline indicator, queued mutation count (with drain progress once the queue grows past
|
|
49
|
+
* {@link PROGRESS_THRESHOLD}), a paused-for-auth indicator, a pressable failed count, and a
|
|
50
|
+
* pressable conflict badge. Initial bootstrap "Syncing…" is intentionally not shown here —
|
|
51
|
+
* apps should surface that as a one-shot toast on launch (see SyncHealthToast). It is
|
|
52
|
+
* intentionally data-driven (no data-layer imports) so it can be reused with any sync store —
|
|
53
|
+
* wire a status hook (such as `useSyncStatus`) to its props in the consuming app.
|
|
54
|
+
*/
|
|
55
|
+
export const SyncStatusBanner: React.FC<SyncStatusBannerProps> = ({
|
|
56
|
+
isOnline,
|
|
57
|
+
queuedCount,
|
|
58
|
+
isSyncing: _isSyncing,
|
|
59
|
+
conflictCount,
|
|
60
|
+
paused,
|
|
61
|
+
failedCount = 0,
|
|
62
|
+
draining = false,
|
|
63
|
+
sentThisDrain = 0,
|
|
64
|
+
totalThisDrain = 0,
|
|
65
|
+
onOpenConflicts,
|
|
66
|
+
onAuthRequired,
|
|
67
|
+
onOpenFailed,
|
|
68
|
+
testID = "sync-status-banner",
|
|
69
|
+
}) => {
|
|
70
|
+
const handleOpenConflicts = useCallback((): void => {
|
|
71
|
+
onOpenConflicts?.();
|
|
72
|
+
}, [onOpenConflicts]);
|
|
73
|
+
|
|
74
|
+
const handleAuthRequired = useCallback((): void => {
|
|
75
|
+
onAuthRequired?.();
|
|
76
|
+
}, [onAuthRequired]);
|
|
77
|
+
|
|
78
|
+
const handleOpenFailed = useCallback((): void => {
|
|
79
|
+
onOpenFailed?.();
|
|
80
|
+
}, [onOpenFailed]);
|
|
81
|
+
|
|
82
|
+
const showProgress = draining && queuedCount > PROGRESS_THRESHOLD && totalThisDrain > 0;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<Box direction="row" gap={2} marginBottom={4} minHeight={20} testID={testID} wrap>
|
|
86
|
+
{!isOnline && (
|
|
87
|
+
<Box alignItems="center" direction="row" gap={1} testID="sync-offline-indicator">
|
|
88
|
+
<Badge status="error" value="Offline" />
|
|
89
|
+
</Box>
|
|
90
|
+
)}
|
|
91
|
+
{paused === "auth" && (
|
|
92
|
+
<Box
|
|
93
|
+
accessibilityHint="Sign in again to resume syncing"
|
|
94
|
+
accessibilityLabel="Sync paused, sign in required"
|
|
95
|
+
accessibilityRole="button"
|
|
96
|
+
alignItems="center"
|
|
97
|
+
direction="row"
|
|
98
|
+
gap={1}
|
|
99
|
+
onClick={handleAuthRequired}
|
|
100
|
+
testID="sync-paused-auth-indicator"
|
|
101
|
+
>
|
|
102
|
+
<Badge status="warning" value="Sign in to sync" />
|
|
103
|
+
</Box>
|
|
104
|
+
)}
|
|
105
|
+
{queuedCount > 0 && !showProgress && (
|
|
106
|
+
<Box alignItems="center" direction="row" gap={1} testID="sync-queued-count">
|
|
107
|
+
<Badge status="warning" value={`${queuedCount} queued`} />
|
|
108
|
+
</Box>
|
|
109
|
+
)}
|
|
110
|
+
{showProgress && (
|
|
111
|
+
<Box alignItems="center" direction="row" gap={1} testID="sync-drain-progress">
|
|
112
|
+
<Badge status="warning" value={`Syncing ${sentThisDrain} / ${totalThisDrain}`} />
|
|
113
|
+
</Box>
|
|
114
|
+
)}
|
|
115
|
+
{failedCount > 0 && (
|
|
116
|
+
<Box
|
|
117
|
+
accessibilityHint="Opens the failed sync mutations detail view"
|
|
118
|
+
accessibilityLabel="View failed sync mutations"
|
|
119
|
+
accessibilityRole="button"
|
|
120
|
+
alignItems="center"
|
|
121
|
+
direction="row"
|
|
122
|
+
gap={1}
|
|
123
|
+
onClick={handleOpenFailed}
|
|
124
|
+
testID="sync-failed-badge"
|
|
125
|
+
>
|
|
126
|
+
<Badge status="error" value={`${failedCount} failed`} />
|
|
127
|
+
</Box>
|
|
128
|
+
)}
|
|
129
|
+
{conflictCount > 0 && (
|
|
130
|
+
<Box
|
|
131
|
+
accessibilityHint="Opens the sync conflict resolution sheet"
|
|
132
|
+
accessibilityLabel="View sync conflicts"
|
|
133
|
+
accessibilityRole="button"
|
|
134
|
+
alignItems="center"
|
|
135
|
+
direction="row"
|
|
136
|
+
gap={1}
|
|
137
|
+
onClick={handleOpenConflicts}
|
|
138
|
+
testID="sync-conflict-badge"
|
|
139
|
+
>
|
|
140
|
+
<Badge
|
|
141
|
+
status="error"
|
|
142
|
+
value={`${conflictCount} conflict${conflictCount === 1 ? "" : "s"}`}
|
|
143
|
+
/>
|
|
144
|
+
</Box>
|
|
145
|
+
)}
|
|
146
|
+
</Box>
|
|
147
|
+
);
|
|
148
|
+
};
|
package/src/TapToEdit.test.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
|
-
import {describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {describe, expect, it, mock, spyOn} from "bun:test";
|
|
4
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
5
3
|
import {Linking} from "react-native";
|
|
6
4
|
|
|
@@ -141,9 +139,7 @@ describe("TapToEdit", () => {
|
|
|
141
139
|
});
|
|
142
140
|
|
|
143
141
|
it("invokes Linking.openURL for url type when clicked", async () => {
|
|
144
|
-
const
|
|
145
|
-
const openMock = mock(() => Promise.resolve(true));
|
|
146
|
-
(Linking as any).openURL = openMock;
|
|
142
|
+
const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
|
|
147
143
|
|
|
148
144
|
const {getByLabelText} = renderWithTheme(
|
|
149
145
|
<TapToEdit editable={false} title="Site" type="url" value="https://example.com" />
|
|
@@ -152,15 +148,13 @@ describe("TapToEdit", () => {
|
|
|
152
148
|
await act(async () => {
|
|
153
149
|
fireEvent.press(getByLabelText("Link"));
|
|
154
150
|
});
|
|
155
|
-
expect(
|
|
151
|
+
expect(openURLSpy).toHaveBeenCalled();
|
|
156
152
|
|
|
157
|
-
(
|
|
153
|
+
openURLSpy.mockRestore();
|
|
158
154
|
});
|
|
159
155
|
|
|
160
156
|
it("invokes Linking.openURL with google maps for address type when clicked", async () => {
|
|
161
|
-
const
|
|
162
|
-
const openMock = mock(() => Promise.resolve(true));
|
|
163
|
-
(Linking as any).openURL = openMock;
|
|
157
|
+
const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
|
|
164
158
|
|
|
165
159
|
const {getByLabelText} = renderWithTheme(
|
|
166
160
|
<TapToEdit
|
|
@@ -174,11 +168,11 @@ describe("TapToEdit", () => {
|
|
|
174
168
|
await act(async () => {
|
|
175
169
|
fireEvent.press(getByLabelText("Link"));
|
|
176
170
|
});
|
|
177
|
-
expect(
|
|
178
|
-
const arg =
|
|
171
|
+
expect(openURLSpy).toHaveBeenCalled();
|
|
172
|
+
const arg = openURLSpy.mock.calls[0][0];
|
|
179
173
|
expect(arg).toContain("google.com/maps");
|
|
180
174
|
|
|
181
|
-
(
|
|
175
|
+
openURLSpy.mockRestore();
|
|
182
176
|
});
|
|
183
177
|
|
|
184
178
|
it("throws when editable is true and setValue is not provided", () => {
|
|
@@ -96,10 +96,9 @@ describe("TerrenoProvider", () => {
|
|
|
96
96
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
//
|
|
100
|
-
const buttons = UNSAFE_getAllByProps({
|
|
101
|
-
|
|
102
|
-
const dismissBtn = buttons.find((b) => !b.props.accessibilityLabel && b.props.onPress);
|
|
99
|
+
// The dismiss Pressable wrapping the xmark icon, found by the label it announces.
|
|
100
|
+
const buttons = UNSAFE_getAllByProps({accessibilityLabel: "Dismiss notification"});
|
|
101
|
+
const dismissBtn = buttons.find((b) => b.props.onPress);
|
|
103
102
|
expect(dismissBtn).toBeDefined();
|
|
104
103
|
|
|
105
104
|
await act(async () => {
|
package/src/Toast.test.tsx
CHANGED
|
@@ -88,6 +88,66 @@ describe("Toast", () => {
|
|
|
88
88
|
expect(toJSON()).toMatchSnapshot();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
it("renders action button when buttonText and buttonOnClick are provided", () => {
|
|
92
|
+
const handleClick = mock(() => {});
|
|
93
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
94
|
+
<Toast
|
|
95
|
+
buttonOnClick={handleClick}
|
|
96
|
+
buttonText="Resolve"
|
|
97
|
+
persistent
|
|
98
|
+
title="Sync needs attention"
|
|
99
|
+
variant="warning"
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
expect(getByText("Resolve")).toBeTruthy();
|
|
103
|
+
const button = getByTestId("toast-action-button");
|
|
104
|
+
expect(button).toBeTruthy();
|
|
105
|
+
button.props.onClick?.();
|
|
106
|
+
button.props.onPress?.();
|
|
107
|
+
expect(handleClick).toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("suffixes the action button testID with the toast id so stacked toasts do not collide", () => {
|
|
111
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
112
|
+
<>
|
|
113
|
+
<Toast
|
|
114
|
+
buttonOnClick={() => {}}
|
|
115
|
+
buttonText="Resolve"
|
|
116
|
+
id="sync-conflicts-todos"
|
|
117
|
+
persistent
|
|
118
|
+
title="Todos need attention"
|
|
119
|
+
variant="warning"
|
|
120
|
+
/>
|
|
121
|
+
<Toast
|
|
122
|
+
buttonOnClick={() => {}}
|
|
123
|
+
buttonText="Retry"
|
|
124
|
+
id="sync-failed-notes"
|
|
125
|
+
persistent
|
|
126
|
+
title="Notes need attention"
|
|
127
|
+
variant="warning"
|
|
128
|
+
/>
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
// getByTestId throws on multiple matches — the shared testID would fail here.
|
|
132
|
+
expect(getByTestId("toast-action-button-sync-conflicts-todos")).toBeTruthy();
|
|
133
|
+
expect(getByTestId("toast-action-button-sync-failed-notes")).toBeTruthy();
|
|
134
|
+
expect(queryByTestId("toast-action-button")).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("gives the action button an accessibilityRole of button", () => {
|
|
138
|
+
const {getByTestId} = renderWithTheme(
|
|
139
|
+
<Toast buttonOnClick={() => {}} buttonText="Resolve" persistent title="Sync" />
|
|
140
|
+
);
|
|
141
|
+
expect(getByTestId("toast-action-button").props.accessibilityRole).toBe("button");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("does not render action button when only buttonText is provided", () => {
|
|
145
|
+
const {queryByTestId} = renderWithTheme(
|
|
146
|
+
<Toast buttonText="Resolve" title="Sync needs attention" variant="warning" />
|
|
147
|
+
);
|
|
148
|
+
expect(queryByTestId("toast-action-button")).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
|
|
91
151
|
it("renders all variants with large size correctly", () => {
|
|
92
152
|
const variants = ["info", "success", "warning", "error"] as const;
|
|
93
153
|
variants.forEach((variant) => {
|
package/src/Toast.tsx
CHANGED
|
@@ -11,12 +11,26 @@ import {isAPIError, printAPIError} from "./Utilities";
|
|
|
11
11
|
|
|
12
12
|
const TOAST_DURATION_MS = 3 * 1000;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Base testID of the action button. Suffixed with the toast id when the caller
|
|
16
|
+
* supplied one, so stacked action toasts stay individually addressable.
|
|
17
|
+
*/
|
|
18
|
+
const ACTION_BUTTON_TEST_ID = "toast-action-button";
|
|
19
|
+
|
|
14
20
|
interface UseToastVariantOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Stable toast id. Showing the same id again replaces the toast on screen
|
|
23
|
+
* instead of stacking a duplicate — use it for a recurring notification that
|
|
24
|
+
* should only ever have one instance (e.g. one per data collection).
|
|
25
|
+
*/
|
|
26
|
+
id?: string;
|
|
15
27
|
persistent?: ToastProps["persistent"];
|
|
16
28
|
secondary?: ToastProps["secondary"];
|
|
17
29
|
size?: ToastProps["size"];
|
|
18
30
|
onDismiss?: ToastProps["onDismiss"];
|
|
19
31
|
subtitle?: ToastProps["subtitle"];
|
|
32
|
+
buttonText?: ToastProps["buttonText"];
|
|
33
|
+
buttonOnClick?: ToastProps["buttonOnClick"];
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
interface UseToastOptions extends UseToastVariantOptions {
|
|
@@ -46,6 +60,7 @@ export const useToast = (): {
|
|
|
46
60
|
return toast.show(title, {
|
|
47
61
|
data: toastData,
|
|
48
62
|
duration: options?.persistent ? 0 : TOAST_DURATION_MS,
|
|
63
|
+
...(options?.id ? {id: options.id} : {}),
|
|
49
64
|
});
|
|
50
65
|
};
|
|
51
66
|
return {
|
|
@@ -87,6 +102,7 @@ export const useToast = (): {
|
|
|
87
102
|
// TODO: Support dismissible version of Toast. Currently only persistent are dismissible.
|
|
88
103
|
export const Toast = ({
|
|
89
104
|
title,
|
|
105
|
+
id,
|
|
90
106
|
variant = "info",
|
|
91
107
|
secondary,
|
|
92
108
|
size = "sm",
|
|
@@ -94,6 +110,8 @@ export const Toast = ({
|
|
|
94
110
|
persistent,
|
|
95
111
|
// TODO enforce these should only show if size is "lg" with type discrinimation
|
|
96
112
|
subtitle,
|
|
113
|
+
buttonText,
|
|
114
|
+
buttonOnClick,
|
|
97
115
|
}: ToastProps): React.ReactElement => {
|
|
98
116
|
const {theme} = useTheme();
|
|
99
117
|
let color: SurfaceColor;
|
|
@@ -126,6 +144,8 @@ export const Toast = ({
|
|
|
126
144
|
iconName = "circle-info";
|
|
127
145
|
}
|
|
128
146
|
|
|
147
|
+
const hasActionButton = Boolean(buttonText && buttonOnClick);
|
|
148
|
+
|
|
129
149
|
return (
|
|
130
150
|
<View
|
|
131
151
|
style={{
|
|
@@ -217,9 +237,34 @@ export const Toast = ({
|
|
|
217
237
|
)}
|
|
218
238
|
</View>
|
|
219
239
|
</View>
|
|
240
|
+
{hasActionButton ? (
|
|
241
|
+
<Pressable
|
|
242
|
+
accessibilityHint={`Press to ${buttonText}`}
|
|
243
|
+
accessibilityLabel={buttonText}
|
|
244
|
+
accessibilityRole="button"
|
|
245
|
+
onPress={buttonOnClick}
|
|
246
|
+
style={{
|
|
247
|
+
alignItems: "center",
|
|
248
|
+
alignSelf: "center",
|
|
249
|
+
backgroundColor: theme.surface.base,
|
|
250
|
+
borderRadius: theme.radius.rounded,
|
|
251
|
+
display: "flex",
|
|
252
|
+
justifyContent: "center",
|
|
253
|
+
marginLeft: theme.spacing.xs,
|
|
254
|
+
paddingHorizontal: theme.spacing.sm,
|
|
255
|
+
paddingVertical: theme.spacing.xs,
|
|
256
|
+
}}
|
|
257
|
+
testID={id ? `${ACTION_BUTTON_TEST_ID}-${id}` : ACTION_BUTTON_TEST_ID}
|
|
258
|
+
>
|
|
259
|
+
<Text bold color="primary" size="sm">
|
|
260
|
+
{buttonText}
|
|
261
|
+
</Text>
|
|
262
|
+
</Pressable>
|
|
263
|
+
) : null}
|
|
220
264
|
{Boolean(persistent && onDismiss) && (
|
|
221
265
|
<Pressable
|
|
222
|
-
|
|
266
|
+
accessibilityLabel="Dismiss notification"
|
|
267
|
+
accessibilityRole="button"
|
|
223
268
|
onPress={onDismiss}
|
|
224
269
|
style={{
|
|
225
270
|
alignItems: "center",
|
|
@@ -670,6 +670,88 @@ describe("ToastNotifications", () => {
|
|
|
670
670
|
});
|
|
671
671
|
});
|
|
672
672
|
|
|
673
|
+
describe("Toast identity and deferred inserts", () => {
|
|
674
|
+
const renderHarness = (): {
|
|
675
|
+
queryAllByText: ReturnType<typeof render>["queryAllByText"];
|
|
676
|
+
getRef: () => ToastType | null;
|
|
677
|
+
} => {
|
|
678
|
+
let toastRef: ToastType | null = null;
|
|
679
|
+
const TestComponent = () => {
|
|
680
|
+
toastRef = useToastNotifications();
|
|
681
|
+
return <Text>Test</Text>;
|
|
682
|
+
};
|
|
683
|
+
const {queryAllByText} = render(
|
|
684
|
+
<ToastProvider swipeEnabled={false}>
|
|
685
|
+
<TestComponent />
|
|
686
|
+
</ToastProvider>
|
|
687
|
+
);
|
|
688
|
+
return {getRef: () => toastRef, queryAllByText};
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
/** Drain the mocked requestAnimationFrame (a setTimeout) and the re-renders it causes. */
|
|
692
|
+
const flushFrames = async (): Promise<void> => {
|
|
693
|
+
for (let i = 0; i < 5; i++) {
|
|
694
|
+
await act(async () => {
|
|
695
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
it("does not resurrect a toast hidden before its deferred insert ran", async () => {
|
|
701
|
+
const {getRef, queryAllByText} = renderHarness();
|
|
702
|
+
await waitFor(() => {
|
|
703
|
+
expect(getRef()?.show).toBeDefined();
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
// `show` defers the insert by a frame, so this hide lands while the toast
|
|
707
|
+
// exists nowhere in state — the insert must be dropped, not replayed.
|
|
708
|
+
await act(async () => {
|
|
709
|
+
getRef()?.show("stale sync warning", {id: "sync-stale"});
|
|
710
|
+
getRef()?.hide("sync-stale");
|
|
711
|
+
getRef()?.show("current sync warning", {id: "sync-current"});
|
|
712
|
+
});
|
|
713
|
+
await flushFrames();
|
|
714
|
+
|
|
715
|
+
expect(queryAllByText("stale sync warning")).toHaveLength(0);
|
|
716
|
+
expect(queryAllByText("current sync warning")).toHaveLength(1);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
it("replaces rather than stacks a toast reusing the same id", async () => {
|
|
720
|
+
const {getRef, queryAllByText} = renderHarness();
|
|
721
|
+
await waitFor(() => {
|
|
722
|
+
expect(getRef()?.show).toBeDefined();
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
await act(async () => {
|
|
726
|
+
getRef()?.show("Todos: 1 conflict", {id: "sync-health:todos"});
|
|
727
|
+
});
|
|
728
|
+
await flushFrames();
|
|
729
|
+
await act(async () => {
|
|
730
|
+
getRef()?.show("Todos: 2 conflicts", {id: "sync-health:todos"});
|
|
731
|
+
});
|
|
732
|
+
await flushFrames();
|
|
733
|
+
|
|
734
|
+
expect(queryAllByText("Todos: 1 conflict")).toHaveLength(0);
|
|
735
|
+
expect(queryAllByText("Todos: 2 conflicts")).toHaveLength(1);
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
it("keeps toasts with distinct ids side by side", async () => {
|
|
739
|
+
const {getRef, queryAllByText} = renderHarness();
|
|
740
|
+
await waitFor(() => {
|
|
741
|
+
expect(getRef()?.show).toBeDefined();
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
await act(async () => {
|
|
745
|
+
getRef()?.show("Todos: 1 conflict", {id: "sync-health:todos"});
|
|
746
|
+
getRef()?.show("Notes: 1 conflict", {id: "sync-health:notes"});
|
|
747
|
+
});
|
|
748
|
+
await flushFrames();
|
|
749
|
+
|
|
750
|
+
expect(queryAllByText("Todos: 1 conflict")).toHaveLength(1);
|
|
751
|
+
expect(queryAllByText("Notes: 1 conflict")).toHaveLength(1);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
|
|
673
755
|
describe("Toast placement rendering", () => {
|
|
674
756
|
it("should render toast with top placement", async () => {
|
|
675
757
|
let toastRef: ToastType | null = null;
|