@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.
Files changed (118) hide show
  1. package/dist/ActionSheet.d.ts +1 -1
  2. package/dist/Avatar.js +1 -4
  3. package/dist/Avatar.js.map +1 -1
  4. package/dist/Box.js +45 -9
  5. package/dist/Box.js.map +1 -1
  6. package/dist/Common.d.ts +21 -0
  7. package/dist/Common.js.map +1 -1
  8. package/dist/ConflictSheet.d.ts +53 -0
  9. package/dist/ConflictSheet.js +132 -0
  10. package/dist/ConflictSheet.js.map +1 -0
  11. package/dist/DateTimeActionSheet.d.ts +2 -1
  12. package/dist/DecimalRangeActionSheet.d.ts +1 -1
  13. package/dist/EmojiSelector.d.ts +1 -1
  14. package/dist/ErrorPage.d.ts +1 -1
  15. package/dist/HeightActionSheet.d.ts +1 -1
  16. package/dist/Hyperlink.d.ts +2 -1
  17. package/dist/Hyperlink.js +2 -1
  18. package/dist/Hyperlink.js.map +1 -1
  19. package/dist/Image.d.ts +1 -1
  20. package/dist/ImageBackground.d.ts +1 -1
  21. package/dist/MobileAddressAutoComplete.d.ts +1 -1
  22. package/dist/NumberPickerActionSheet.d.ts +1 -1
  23. package/dist/Page.d.ts +3 -3
  24. package/dist/PickerSelect.d.ts +1 -1
  25. package/dist/SidebarNavigation.js +1 -1
  26. package/dist/SidebarNavigation.js.map +1 -1
  27. package/dist/SidebarNavigation.native.js +1 -1
  28. package/dist/SidebarNavigation.native.js.map +1 -1
  29. package/dist/SplitPage.d.ts +1 -1
  30. package/dist/SplitPage.js +1 -4
  31. package/dist/SplitPage.js.map +1 -1
  32. package/dist/SplitPage.native.d.ts +1 -1
  33. package/dist/SyncStatusBanner.d.ts +46 -0
  34. package/dist/SyncStatusBanner.js +29 -0
  35. package/dist/SyncStatusBanner.js.map +1 -0
  36. package/dist/Theme.d.ts +1 -1
  37. package/dist/Toast.d.ts +9 -1
  38. package/dist/Toast.js +20 -7
  39. package/dist/Toast.js.map +1 -1
  40. package/dist/ToastNotifications.js +23 -1
  41. package/dist/ToastNotifications.js.map +1 -1
  42. package/dist/UnifiedAddressAutoComplete.d.ts +1 -1
  43. package/dist/Unifier.js +1 -1
  44. package/dist/Unifier.js.map +1 -1
  45. package/dist/conflictFieldDiff.d.ts +14 -0
  46. package/dist/conflictFieldDiff.js +62 -0
  47. package/dist/conflictFieldDiff.js.map +1 -0
  48. package/dist/icons/OfflineIcon.d.ts +1 -1
  49. package/dist/icons/OnlineIcon.d.ts +1 -1
  50. package/dist/icons/OutOfficeIcon.d.ts +1 -1
  51. package/dist/index.d.ts +5 -2
  52. package/dist/index.js +5 -2
  53. package/dist/index.js.map +1 -1
  54. package/dist/pdfHtmlTemplate.d.ts +30 -0
  55. package/dist/pdfHtmlTemplate.js +170 -0
  56. package/dist/pdfHtmlTemplate.js.map +1 -0
  57. package/dist/table/TableTitle.js +1 -3
  58. package/dist/table/TableTitle.js.map +1 -1
  59. package/dist/useAppLaunchOrForeground.d.ts +9 -0
  60. package/dist/useAppLaunchOrForeground.js +27 -0
  61. package/dist/useAppLaunchOrForeground.js.map +1 -0
  62. package/package.json +44 -37
  63. package/src/Box.test.tsx +39 -9
  64. package/src/Box.tsx +46 -7
  65. package/src/Common.ts +21 -3
  66. package/src/ConflictSheet.test.tsx +461 -0
  67. package/src/ConflictSheet.tsx +399 -0
  68. package/src/DataTable.test.tsx +15 -21
  69. package/src/Hyperlink.tsx +1 -1
  70. package/src/SidebarNavigation.native.tsx +1 -1
  71. package/src/SidebarNavigation.tsx +1 -1
  72. package/src/SyncStatusBanner.test.tsx +204 -0
  73. package/src/SyncStatusBanner.tsx +148 -0
  74. package/src/TapToEdit.test.tsx +8 -14
  75. package/src/TerrenoProvider.test.tsx +3 -4
  76. package/src/Toast.test.tsx +60 -0
  77. package/src/Toast.tsx +46 -1
  78. package/src/ToastNotifications.test.tsx +82 -0
  79. package/src/ToastNotifications.tsx +25 -1
  80. package/src/Tooltip.test.tsx +1 -0
  81. package/src/Unifier.ts +1 -1
  82. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +0 -3
  83. package/src/__snapshots__/Body.test.tsx.snap +0 -16
  84. package/src/__snapshots__/Box.test.tsx.snap +4 -13
  85. package/src/__snapshots__/Page.test.tsx.snap +0 -84
  86. package/src/__snapshots__/SplitPage.test.tsx.snap +24 -120
  87. package/src/__snapshots__/TapToEdit.test.tsx.snap +5 -16
  88. package/src/__snapshots__/Toast.test.tsx.snap +4 -2
  89. package/src/bunSetup.ts +19 -0
  90. package/src/conflictFieldDiff.test.ts +26 -0
  91. package/src/conflictFieldDiff.ts +78 -0
  92. package/src/index.tsx +5 -2
  93. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +0 -9
  94. package/src/pdfHtmlTemplate.ts +219 -0
  95. package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +0 -1
  96. package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +2 -16
  97. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +1 -17
  98. package/src/signUp/__snapshots__/Swiper.test.tsx.snap +0 -1
  99. package/src/table/__snapshots__/Table.test.tsx.snap +22 -87
  100. package/src/table/__snapshots__/TableHeader.test.tsx.snap +10 -50
  101. package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +10 -84
  102. package/src/table/__snapshots__/TableRow.test.tsx.snap +12 -77
  103. package/src/useAppLaunchOrForeground.test.tsx +54 -0
  104. package/src/useAppLaunchOrForeground.ts +30 -0
  105. package/dist/ConsentHistory.d.ts +0 -9
  106. package/dist/ConsentHistory.js +0 -70
  107. package/dist/ConsentHistory.js.map +0 -1
  108. package/dist/generateConsentHistoryPdf.d.ts +0 -2
  109. package/dist/generateConsentHistoryPdf.js +0 -185
  110. package/dist/generateConsentHistoryPdf.js.map +0 -1
  111. package/dist/useConsentHistory.d.ts +0 -63
  112. package/dist/useConsentHistory.js +0 -40
  113. package/dist/useConsentHistory.js.map +0 -1
  114. package/src/ConsentHistory.test.tsx +0 -161
  115. package/src/ConsentHistory.tsx +0 -249
  116. package/src/generateConsentHistoryPdf.ts +0 -211
  117. package/src/useConsentHistory.test.ts +0 -106
  118. package/src/useConsentHistory.ts +0 -94
