@terreno/ui 0.31.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/LICENSE +203 -21
- 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 -39
- 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/Theme.js +0 -1
- package/dist/Theme.js.map +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 -3
- package/dist/index.js +5 -3
- 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 +45 -39
- package/src/ActionSheet.test.tsx +37 -80
- package/src/Box.test.tsx +39 -9
- package/src/Box.tsx +46 -7
- package/src/Common.ts +21 -50
- package/src/ConflictSheet.test.tsx +461 -0
- package/src/ConflictSheet.tsx +399 -0
- package/src/ConsentNavigator.test.tsx +8 -6
- package/src/DateTimeField.test.tsx +0 -36
- package/src/Hyperlink.tsx +1 -1
- package/src/PickerSelect.test.tsx +12 -23
- 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/TerrenoProvider.test.tsx +3 -4
- package/src/Theme.tsx +0 -1
- 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/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__/Card.test.tsx.snap +0 -1
- 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 +21 -6
- package/src/conflictFieldDiff.test.ts +26 -0
- package/src/conflictFieldDiff.ts +78 -0
- package/src/index.tsx +5 -3
- 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/EditableCard.d.ts +0 -3
- package/dist/EditableCard.js +0 -23
- package/dist/EditableCard.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 -224
- package/src/ConsentHistory.tsx +0 -249
- package/src/DraggableList.test.tsx +0 -377
- package/src/EditableCard.test.tsx +0 -69
- package/src/EditableCard.tsx +0 -73
- package/src/SidebarNavigation.test.tsx +0 -339
- package/src/__snapshots__/EditableCard.test.tsx.snap +0 -242
- package/src/generateConsentHistoryPdf.test.ts +0 -253
- package/src/generateConsentHistoryPdf.ts +0 -211
- package/src/useConsentHistory.test.ts +0 -106
- package/src/useConsentHistory.ts +0 -94
package/src/Box.tsx
CHANGED
|
@@ -60,6 +60,32 @@ const isValidWidthHeight = (value: number | string): boolean => {
|
|
|
60
60
|
return typeof value === "number" || !Number.isNaN(Number(value)) || isValidPercentage(value);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Box props that describe behavior rather than layout. Unknown props fall through
|
|
65
|
+
* to the style object, so these have to be named explicitly: a callback or ref
|
|
66
|
+
* object reaching a native view's style crashes on Fabric, which serializes style
|
|
67
|
+
* (a ref holding a host instance is a cyclical structure) and freezes it in dev,
|
|
68
|
+
* so React then throws detaching the frozen `ref.current` on unmount.
|
|
69
|
+
*/
|
|
70
|
+
const NON_STYLE_BOX_PROPS = new Set<string>([
|
|
71
|
+
"accessibilityHint",
|
|
72
|
+
"accessibilityLabel",
|
|
73
|
+
"accessibilityRole",
|
|
74
|
+
"avoidKeyboard",
|
|
75
|
+
"children",
|
|
76
|
+
"dangerouslySetInlineStyle",
|
|
77
|
+
"keyboardOffset",
|
|
78
|
+
"onClick",
|
|
79
|
+
"onHoverEnd",
|
|
80
|
+
"onHoverStart",
|
|
81
|
+
"onLayout",
|
|
82
|
+
"onScroll",
|
|
83
|
+
"scroll",
|
|
84
|
+
"scrollRef",
|
|
85
|
+
"testID",
|
|
86
|
+
"testIDs",
|
|
87
|
+
]);
|
|
88
|
+
|
|
63
89
|
export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
64
90
|
const {theme} = useTheme();
|
|
65
91
|
const resolvedTestID = props.testID;
|
|
@@ -261,7 +287,14 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
261
287
|
return {width: value};
|
|
262
288
|
}
|
|
263
289
|
},
|
|
264
|
-
|
|
290
|
+
// Defaults to alignItems: "flex-start" so wrapped lines size to their content instead of
|
|
291
|
+
// stretching, but never overrides an explicit alignItems (prop order would decide the winner).
|
|
292
|
+
wrap: (value, allProps) => ({
|
|
293
|
+
alignItems: allProps.alignItems
|
|
294
|
+
? ALIGN_ITEMS[allProps.alignItems as AlignItems]
|
|
295
|
+
: "flex-start",
|
|
296
|
+
flexWrap: value ? "wrap" : "nowrap",
|
|
297
|
+
}),
|
|
265
298
|
zIndex: (value) => ({zIndex: value ? value : undefined}),
|
|
266
299
|
};
|
|
267
300
|
|
|
@@ -277,16 +310,12 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
277
310
|
const value = props[prop];
|
|
278
311
|
if (BOX_STYLE_MAP[prop]) {
|
|
279
312
|
Object.assign(style, BOX_STYLE_MAP[prop](value, props));
|
|
280
|
-
} else if (prop
|
|
313
|
+
} else if (!NON_STYLE_BOX_PROPS.has(prop as string)) {
|
|
281
314
|
style[prop] = value;
|
|
282
315
|
// console.warn(`Box: unknown property ${prop}`);
|
|
283
316
|
}
|
|
284
317
|
}
|
|
285
318
|
|
|
286
|
-
if (props.wrap && props.alignItems && Platform.OS !== "web") {
|
|
287
|
-
console.warn("React Native doesn't support wrap and alignItems together.");
|
|
288
|
-
}
|
|
289
|
-
|
|
290
319
|
// Finally, dangerously set overrides.
|
|
291
320
|
if (props.dangerouslySetInlineStyle) {
|
|
292
321
|
style = {...style, ...props.dangerouslySetInlineStyle.__style};
|
|
@@ -306,11 +335,17 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
306
335
|
let box: React.ReactElement;
|
|
307
336
|
|
|
308
337
|
// Adding the accessibilityRole of button throws a warning in React Native since we nest buttons
|
|
309
|
-
// within Box and RN does not support nested buttons
|
|
338
|
+
// within Box and RN does not support nested buttons — so this stays on `aria-role` (which RN
|
|
339
|
+
// itself translates to accessibilityRole under the hood) by default; an explicit
|
|
340
|
+
// `accessibilityRole` prop is only forwarded literally when the caller opts in.
|
|
310
341
|
if (props.onClick) {
|
|
342
|
+
const explicitAccessibilityRole = (props as AccessibilityProps).accessibilityRole;
|
|
311
343
|
box = (
|
|
312
344
|
<Pressable
|
|
313
345
|
accessibilityHint={(props as AccessibilityProps).accessibilityHint}
|
|
346
|
+
{...(explicitAccessibilityRole
|
|
347
|
+
? {accessibilityRole: explicitAccessibilityRole as never}
|
|
348
|
+
: {})}
|
|
314
349
|
aria-label={(props as AccessibilityProps).accessibilityLabel}
|
|
315
350
|
aria-role="button"
|
|
316
351
|
onLayout={props.onLayout}
|
|
@@ -327,8 +362,12 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
327
362
|
</Pressable>
|
|
328
363
|
);
|
|
329
364
|
} else {
|
|
365
|
+
const accessibilityHint = (props as AccessibilityProps).accessibilityHint;
|
|
366
|
+
const accessibilityLabel = (props as AccessibilityProps).accessibilityLabel;
|
|
330
367
|
box = (
|
|
331
368
|
<View
|
|
369
|
+
{...(accessibilityHint ? {accessibilityHint} : {})}
|
|
370
|
+
{...(accessibilityLabel ? {accessibilityLabel} : {})}
|
|
332
371
|
onPointerEnter={onHoverIn}
|
|
333
372
|
onPointerLeave={onHoverOut}
|
|
334
373
|
style={propsToStyle()}
|
package/src/Common.ts
CHANGED
|
@@ -219,7 +219,6 @@ export interface TextThemeConfig {
|
|
|
219
219
|
export interface SurfaceThemeConfig {
|
|
220
220
|
base: keyof ThemePrimitiveColors;
|
|
221
221
|
primary: keyof ThemePrimitiveColors;
|
|
222
|
-
secondaryExtraLight: keyof ThemePrimitiveColors;
|
|
223
222
|
secondaryLight: keyof ThemePrimitiveColors;
|
|
224
223
|
secondaryDark: keyof ThemePrimitiveColors;
|
|
225
224
|
secondaryExtraDark: keyof ThemePrimitiveColors;
|
|
@@ -288,7 +287,6 @@ export interface TextTheme {
|
|
|
288
287
|
export interface SurfaceTheme {
|
|
289
288
|
base: string;
|
|
290
289
|
primary: string;
|
|
291
|
-
secondaryExtraLight: string;
|
|
292
290
|
secondaryLight: string;
|
|
293
291
|
secondaryDark: string;
|
|
294
292
|
secondaryExtraDark: string;
|
|
@@ -518,6 +516,13 @@ export interface LayerProps {
|
|
|
518
516
|
export interface AccessibilityProps {
|
|
519
517
|
accessibilityLabel: string;
|
|
520
518
|
accessibilityHint: string;
|
|
519
|
+
/**
|
|
520
|
+
* RN/RNW accessibility role (e.g. "button") for a clickable Box. Optional —
|
|
521
|
+
* most onClick Boxes get an implicit button role already (see Box.tsx); set
|
|
522
|
+
* this explicitly when a screen-reader-facing role needs to be guaranteed
|
|
523
|
+
* (e.g. a badge that opens a sheet).
|
|
524
|
+
*/
|
|
525
|
+
accessibilityRole?: string;
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
export interface BoxPropsBase extends WithTestID {
|
|
@@ -687,51 +692,6 @@ export type CardProps = BoxProps & {
|
|
|
687
692
|
imageHeight?: number;
|
|
688
693
|
};
|
|
689
694
|
|
|
690
|
-
export type EditableCardProps = BoxProps & {
|
|
691
|
-
/**
|
|
692
|
-
* The name of an icon shown before the title.
|
|
693
|
-
*/
|
|
694
|
-
iconName?: IconName;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* The title of the summarized information.
|
|
698
|
-
*/
|
|
699
|
-
title?: string;
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Props for a badge rendered next to the title.
|
|
703
|
-
*/
|
|
704
|
-
badge?: BadgeProps;
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* The summarized information itself, displayed below the title.
|
|
708
|
-
*/
|
|
709
|
-
description?: string;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Secondary text displayed below the description, in a muted style.
|
|
713
|
-
*/
|
|
714
|
-
helperText?: string;
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* Callback invoked when the edit button is pressed. The edit button is only rendered when this
|
|
718
|
-
* is provided.
|
|
719
|
-
*/
|
|
720
|
-
onEdit?: () => void | Promise<void>;
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* Accessibility label for the edit button.
|
|
724
|
-
* @default "Edit"
|
|
725
|
-
*/
|
|
726
|
-
editAccessibilityLabel?: string;
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* If true, the card is highlighted to draw attention to it, e.g. for content that needs review.
|
|
730
|
-
* @default false
|
|
731
|
-
*/
|
|
732
|
-
attention?: boolean;
|
|
733
|
-
};
|
|
734
|
-
|
|
735
695
|
export interface ErrorBoundaryProps {
|
|
736
696
|
onError?: (error: Error, stack: string) => void;
|
|
737
697
|
children?: ReactNode;
|
|
@@ -2600,6 +2560,12 @@ export interface TextFieldPickerActionSheetProps {
|
|
|
2600
2560
|
|
|
2601
2561
|
export interface ToastProps {
|
|
2602
2562
|
title: string;
|
|
2563
|
+
/**
|
|
2564
|
+
* Stable toast id, forwarded by `useToast` from the caller's options. Used to
|
|
2565
|
+
* disambiguate the action button's testID so two stacked action toasts do not
|
|
2566
|
+
* both answer to `toast-action-button`.
|
|
2567
|
+
*/
|
|
2568
|
+
id?: string;
|
|
2603
2569
|
variant?: "error" | "info" | "success" | "warning";
|
|
2604
2570
|
secondary?: boolean;
|
|
2605
2571
|
size?: "sm" | "lg";
|
|
@@ -2607,9 +2573,14 @@ export interface ToastProps {
|
|
|
2607
2573
|
persistent?: boolean;
|
|
2608
2574
|
// TODO enforce these should only show if size is "lg" with type discrinimation
|
|
2609
2575
|
subtitle?: string;
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2576
|
+
/**
|
|
2577
|
+
* Optional action button label. Renders only when `buttonOnClick` is also provided.
|
|
2578
|
+
*/
|
|
2579
|
+
buttonText?: string;
|
|
2580
|
+
/**
|
|
2581
|
+
* Optional action button handler. Renders only when `buttonText` is also provided.
|
|
2582
|
+
*/
|
|
2583
|
+
buttonOnClick?: () => void | Promise<void>;
|
|
2613
2584
|
}
|
|
2614
2585
|
|
|
2615
2586
|
export interface TooltipProps {
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {fireEvent, within} from "@testing-library/react-native";
|
|
3
|
+
import {DateTime} from "luxon";
|
|
4
|
+
|
|
5
|
+
import {ConflictSheet, type SyncConflictItem} from "./ConflictSheet";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Timestamps render in the runner's own locale and zone, and the exact
|
|
10
|
+
* separators shift between ICU versions — so derive the expectation the same way
|
|
11
|
+
* the sheet does instead of pinning a literal string.
|
|
12
|
+
*/
|
|
13
|
+
const expectedTime = (iso: string): string =>
|
|
14
|
+
DateTime.fromISO(iso).toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS);
|
|
15
|
+
|
|
16
|
+
const buildConflict = (overrides?: Partial<SyncConflictItem>): SyncConflictItem => ({
|
|
17
|
+
collection: "todos",
|
|
18
|
+
entityId: "todo-1",
|
|
19
|
+
localData: JSON.stringify({title: "My local title", updated: "2026-01-02T15:04:00.000Z"}),
|
|
20
|
+
mutationId: "m-1",
|
|
21
|
+
serverData: JSON.stringify({title: "Server title", updated: "2026-01-02T16:05:00.000Z"}),
|
|
22
|
+
...overrides,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const flush = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0));
|
|
26
|
+
const flushDebounce = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 550));
|
|
27
|
+
|
|
28
|
+
describe("ConflictSheet", () => {
|
|
29
|
+
it("renders each conflict with local and server summaries", () => {
|
|
30
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
31
|
+
<ConflictSheet
|
|
32
|
+
conflicts={[buildConflict()]}
|
|
33
|
+
onDismiss={() => {}}
|
|
34
|
+
onResolve={() => {}}
|
|
35
|
+
visible={true}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
expect(getByTestId("conflict-item-todo-1")).toBeTruthy();
|
|
39
|
+
expect(getByText("My local title")).toBeTruthy();
|
|
40
|
+
expect(getByText("Server title")).toBeTruthy();
|
|
41
|
+
// Asserted per row so a swap of the local and server columns fails here.
|
|
42
|
+
expect(getByTestId("conflict-local-time-todo-1").props.children).toBe(
|
|
43
|
+
expectedTime("2026-01-02T15:04:00.000Z")
|
|
44
|
+
);
|
|
45
|
+
expect(getByTestId("conflict-server-time-todo-1").props.children).toBe(
|
|
46
|
+
expectedTime("2026-01-02T16:05:00.000Z")
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("always renders a time row when conflict payloads have no usable timestamp", () => {
|
|
51
|
+
const {getAllByText} = renderWithTheme(
|
|
52
|
+
<ConflictSheet
|
|
53
|
+
conflicts={[
|
|
54
|
+
buildConflict({
|
|
55
|
+
localData: JSON.stringify({title: "Local without time"}),
|
|
56
|
+
serverData: JSON.stringify({title: "Server without time"}),
|
|
57
|
+
}),
|
|
58
|
+
]}
|
|
59
|
+
onDismiss={() => {}}
|
|
60
|
+
onResolve={() => {}}
|
|
61
|
+
visible={true}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
expect(getAllByText("Time unavailable")).toHaveLength(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("badges the server side when it has the later timestamp", () => {
|
|
68
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
69
|
+
<ConflictSheet
|
|
70
|
+
conflicts={[buildConflict()]}
|
|
71
|
+
onDismiss={() => {}}
|
|
72
|
+
onResolve={() => {}}
|
|
73
|
+
visible={true}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
expect(getByTestId("conflict-server-recency-todo-1")).toBeTruthy();
|
|
77
|
+
expect(queryByTestId("conflict-local-recency-todo-1")).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("badges the local side when it has the later timestamp", () => {
|
|
81
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
82
|
+
<ConflictSheet
|
|
83
|
+
conflicts={[
|
|
84
|
+
buildConflict({
|
|
85
|
+
localData: JSON.stringify({title: "Local", updated: "2026-01-02T18:00:00.000Z"}),
|
|
86
|
+
serverData: JSON.stringify({title: "Server", updated: "2026-01-02T16:05:00.000Z"}),
|
|
87
|
+
}),
|
|
88
|
+
]}
|
|
89
|
+
onDismiss={() => {}}
|
|
90
|
+
onResolve={() => {}}
|
|
91
|
+
visible={true}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
expect(getByTestId("conflict-local-recency-todo-1")).toBeTruthy();
|
|
95
|
+
expect(queryByTestId("conflict-server-recency-todo-1")).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("badges both sides as the same time when the timestamps match", () => {
|
|
99
|
+
const {getAllByText, getByTestId} = renderWithTheme(
|
|
100
|
+
<ConflictSheet
|
|
101
|
+
conflicts={[
|
|
102
|
+
buildConflict({
|
|
103
|
+
localData: JSON.stringify({title: "Local", updated: "2026-01-02T16:05:00.000Z"}),
|
|
104
|
+
serverData: JSON.stringify({title: "Server", updated: "2026-01-02T16:05:00.000Z"}),
|
|
105
|
+
}),
|
|
106
|
+
]}
|
|
107
|
+
onDismiss={() => {}}
|
|
108
|
+
onResolve={() => {}}
|
|
109
|
+
visible={true}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
expect(getByTestId("conflict-local-recency-todo-1")).toBeTruthy();
|
|
113
|
+
expect(getByTestId("conflict-server-recency-todo-1")).toBeTruthy();
|
|
114
|
+
expect(getAllByText("Same time")).toHaveLength(2);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("badges neither side when a timestamp is missing or unparseable", () => {
|
|
118
|
+
const {queryByTestId} = renderWithTheme(
|
|
119
|
+
<ConflictSheet
|
|
120
|
+
conflicts={[
|
|
121
|
+
buildConflict({
|
|
122
|
+
localData: JSON.stringify({title: "Local", updated: "not a date"}),
|
|
123
|
+
serverData: JSON.stringify({title: "Server"}),
|
|
124
|
+
}),
|
|
125
|
+
]}
|
|
126
|
+
onDismiss={() => {}}
|
|
127
|
+
onResolve={() => {}}
|
|
128
|
+
visible={true}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
expect(queryByTestId("conflict-local-recency-todo-1")).toBeNull();
|
|
132
|
+
expect(queryByTestId("conflict-server-recency-todo-1")).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("renders a caller-supplied title and description", () => {
|
|
136
|
+
const {getByText} = renderWithTheme(
|
|
137
|
+
<ConflictSheet
|
|
138
|
+
conflicts={[buildConflict()]}
|
|
139
|
+
description="Pick one for your todos."
|
|
140
|
+
onDismiss={() => {}}
|
|
141
|
+
onResolve={() => {}}
|
|
142
|
+
title="Todos don't match"
|
|
143
|
+
visible={true}
|
|
144
|
+
/>
|
|
145
|
+
);
|
|
146
|
+
expect(getByText("Todos don't match")).toBeTruthy();
|
|
147
|
+
expect(getByText("Pick one for your todos.")).toBeTruthy();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("hides the description when an empty string is passed", () => {
|
|
151
|
+
const {queryByTestId} = renderWithTheme(
|
|
152
|
+
<ConflictSheet
|
|
153
|
+
conflicts={[buildConflict()]}
|
|
154
|
+
description=""
|
|
155
|
+
onDismiss={() => {}}
|
|
156
|
+
onResolve={() => {}}
|
|
157
|
+
visible={true}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
expect(queryByTestId("conflict-sheet-description")).toBeNull();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("shows an empty state when there are no conflicts", () => {
|
|
164
|
+
const {getByText} = renderWithTheme(
|
|
165
|
+
<ConflictSheet conflicts={[]} onDismiss={() => {}} onResolve={() => {}} visible={true} />
|
|
166
|
+
);
|
|
167
|
+
expect(getByText("Nothing left to choose — you're all set.")).toBeTruthy();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("keeps overflowing conflict content inside a bounded scroll view", () => {
|
|
171
|
+
const {getByTestId} = renderWithTheme(
|
|
172
|
+
<ConflictSheet
|
|
173
|
+
conflicts={[
|
|
174
|
+
buildConflict(),
|
|
175
|
+
buildConflict({entityId: "todo-2", mutationId: "m-2"}),
|
|
176
|
+
buildConflict({entityId: "todo-3", mutationId: "m-3"}),
|
|
177
|
+
]}
|
|
178
|
+
onDismiss={() => {}}
|
|
179
|
+
onResolve={() => {}}
|
|
180
|
+
visible={true}
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const scrollView = getByTestId("conflict-sheet-scroll");
|
|
185
|
+
expect(scrollView.props.style.maxHeight).toBeGreaterThan(0);
|
|
186
|
+
expect(getByTestId("conflict-item-todo-3")).toBeTruthy();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("explains the situation in plain language and labels each side clearly", () => {
|
|
190
|
+
const {getByTestId, getByText, queryByText} = renderWithTheme(
|
|
191
|
+
<ConflictSheet
|
|
192
|
+
conflicts={[buildConflict()]}
|
|
193
|
+
onDismiss={() => {}}
|
|
194
|
+
onResolve={() => {}}
|
|
195
|
+
visible={true}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
expect(getByTestId("conflict-sheet-description")).toBeTruthy();
|
|
199
|
+
expect(getByText("Your change")).toBeTruthy();
|
|
200
|
+
expect(getByText("Other version")).toBeTruthy();
|
|
201
|
+
expect(queryByText("What you edited on this device")).toBeNull();
|
|
202
|
+
expect(
|
|
203
|
+
queryByText("What's saved elsewhere — another device, another person, or an older copy")
|
|
204
|
+
).toBeNull();
|
|
205
|
+
expect(getByText("Keep my change")).toBeTruthy();
|
|
206
|
+
expect(getByText("Use the other version")).toBeTruthy();
|
|
207
|
+
expect(getByText("Keep all of my changes")).toBeTruthy();
|
|
208
|
+
expect(getByText("Use all other versions")).toBeTruthy();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("renders only changed fields in both version columns", async () => {
|
|
212
|
+
const {getAllByText, getByTestId, getByText, queryByText} = renderWithTheme(
|
|
213
|
+
<ConflictSheet
|
|
214
|
+
conflicts={[
|
|
215
|
+
buildConflict({
|
|
216
|
+
localData: JSON.stringify({
|
|
217
|
+
completed: true,
|
|
218
|
+
title: "My local title",
|
|
219
|
+
unchanged: "same",
|
|
220
|
+
updated: "2026-01-02T15:04:00.000Z",
|
|
221
|
+
}),
|
|
222
|
+
serverData: JSON.stringify({
|
|
223
|
+
completed: false,
|
|
224
|
+
title: "Server title",
|
|
225
|
+
unchanged: "same",
|
|
226
|
+
updated: "2026-01-02T16:05:00.000Z",
|
|
227
|
+
}),
|
|
228
|
+
}),
|
|
229
|
+
]}
|
|
230
|
+
onDismiss={() => {}}
|
|
231
|
+
onResolve={() => {}}
|
|
232
|
+
visible={true}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
fireEvent.press(getByTestId("conflict-diff-toggle-todo-1"));
|
|
237
|
+
await flushDebounce();
|
|
238
|
+
expect(getAllByText("Title")).toHaveLength(2);
|
|
239
|
+
expect(getAllByText("Completed")).toHaveLength(2);
|
|
240
|
+
expect(getByText("My local title")).toBeTruthy();
|
|
241
|
+
expect(getByText("Server title")).toBeTruthy();
|
|
242
|
+
expect(getByText("true")).toBeTruthy();
|
|
243
|
+
expect(getByText("false")).toBeTruthy();
|
|
244
|
+
expect(queryByText("Unchanged")).toBeNull();
|
|
245
|
+
expect(queryByText("same")).toBeNull();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("opens field diff rows when Diff is pressed", async () => {
|
|
249
|
+
const {getAllByText, getByTestId, getByText, queryByTestId} = renderWithTheme(
|
|
250
|
+
<ConflictSheet
|
|
251
|
+
conflicts={[
|
|
252
|
+
buildConflict({
|
|
253
|
+
localData: JSON.stringify({completed: true, title: "My local title"}),
|
|
254
|
+
serverData: JSON.stringify({completed: false, title: "Server title"}),
|
|
255
|
+
}),
|
|
256
|
+
]}
|
|
257
|
+
onDismiss={() => {}}
|
|
258
|
+
onResolve={() => {}}
|
|
259
|
+
visible={true}
|
|
260
|
+
/>
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
expect(getByText("Diff")).toBeTruthy();
|
|
264
|
+
expect(queryByTestId("conflict-local-field-completed-todo-1")).toBeNull();
|
|
265
|
+
fireEvent.press(getByTestId("conflict-diff-toggle-todo-1"));
|
|
266
|
+
await flushDebounce();
|
|
267
|
+
expect(getByText("Hide diff")).toBeTruthy();
|
|
268
|
+
expect(getByTestId("conflict-local-field-completed-todo-1")).toBeTruthy();
|
|
269
|
+
expect(getAllByText("Completed")).toHaveLength(2);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("keeps each resolution button inside the version column it applies to", () => {
|
|
273
|
+
const {getByTestId} = renderWithTheme(
|
|
274
|
+
<ConflictSheet
|
|
275
|
+
conflicts={[buildConflict()]}
|
|
276
|
+
onDismiss={() => {}}
|
|
277
|
+
onResolve={() => {}}
|
|
278
|
+
visible={true}
|
|
279
|
+
/>
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const localColumn = getByTestId("conflict-local-column-todo-1");
|
|
283
|
+
const serverColumn = getByTestId("conflict-server-column-todo-1");
|
|
284
|
+
expect(within(localColumn).getByTestId("conflict-keep-mine-button-m-1")).toBeTruthy();
|
|
285
|
+
expect(within(serverColumn).getByTestId("conflict-use-server-button-m-1")).toBeTruthy();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("calls onResolve with keepMine but keeps the sheet open until the conflict clears", async () => {
|
|
289
|
+
const onResolve = mock(() => {});
|
|
290
|
+
const onDismiss = mock(() => {});
|
|
291
|
+
const {getByTestId, rerender} = renderWithTheme(
|
|
292
|
+
<ConflictSheet
|
|
293
|
+
conflicts={[buildConflict()]}
|
|
294
|
+
onDismiss={onDismiss}
|
|
295
|
+
onResolve={onResolve}
|
|
296
|
+
visible={true}
|
|
297
|
+
/>
|
|
298
|
+
);
|
|
299
|
+
fireEvent.press(getByTestId("conflict-keep-mine-button-m-1"));
|
|
300
|
+
await flush();
|
|
301
|
+
expect(onResolve).toHaveBeenCalledTimes(1);
|
|
302
|
+
expect(onResolve.mock.calls[0][0]).toEqual({mutationId: "m-1", strategy: "keepMine"});
|
|
303
|
+
// Resolution has not landed yet (async in the data layer) — a failed resolve must
|
|
304
|
+
// leave the conflict on screen rather than closing over it.
|
|
305
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
306
|
+
|
|
307
|
+
rerender(
|
|
308
|
+
<ConflictSheet conflicts={[]} onDismiss={onDismiss} onResolve={onResolve} visible={true} />
|
|
309
|
+
);
|
|
310
|
+
await flush();
|
|
311
|
+
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("keeps the sheet open when a resolution never lands", async () => {
|
|
315
|
+
const onDismiss = mock(() => {});
|
|
316
|
+
const {getByTestId} = renderWithTheme(
|
|
317
|
+
<ConflictSheet
|
|
318
|
+
conflicts={[buildConflict()]}
|
|
319
|
+
onDismiss={onDismiss}
|
|
320
|
+
onResolve={() => {}}
|
|
321
|
+
visible={true}
|
|
322
|
+
/>
|
|
323
|
+
);
|
|
324
|
+
fireEvent.press(getByTestId("conflict-use-server-button-m-1"));
|
|
325
|
+
await flush();
|
|
326
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
327
|
+
expect(getByTestId("conflict-item-todo-1")).toBeTruthy();
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("does not dismiss a sheet opened with no conflicts at all", async () => {
|
|
331
|
+
const onDismiss = mock(() => {});
|
|
332
|
+
renderWithTheme(
|
|
333
|
+
<ConflictSheet conflicts={[]} onDismiss={onDismiss} onResolve={() => {}} visible={true} />
|
|
334
|
+
);
|
|
335
|
+
await flush();
|
|
336
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("calls onResolve with useServer without dismissing when other conflicts remain", async () => {
|
|
340
|
+
const onResolve = mock(() => {});
|
|
341
|
+
const onDismiss = mock(() => {});
|
|
342
|
+
const {getByTestId} = renderWithTheme(
|
|
343
|
+
<ConflictSheet
|
|
344
|
+
conflicts={[buildConflict(), buildConflict({entityId: "todo-2", mutationId: "m-2"})]}
|
|
345
|
+
onDismiss={onDismiss}
|
|
346
|
+
onResolve={onResolve}
|
|
347
|
+
visible={true}
|
|
348
|
+
/>
|
|
349
|
+
);
|
|
350
|
+
fireEvent.press(getByTestId("conflict-use-server-button-m-1"));
|
|
351
|
+
await flush();
|
|
352
|
+
expect(onResolve).toHaveBeenCalledTimes(1);
|
|
353
|
+
expect(onResolve.mock.calls[0][0]).toEqual({mutationId: "m-1", strategy: "useServer"});
|
|
354
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("uses the server version for every conflict after confirmation, dismissing once they clear", async () => {
|
|
358
|
+
const onResolve = mock(() => {});
|
|
359
|
+
const onDismiss = mock(() => {});
|
|
360
|
+
const {findByText, getByTestId, rerender} = renderWithTheme(
|
|
361
|
+
<ConflictSheet
|
|
362
|
+
conflicts={[buildConflict(), buildConflict({entityId: "todo-2", mutationId: "m-2"})]}
|
|
363
|
+
onDismiss={onDismiss}
|
|
364
|
+
onResolve={onResolve}
|
|
365
|
+
visible={true}
|
|
366
|
+
/>
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
fireEvent.press(getByTestId("conflict-use-server-all-button"));
|
|
370
|
+
fireEvent.press(await findByText("Confirm"));
|
|
371
|
+
await flush();
|
|
372
|
+
|
|
373
|
+
expect(onResolve).toHaveBeenCalledTimes(2);
|
|
374
|
+
expect(onResolve.mock.calls.map(([args]) => args)).toEqual([
|
|
375
|
+
{mutationId: "m-1", strategy: "useServer"},
|
|
376
|
+
{mutationId: "m-2", strategy: "useServer"},
|
|
377
|
+
]);
|
|
378
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
379
|
+
|
|
380
|
+
rerender(
|
|
381
|
+
<ConflictSheet conflicts={[]} onDismiss={onDismiss} onResolve={onResolve} visible={true} />
|
|
382
|
+
);
|
|
383
|
+
await flush();
|
|
384
|
+
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("keeps the local version for every conflict after confirmation, dismissing once they clear", async () => {
|
|
388
|
+
const onResolve = mock(() => {});
|
|
389
|
+
const onDismiss = mock(() => {});
|
|
390
|
+
const {findByText, getByTestId, rerender} = renderWithTheme(
|
|
391
|
+
<ConflictSheet
|
|
392
|
+
conflicts={[buildConflict(), buildConflict({entityId: "todo-2", mutationId: "m-2"})]}
|
|
393
|
+
onDismiss={onDismiss}
|
|
394
|
+
onResolve={onResolve}
|
|
395
|
+
visible={true}
|
|
396
|
+
/>
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
fireEvent.press(getByTestId("conflict-use-mine-all-button"));
|
|
400
|
+
fireEvent.press(await findByText("Confirm"));
|
|
401
|
+
await flush();
|
|
402
|
+
|
|
403
|
+
expect(onResolve).toHaveBeenCalledTimes(2);
|
|
404
|
+
expect(onResolve.mock.calls.map(([args]) => args)).toEqual([
|
|
405
|
+
{mutationId: "m-1", strategy: "keepMine"},
|
|
406
|
+
{mutationId: "m-2", strategy: "keepMine"},
|
|
407
|
+
]);
|
|
408
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
409
|
+
|
|
410
|
+
rerender(
|
|
411
|
+
<ConflictSheet conflicts={[]} onDismiss={onDismiss} onResolve={onResolve} visible={true} />
|
|
412
|
+
);
|
|
413
|
+
await flush();
|
|
414
|
+
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("suffixes testIDs with mutationId so multiple conflicts never collide (E6, RN Testing Library strict-mode fix)", () => {
|
|
418
|
+
const {getByTestId} = renderWithTheme(
|
|
419
|
+
<ConflictSheet
|
|
420
|
+
conflicts={[buildConflict(), buildConflict({entityId: "todo-2", mutationId: "m-2"})]}
|
|
421
|
+
onDismiss={() => {}}
|
|
422
|
+
onResolve={() => {}}
|
|
423
|
+
visible={true}
|
|
424
|
+
/>
|
|
425
|
+
);
|
|
426
|
+
// getByTestId throws if more than one match is found — this is exactly
|
|
427
|
+
// what would happen with the old shared "conflict-keep-mine-button" /
|
|
428
|
+
// "conflict-use-server-button" testIDs across two rendered conflicts.
|
|
429
|
+
expect(getByTestId("conflict-keep-mine-button-m-1")).toBeTruthy();
|
|
430
|
+
expect(getByTestId("conflict-keep-mine-button-m-2")).toBeTruthy();
|
|
431
|
+
expect(getByTestId("conflict-use-server-button-m-1")).toBeTruthy();
|
|
432
|
+
expect(getByTestId("conflict-use-server-button-m-2")).toBeTruthy();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("renders changed fields when a payload has no title", async () => {
|
|
436
|
+
const {getAllByText, getByTestId, getByText} = renderWithTheme(
|
|
437
|
+
<ConflictSheet
|
|
438
|
+
conflicts={[buildConflict({localData: JSON.stringify({completed: true})})]}
|
|
439
|
+
onDismiss={() => {}}
|
|
440
|
+
onResolve={() => {}}
|
|
441
|
+
visible={true}
|
|
442
|
+
/>
|
|
443
|
+
);
|
|
444
|
+
fireEvent.press(getByTestId("conflict-diff-toggle-todo-1"));
|
|
445
|
+
await flushDebounce();
|
|
446
|
+
expect(getAllByText("Completed")).toHaveLength(2);
|
|
447
|
+
expect(getByText("true")).toBeTruthy();
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("tolerates invalid JSON payloads", () => {
|
|
451
|
+
const {getByTestId} = renderWithTheme(
|
|
452
|
+
<ConflictSheet
|
|
453
|
+
conflicts={[buildConflict({localData: "not json", serverData: "{bad"})]}
|
|
454
|
+
onDismiss={() => {}}
|
|
455
|
+
onResolve={() => {}}
|
|
456
|
+
visible={true}
|
|
457
|
+
/>
|
|
458
|
+
);
|
|
459
|
+
expect(getByTestId("conflict-item-todo-1")).toBeTruthy();
|
|
460
|
+
});
|
|
461
|
+
});
|