package/src/Box.test.tsx CHANGED
@@ -502,6 +502,36 @@ describe("Box", () => {
502
502
  expect(root).toBeTruthy();
503
503
  // Just verify the component renders without error when onScroll is provided
504
504
  });
505
+
506
+ // Behavior props leaking into style reach the native view as unserializable
507
+ // values: a ref object in style is cyclical (host instance points back at the
508
+ // node) and gets dev-frozen, so React throws when detaching it on unmount.
509
+ it("should keep behavior props out of the ScrollView style", () => {
510
+ const scrollRef = React.createRef<any>();
511
+ const {root} = renderWithTheme(
512
+ <Box onScroll={mock(() => {})} scroll scrollRef={scrollRef}>
513
+ <Text>Scrollable</Text>
514
+ </Box>
515
+ );
516
+
517
+ const scrollView = root.findByType("ScrollView" as any);
518
+ expect(scrollView.props.style).not.toHaveProperty("scrollRef");
519
+ expect(scrollView.props.style).not.toHaveProperty("scroll");
520
+ expect(scrollView.props.style).not.toHaveProperty("onScroll");
521
+ expect(scrollView.props.style).not.toHaveProperty("testID");
522
+ });
523
+
524
+ it("should keep behavior props out of the View style", () => {
525
+ const {root} = renderWithTheme(
526
+ <Box avoidKeyboard keyboardOffset={12} onLayout={mock(() => {})} testID="behavior-box" />
527
+ );
528
+
529
+ const view = root.findByType("View");
530
+ expect(view.props.style).not.toHaveProperty("onLayout");
531
+ expect(view.props.style).not.toHaveProperty("avoidKeyboard");
532
+ expect(view.props.style).not.toHaveProperty("keyboardOffset");
533
+ expect(view.props.style).not.toHaveProperty("testID");
534
+ });
505
535
  });
506
536
 
507
537
  describe("keyboard avoidance", () => {
@@ -601,12 +631,10 @@ describe("Box", () => {
601
631
  });
602
632
 
603
633
  describe("warnings", () => {
604
- it("should warn when using wrap and alignItems together", () => {
634
+ it("should not warn when using wrap and alignItems together", () => {
605
635
  const consoleSpy = spyOn(console, "warn").mockImplementation(() => {});
606
636
  renderWithTheme(<Box alignItems="center" wrap />);
607
- expect(consoleSpy).toHaveBeenCalledWith(
608
- "React Native doesn't support wrap and alignItems together."
609
- );
637
+ expect(consoleSpy).not.toHaveBeenCalled();
610
638
  consoleSpy.mockRestore();
611
639
  });
612
640
  });
@@ -807,11 +835,13 @@ describe("Box", () => {
807
835
  expect(view.props.style.height).toBe(84);
808
836
  });
809
837
 
810
- it("warns when wrap is combined with alignItems on native", () => {
811
- const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
812
- renderWithTheme(<Box alignItems="center" wrap />);
813
- expect(warnSpy).toHaveBeenCalled();
814
- warnSpy.mockRestore();
838
+ it("keeps an explicit alignItems when combined with wrap", () => {
839
+ const {root} = renderWithTheme(<Box alignItems="center" wrap />);
840
+ const view = root.findByType("View");
841
+ expect(view.props.style).toMatchObject({
842
+ alignItems: "center",
843
+ flexWrap: "wrap",
844
+ });
815
845
  });
816
846
 
817
847
  it("applies dangerouslySetInlineStyle overrides", () => {
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
- wrap: (value) => ({alignItems: "flex-start", flexWrap: value ? "wrap" : "nowrap"}),
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 !== "children" && prop !== "onClick") {
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
@@ -516,6 +516,13 @@ export interface LayerProps {
516
516
  export interface AccessibilityProps {
517
517
  accessibilityLabel: string;
518
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;
519
526
  }
520
527
 
521
528
  export interface BoxPropsBase extends WithTestID {
@@ -2553,6 +2560,12 @@ export interface TextFieldPickerActionSheetProps {
2553
2560
 
2554
2561
  export interface ToastProps {
2555
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;
2556
2569
  variant?: "error" | "info" | "success" | "warning";
2557
2570
  secondary?: boolean;
2558
2571
  size?: "sm" | "lg";
@@ -2560,9 +2573,14 @@ export interface ToastProps {
2560
2573
  persistent?: boolean;
2561
2574
  // TODO enforce these should only show if size is "lg" with type discrinimation
2562
2575
  subtitle?: string;
2563
- // TODO Add buttons for Toast
2564
- // buttonText?: string;
2565
- // buttonOnClick?: () => void | Promise<void>;
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>;
2566
2584
  }
2567
2585
 
2568
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
+ });