@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.
Files changed (133) hide show
  1. package/LICENSE +203 -21
  2. package/dist/ActionSheet.d.ts +1 -1
  3. package/dist/Avatar.js +1 -4
  4. package/dist/Avatar.js.map +1 -1
  5. package/dist/Box.js +45 -9
  6. package/dist/Box.js.map +1 -1
  7. package/dist/Common.d.ts +21 -39
  8. package/dist/Common.js.map +1 -1
  9. package/dist/ConflictSheet.d.ts +53 -0
  10. package/dist/ConflictSheet.js +132 -0
  11. package/dist/ConflictSheet.js.map +1 -0
  12. package/dist/DateTimeActionSheet.d.ts +2 -1
  13. package/dist/DecimalRangeActionSheet.d.ts +1 -1
  14. package/dist/EmojiSelector.d.ts +1 -1
  15. package/dist/ErrorPage.d.ts +1 -1
  16. package/dist/HeightActionSheet.d.ts +1 -1
  17. package/dist/Hyperlink.d.ts +2 -1
  18. package/dist/Hyperlink.js +2 -1
  19. package/dist/Hyperlink.js.map +1 -1
  20. package/dist/Image.d.ts +1 -1
  21. package/dist/ImageBackground.d.ts +1 -1
  22. package/dist/MobileAddressAutoComplete.d.ts +1 -1
  23. package/dist/NumberPickerActionSheet.d.ts +1 -1
  24. package/dist/Page.d.ts +3 -3
  25. package/dist/PickerSelect.d.ts +1 -1
  26. package/dist/SidebarNavigation.js +1 -1
  27. package/dist/SidebarNavigation.js.map +1 -1
  28. package/dist/SidebarNavigation.native.js +1 -1
  29. package/dist/SidebarNavigation.native.js.map +1 -1
  30. package/dist/SplitPage.d.ts +1 -1
  31. package/dist/SplitPage.js +1 -4
  32. package/dist/SplitPage.js.map +1 -1
  33. package/dist/SplitPage.native.d.ts +1 -1
  34. package/dist/SyncStatusBanner.d.ts +46 -0
  35. package/dist/SyncStatusBanner.js +29 -0
  36. package/dist/SyncStatusBanner.js.map +1 -0
  37. package/dist/Theme.d.ts +1 -1
  38. package/dist/Theme.js +0 -1
  39. package/dist/Theme.js.map +1 -1
  40. package/dist/Toast.d.ts +9 -1
  41. package/dist/Toast.js +20 -7
  42. package/dist/Toast.js.map +1 -1
  43. package/dist/ToastNotifications.js +23 -1
  44. package/dist/ToastNotifications.js.map +1 -1
  45. package/dist/UnifiedAddressAutoComplete.d.ts +1 -1
  46. package/dist/Unifier.js +1 -1
  47. package/dist/Unifier.js.map +1 -1
  48. package/dist/conflictFieldDiff.d.ts +14 -0
  49. package/dist/conflictFieldDiff.js +62 -0
  50. package/dist/conflictFieldDiff.js.map +1 -0
  51. package/dist/icons/OfflineIcon.d.ts +1 -1
  52. package/dist/icons/OnlineIcon.d.ts +1 -1
  53. package/dist/icons/OutOfficeIcon.d.ts +1 -1
  54. package/dist/index.d.ts +5 -3
  55. package/dist/index.js +5 -3
  56. package/dist/index.js.map +1 -1
  57. package/dist/pdfHtmlTemplate.d.ts +30 -0
  58. package/dist/pdfHtmlTemplate.js +170 -0
  59. package/dist/pdfHtmlTemplate.js.map +1 -0
  60. package/dist/table/TableTitle.js +1 -3
  61. package/dist/table/TableTitle.js.map +1 -1
  62. package/dist/useAppLaunchOrForeground.d.ts +9 -0
  63. package/dist/useAppLaunchOrForeground.js +27 -0
  64. package/dist/useAppLaunchOrForeground.js.map +1 -0
  65. package/package.json +45 -39
  66. package/src/ActionSheet.test.tsx +37 -80
  67. package/src/Box.test.tsx +39 -9
  68. package/src/Box.tsx +46 -7
  69. package/src/Common.ts +21 -50
  70. package/src/ConflictSheet.test.tsx +461 -0
  71. package/src/ConflictSheet.tsx +399 -0
  72. package/src/ConsentNavigator.test.tsx +8 -6
  73. package/src/DateTimeField.test.tsx +0 -36
  74. package/src/Hyperlink.tsx +1 -1
  75. package/src/PickerSelect.test.tsx +12 -23
  76. package/src/SidebarNavigation.native.tsx +1 -1
  77. package/src/SidebarNavigation.tsx +1 -1
  78. package/src/SyncStatusBanner.test.tsx +204 -0
  79. package/src/SyncStatusBanner.tsx +148 -0
  80. package/src/TerrenoProvider.test.tsx +3 -4
  81. package/src/Theme.tsx +0 -1
  82. package/src/Toast.test.tsx +60 -0
  83. package/src/Toast.tsx +46 -1
  84. package/src/ToastNotifications.test.tsx +82 -0
  85. package/src/ToastNotifications.tsx +25 -1
  86. package/src/Unifier.ts +1 -1
  87. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +0 -3
  88. package/src/__snapshots__/Body.test.tsx.snap +0 -16
  89. package/src/__snapshots__/Box.test.tsx.snap +4 -13
  90. package/src/__snapshots__/Card.test.tsx.snap +0 -1
  91. package/src/__snapshots__/Page.test.tsx.snap +0 -84
  92. package/src/__snapshots__/SplitPage.test.tsx.snap +24 -120
  93. package/src/__snapshots__/TapToEdit.test.tsx.snap +5 -16
  94. package/src/__snapshots__/Toast.test.tsx.snap +4 -2
  95. package/src/bunSetup.ts +21 -6
  96. package/src/conflictFieldDiff.test.ts +26 -0
  97. package/src/conflictFieldDiff.ts +78 -0
  98. package/src/index.tsx +5 -3
  99. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +0 -9
  100. package/src/pdfHtmlTemplate.ts +219 -0
  101. package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +0 -1
  102. package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +2 -16
  103. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +1 -17
  104. package/src/signUp/__snapshots__/Swiper.test.tsx.snap +0 -1
  105. package/src/table/__snapshots__/Table.test.tsx.snap +22 -87
  106. package/src/table/__snapshots__/TableHeader.test.tsx.snap +10 -50
  107. package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +10 -84
  108. package/src/table/__snapshots__/TableRow.test.tsx.snap +12 -77
  109. package/src/useAppLaunchOrForeground.test.tsx +54 -0
  110. package/src/useAppLaunchOrForeground.ts +30 -0
  111. package/dist/ConsentHistory.d.ts +0 -9
  112. package/dist/ConsentHistory.js +0 -70
  113. package/dist/ConsentHistory.js.map +0 -1
  114. package/dist/EditableCard.d.ts +0 -3
  115. package/dist/EditableCard.js +0 -23
  116. package/dist/EditableCard.js.map +0 -1
  117. package/dist/generateConsentHistoryPdf.d.ts +0 -2
  118. package/dist/generateConsentHistoryPdf.js +0 -185
  119. package/dist/generateConsentHistoryPdf.js.map +0 -1
  120. package/dist/useConsentHistory.d.ts +0 -63
  121. package/dist/useConsentHistory.js +0 -40
  122. package/dist/useConsentHistory.js.map +0 -1
  123. package/src/ConsentHistory.test.tsx +0 -224
  124. package/src/ConsentHistory.tsx +0 -249
  125. package/src/DraggableList.test.tsx +0 -377
  126. package/src/EditableCard.test.tsx +0 -69
  127. package/src/EditableCard.tsx +0 -73
  128. package/src/SidebarNavigation.test.tsx +0 -339
  129. package/src/__snapshots__/EditableCard.test.tsx.snap +0 -242
  130. package/src/generateConsentHistoryPdf.test.ts +0 -253
  131. package/src/generateConsentHistoryPdf.ts +0 -211
  132. package/src/useConsentHistory.test.ts +0 -106
  133. package/src/useConsentHistory.ts +0 -94
@@ -1,249 +0,0 @@
1
- import {DateTime} from "luxon";
2
- import React, {useCallback, useState} from "react";
3
- import {Image, Pressable} from "react-native";
4
-
5
- import {Badge} from "./Badge";
6
- import {Box} from "./Box";
7
- import {Button} from "./Button";
8
- import {Card} from "./Card";
9
- import {generateConsentHistoryPdf} from "./generateConsentHistoryPdf";
10
- import {Icon} from "./Icon";
11
- import {IconButton} from "./IconButton";
12
- import {MarkdownView} from "./MarkdownView";
13
- import {Page} from "./Page";
14
- import {Spinner} from "./Spinner";
15
- import {Text} from "./Text";
16
- import type {ConsentHistoryEntry} from "./useConsentHistory";
17
- import {useConsentHistory} from "./useConsentHistory";
18
-
19
- interface ConsentHistoryProps {
20
- api: Parameters<typeof useConsentHistory>[0];
21
- baseUrl?: string;
22
- title?: string;
23
- }
24
-
25
- const formatDate = (value: unknown): string => {
26
- if (!value) {
27
- return "";
28
- }
29
- const dt = DateTime.fromISO(String(value));
30
- if (!dt.isValid) {
31
- return String(value);
32
- }
33
- return dt.toLocaleString(DateTime.DATETIME_MED);
34
- };
35
-
36
- const ConsentHistoryItem: React.FC<{entry: ConsentHistoryEntry}> = ({entry}) => {
37
- const [expanded, setExpanded] = useState(false);
38
- const [isDownloading, setIsDownloading] = useState(false);
39
-
40
- const toggle = useCallback(() => {
41
- setExpanded((prev) => !prev);
42
- }, []);
43
-
44
- const handleDownload = useCallback(async () => {
45
- setIsDownloading(true);
46
- try {
47
- await generateConsentHistoryPdf(entry);
48
- } catch (err) {
49
- console.error("Failed to generate PDF", err);
50
- } finally {
51
- setIsDownloading(false);
52
- }
53
- }, [entry]);
54
-
55
- const formTitle = entry.form?.title ?? "Unknown Form";
56
- const formType = entry.form?.type ?? "";
57
-
58
- const checkboxEntries =
59
- entry.checkboxValues && typeof entry.checkboxValues === "object"
60
- ? Object.entries(entry.checkboxValues)
61
- : [];
62
-
63
- return (
64
- <Card padding={0} testID={`consent-history-item-${entry._id}`}>
65
- <Pressable onPress={toggle} testID={`consent-history-item-toggle-${entry._id}`}>
66
- <Box direction="row" gap={3} padding={4}>
67
- <Box flex="grow" gap={1}>
68
- <Box alignItems="center" direction="row" gap={2}>
69
- <Text bold size="md">
70
- {formTitle}
71
- </Text>
72
- {formType ? <Badge status="neutral" value={formType} /> : null}
73
- </Box>
74
- <Box alignItems="center" direction="row" gap={2}>
75
- <Badge
76
- status={entry.agreed ? "success" : "error"}
77
- value={entry.agreed ? "Agreed" : "Declined"}
78
- />
79
- <Text color="secondaryDark" size="sm">
80
- {formatDate(entry.agreedAt)}
81
- </Text>
82
- </Box>
83
- </Box>
84
- <Box alignItems="center" justifyContent="center">
85
- <Icon
86
- color="secondaryDark"
87
- iconName={expanded ? "chevron-up" : "chevron-down"}
88
- size="sm"
89
- />
90
- </Box>
91
- </Box>
92
- </Pressable>
93
-
94
- {expanded && (
95
- <Box gap={3} padding={4} testID={`consent-history-item-details-${entry._id}`}>
96
- <Box alignItems="center" direction="row" justifyContent="between">
97
- <Box color="disabled" flex="grow" height={1} />
98
- <Box marginLeft={2}>
99
- <IconButton
100
- accessibilityLabel="Download PDF"
101
- iconName="download"
102
- loading={isDownloading}
103
- onClick={handleDownload}
104
- testID={`consent-history-download-${entry._id}`}
105
- tooltipText="Download PDF"
106
- />
107
- </Box>
108
- </Box>
109
-
110
- {entry.form?.version !== undefined && (
111
- <Box alignItems="center" direction="row" gap={2}>
112
- <Text color="secondaryDark" size="sm">
113
- Version:
114
- </Text>
115
- <Text size="sm">{entry.form.version}</Text>
116
- </Box>
117
- )}
118
-
119
- {entry.locale && (
120
- <Box alignItems="center" direction="row" gap={2}>
121
- <Text color="secondaryDark" size="sm">
122
- Locale:
123
- </Text>
124
- <Text size="sm">{entry.locale}</Text>
125
- </Box>
126
- )}
127
-
128
- {entry.signedAt && (
129
- <Box alignItems="center" direction="row" gap={2}>
130
- <Text color="secondaryDark" size="sm">
131
- Signed:
132
- </Text>
133
- <Text size="sm">{formatDate(entry.signedAt)}</Text>
134
- </Box>
135
- )}
136
-
137
- {entry.ipAddress && (
138
- <Box alignItems="center" direction="row" gap={2}>
139
- <Text color="secondaryDark" size="sm">
140
- IP Address:
141
- </Text>
142
- <Text size="sm">{entry.ipAddress}</Text>
143
- </Box>
144
- )}
145
-
146
- {checkboxEntries.length > 0 && (
147
- <Box gap={2}>
148
- <Text bold color="secondaryDark" size="sm">
149
- Checkboxes
150
- </Text>
151
- {checkboxEntries.map(([index, checked]) => {
152
- const label = entry.form?.checkboxes?.[Number(index)]?.label;
153
- return (
154
- <Box alignItems="center" direction="row" gap={2} key={index}>
155
- <Badge
156
- status={checked ? "success" : "neutral"}
157
- value={checked ? "Yes" : "No"}
158
- />
159
- <Text size="sm">{label ?? `Checkbox ${index}`}</Text>
160
- </Box>
161
- );
162
- })}
163
- </Box>
164
- )}
165
-
166
- {entry.signature && (
167
- <Box gap={2}>
168
- <Text bold color="secondaryDark" size="sm">
169
- Signature
170
- </Text>
171
- <Box border="default" padding={2} rounding="sm">
172
- <Image
173
- accessibilityLabel="Your signature"
174
- accessible
175
- resizeMode="contain"
176
- source={{uri: entry.signature}}
177
- style={{height: 80, width: "100%"}}
178
- testID={`consent-history-signature-${entry._id}`}
179
- />
180
- </Box>
181
- </Box>
182
- )}
183
-
184
- {entry.contentSnapshot && (
185
- <Box gap={2}>
186
- <Text bold color="secondaryDark" size="sm">
187
- Form Content
188
- </Text>
189
- <Box border="default" padding={3} rounding="sm">
190
- <MarkdownView>{entry.contentSnapshot}</MarkdownView>
191
- </Box>
192
- </Box>
193
- )}
194
- </Box>
195
- )}
196
- </Card>
197
- );
198
- };
199
-
200
- export const ConsentHistory: React.FC<ConsentHistoryProps> = ({
201
- api,
202
- baseUrl,
203
- title = "My Consents",
204
- }) => {
205
- const {entries, isLoading, error, refetch} = useConsentHistory(api, baseUrl);
206
-
207
- if (isLoading) {
208
- return (
209
- <Page maxWidth={800} title={title}>
210
- <Box alignItems="center" justifyContent="center" padding={6}>
211
- <Spinner />
212
- </Box>
213
- </Page>
214
- );
215
- }
216
-
217
- if (error) {
218
- return (
219
- <Page maxWidth={800} title={title}>
220
- <Box alignItems="center" direction="column" gap={3} padding={6}>
221
- <Text color="error" size="lg">
222
- Failed to load consent history
223
- </Text>
224
- <Button onClick={refetch} text="Retry" />
225
- </Box>
226
- </Page>
227
- );
228
- }
229
-
230
- if (entries.length === 0) {
231
- return (
232
- <Page maxWidth={800} title={title}>
233
- <Box alignItems="center" padding={6}>
234
- <Text color="secondaryDark">No consent records found.</Text>
235
- </Box>
236
- </Page>
237
- );
238
- }
239
-
240
- return (
241
- <Page maxWidth={800} scroll title={title}>
242
- <Box gap={3} padding={4} testID="consent-history-list">
243
- {entries.map((entry) => (
244
- <ConsentHistoryItem entry={entry} key={entry._id} />
245
- ))}
246
- </Box>
247
- </Page>
248
- );
249
- };
@@ -1,377 +0,0 @@
1
- import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
- import {act, render} from "@testing-library/react-native";
3
- import React from "react";
4
- import {Platform, Text as RNText, View} from "react-native";
5
- import {Gesture} from "react-native-gesture-handler";
6
- import * as Reanimated from "react-native-reanimated";
7
-
8
- import {DraggableList, DragItem} from "./DraggableList";
9
-
10
- interface PanEvent {
11
- translationY: number;
12
- }
13
-
14
- interface CapturedGesture {
15
- onBegin?: () => void;
16
- onChange?: (event: PanEvent) => void;
17
- onFinalize?: () => void;
18
- }
19
-
20
- let capturedGestures: CapturedGesture[] = [];
21
-
22
- /** Replaces Gesture.Pan with a chainable stub that records the registered handlers. */
23
- const capturePanGestures = () => {
24
- return spyOn(Gesture, "Pan").mockImplementation(() => {
25
- const captured: CapturedGesture = {};
26
- capturedGestures.push(captured);
27
- const chainable = {
28
- onBegin: (handler: () => void) => {
29
- captured.onBegin = handler;
30
- return chainable;
31
- },
32
- onChange: (handler: (event: PanEvent) => void) => {
33
- captured.onChange = handler;
34
- return chainable;
35
- },
36
- onFinalize: (handler: () => void) => {
37
- captured.onFinalize = handler;
38
- return chainable;
39
- },
40
- };
41
- return chainable as unknown as ReturnType<typeof Gesture.Pan>;
42
- });
43
- };
44
-
45
- const renderItem = ({item}: {item: string}): React.ReactElement => <RNText>{item}</RNText>;
46
-
47
- describe("DraggableList", () => {
48
- let panSpy: ReturnType<typeof capturePanGestures>;
49
-
50
- beforeEach(() => {
51
- capturedGestures = [];
52
- panSpy = capturePanGestures();
53
- });
54
-
55
- afterEach(() => {
56
- panSpy.mockRestore();
57
- });
58
-
59
- it("renders one draggable item per id", () => {
60
- const {getByText} = render(
61
- <DraggableList
62
- callbackNewDataIds={() => {}}
63
- dataIDs={["a", "b", "c"]}
64
- renderItem={renderItem}
65
- />
66
- );
67
-
68
- expect(getByText("a")).toBeTruthy();
69
- expect(getByText("b")).toBeTruthy();
70
- expect(getByText("c")).toBeTruthy();
71
- });
72
-
73
- it("falls back to the deprecated data prop", () => {
74
- const {getByText} = render(
75
- <DraggableList callbackNewDataIds={() => {}} data={["one", "two"]} renderItem={renderItem} />
76
- );
77
-
78
- expect(getByText("one")).toBeTruthy();
79
- expect(getByText("two")).toBeTruthy();
80
- });
81
-
82
- it("renders an empty list when no ids are provided", () => {
83
- const {toJSON} = render(
84
- <DraggableList callbackNewDataIds={() => {}} renderItem={renderItem} />
85
- );
86
-
87
- expect(toJSON()).toBeTruthy();
88
- expect(capturedGestures).toHaveLength(0);
89
- });
90
-
91
- it("renders a custom grip element", () => {
92
- const {getByText} = render(
93
- <DraggableList
94
- callbackNewDataIds={() => {}}
95
- dataIDs={["a"]}
96
- renderGrip={<RNText>grip</RNText>}
97
- renderItem={renderItem}
98
- />
99
- );
100
-
101
- expect(getByText("grip")).toBeTruthy();
102
- });
103
-
104
- it("renders a grip render function", () => {
105
- const {getByText} = render(
106
- <DraggableList
107
- callbackNewDataIds={() => {}}
108
- dataIDs={["a"]}
109
- renderGrip={() => <RNText>grip-fn</RNText>}
110
- renderItem={renderItem}
111
- />
112
- );
113
-
114
- expect(getByText("grip-fn")).toBeTruthy();
115
- });
116
-
117
- it("throws when the data prop is not an array", () => {
118
- expect(() =>
119
- render(
120
- <DraggableList
121
- callbackNewDataIds={() => {}}
122
- dataIDs={"nope" as unknown as string[]}
123
- renderItem={renderItem}
124
- />
125
- )
126
- ).toThrow(/should be \[\]/);
127
- });
128
-
129
- it("throws when renderItem is missing", () => {
130
- expect(() =>
131
- render(
132
- <DraggableList
133
- callbackNewDataIds={() => {}}
134
- dataIDs={["a"]}
135
- renderItem={undefined as unknown as typeof renderItem}
136
- />
137
- )
138
- ).toThrow(/"renderItem" prop is missing/);
139
- });
140
-
141
- it("throws when callbackNewDataIds is missing", () => {
142
- expect(() =>
143
- render(
144
- <DraggableList
145
- callbackNewDataIds={undefined as unknown as (ids: string[]) => void}
146
- dataIDs={["a"]}
147
- renderItem={renderItem}
148
- />
149
- )
150
- ).toThrow(/"callbackNewDataIds" prop is missing/);
151
- });
152
-
153
- it("throws when callbackNewDataIds is not a function", () => {
154
- expect(() =>
155
- render(
156
- <DraggableList
157
- callbackNewDataIds={"nope" as unknown as (ids: string[]) => void}
158
- dataIDs={["a"]}
159
- renderItem={renderItem}
160
- />
161
- )
162
- ).toThrow(/should be function type/);
163
- });
164
-
165
- it("updates positions when the ids change", () => {
166
- const {getByText, rerender} = render(
167
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
168
- );
169
-
170
- rerender(
171
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["b", "a"]} renderItem={renderItem} />
172
- );
173
-
174
- expect(getByText("a")).toBeTruthy();
175
- expect(getByText("b")).toBeTruthy();
176
- });
177
-
178
- describe("drag gestures", () => {
179
- it("vibrates when the drag begins", () => {
180
- const passVibration = mock(() => {});
181
- render(
182
- <DraggableList
183
- callbackNewDataIds={() => {}}
184
- dataIDs={["a", "b"]}
185
- passVibration={passVibration}
186
- renderItem={renderItem}
187
- />
188
- );
189
-
190
- act(() => {
191
- capturedGestures[0]?.onBegin?.();
192
- });
193
-
194
- expect(passVibration).toHaveBeenCalled();
195
- });
196
-
197
- it("begins the drag without a vibration callback", () => {
198
- render(
199
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
200
- );
201
-
202
- expect(() =>
203
- act(() => {
204
- capturedGestures[0]?.onBegin?.();
205
- })
206
- ).not.toThrow();
207
- });
208
-
209
- it("reorders items and vibrates when dragged past another item", () => {
210
- const passVibration = mock(() => {});
211
- render(
212
- <DraggableList
213
- callbackNewDataIds={() => {}}
214
- dataIDs={["a", "b", "c"]}
215
- itemHeight={50}
216
- itemsGap={5}
217
- passVibration={passVibration}
218
- renderItem={renderItem}
219
- />
220
- );
221
-
222
- act(() => {
223
- capturedGestures[0]?.onBegin?.();
224
- capturedGestures[0]?.onChange?.({translationY: 120});
225
- });
226
-
227
- // Once for the drag start, once for crossing into a new position.
228
- expect(passVibration.mock.calls.length).toBeGreaterThan(1);
229
- });
230
-
231
- it("does not reorder when the item stays in place", () => {
232
- const passVibration = mock(() => {});
233
- render(
234
- <DraggableList
235
- callbackNewDataIds={() => {}}
236
- dataIDs={["a", "b", "c"]}
237
- passVibration={passVibration}
238
- renderItem={renderItem}
239
- />
240
- );
241
-
242
- act(() => {
243
- capturedGestures[0]?.onChange?.({translationY: 1});
244
- });
245
-
246
- expect(passVibration).not.toHaveBeenCalled();
247
- });
248
-
249
- it("clamps the new position to the end of the list", () => {
250
- const callbackNewDataIds = mock(() => {});
251
- render(
252
- <DraggableList
253
- callbackNewDataIds={callbackNewDataIds}
254
- dataIDs={["a", "b", "c"]}
255
- renderItem={renderItem}
256
- />
257
- );
258
-
259
- act(() => {
260
- capturedGestures[0]?.onChange?.({translationY: 10000});
261
- capturedGestures[0]?.onFinalize?.();
262
- });
263
-
264
- expect(callbackNewDataIds).toHaveBeenCalledWith(["c", "b", "a"]);
265
- });
266
-
267
- it("reports the new order once per unique arrangement", () => {
268
- const callbackNewDataIds = mock(() => {});
269
- render(
270
- <DraggableList
271
- callbackNewDataIds={callbackNewDataIds}
272
- dataIDs={["a", "b"]}
273
- renderItem={renderItem}
274
- />
275
- );
276
-
277
- act(() => {
278
- capturedGestures[0]?.onFinalize?.();
279
- capturedGestures[0]?.onFinalize?.();
280
- });
281
-
282
- expect(callbackNewDataIds).toHaveBeenCalledTimes(1);
283
- expect(callbackNewDataIds).toHaveBeenCalledWith(["a", "b"]);
284
- });
285
- });
286
-
287
- describe("animated styles", () => {
288
- const originalOS = Platform.OS;
289
-
290
- afterEach(() => {
291
- Platform.OS = originalOS;
292
- });
293
-
294
- it("omits shadows on Android", () => {
295
- Platform.OS = "android";
296
- const {getByText} = render(
297
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["a"]} renderItem={renderItem} />
298
- );
299
-
300
- expect(getByText("a")).toBeTruthy();
301
- });
302
-
303
- it("adds shadow styles on iOS", () => {
304
- Platform.OS = "ios";
305
- const {getByText} = render(
306
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["a"]} renderItem={renderItem} />
307
- );
308
-
309
- expect(getByText("a")).toBeTruthy();
310
- });
311
- });
312
-
313
- it("mirrors the shared positions into state", () => {
314
- let invocations = 0;
315
- const reactionSpy = spyOn(Reanimated, "useAnimatedReaction").mockImplementation(((
316
- prepare: () => unknown,
317
- react: (current: unknown, previous: unknown) => void
318
- ) => {
319
- invocations += 1;
320
- // Only run the first registered reaction (the list-level one) so the
321
- // render-phase state update settles instead of looping.
322
- if (invocations === 1) {
323
- react(prepare(), undefined);
324
- }
325
- }) as unknown as typeof Reanimated.useAnimatedReaction);
326
-
327
- const {getByText} = render(
328
- <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
329
- );
330
-
331
- expect(getByText("a")).toBeTruthy();
332
- reactionSpy.mockRestore();
333
- });
334
-
335
- describe("DragItem", () => {
336
- const baseProps = {
337
- index: 0,
338
- item: "a",
339
- itemBorderRadius: 8,
340
- itemHeight: 50,
341
- itemsCount: 1,
342
- itemsGap: 5,
343
- plainPosition: 0,
344
- positions: {value: {a: 0}},
345
- renderItem,
346
- scrollY: {value: 0},
347
- };
348
-
349
- it("syncs its offset when the shared positions change", () => {
350
- const reactionSpy = spyOn(Reanimated, "useAnimatedReaction").mockImplementation(((
351
- prepare: () => unknown,
352
- react: (current: unknown, previous: unknown) => void
353
- ) => {
354
- react(prepare(), undefined);
355
- }) as unknown as typeof Reanimated.useAnimatedReaction);
356
-
357
- const {getByText} = render(
358
- <View>
359
- <DragItem {...baseProps} item="b" itemsCount={2} positions={{value: {a: 0, b: 1}}} />
360
- </View>
361
- );
362
-
363
- expect(getByText("b")).toBeTruthy();
364
- reactionSpy.mockRestore();
365
- });
366
-
367
- it("falls back to a zero offset when the computed offset is not a number", () => {
368
- const {getByText} = render(
369
- <View>
370
- <DragItem {...baseProps} itemHeight={Number.NaN} />
371
- </View>
372
- );
373
-
374
- expect(getByText("a")).toBeTruthy();
375
- });
376
- });
377
- });
@@ -1,69 +0,0 @@
1
- import {describe, expect, it} from "bun:test";
2
- import type {ReactTestRendererJSON} from "react-test-renderer";
3
-
4
- import {EditableCard} from "./EditableCard";
5
- import {Text} from "./Text";
6
- import {renderWithTheme} from "./test-utils";
7
-
8
- describe("EditableCard", () => {
9
- it("renders correctly with all props", () => {
10
- const {toJSON} = renderWithTheme(
11
- <EditableCard
12
- badge={{iconName: "check", secondary: true, status: "success", value: "Verified"}}
13
- description="123 Main Street"
14
- helperText="Last updated 2 days ago"
15
- iconName="location-dot"
16
- onEdit={() => {}}
17
- title="Home Address"
18
- />
19
- );
20
- expect(toJSON()).toMatchSnapshot();
21
- });
22
-
23
- it("renders title, description and helper text", () => {
24
- const {getByText} = renderWithTheme(
25
- <EditableCard
26
- description="123 Main Street"
27
- helperText="Last updated 2 days ago"
28
- title="Home Address"
29
- />
30
- );
31
- expect(getByText("Home Address")).toBeTruthy();
32
- expect(getByText("123 Main Street")).toBeTruthy();
33
- expect(getByText("Last updated 2 days ago")).toBeTruthy();
34
- });
35
-
36
- it("renders the badge", () => {
37
- const {getByText} = renderWithTheme(
38
- <EditableCard
39
- badge={{secondary: true, status: "success", value: "Verified"}}
40
- title="Home Address"
41
- />
42
- );
43
- expect(getByText("Verified")).toBeTruthy();
44
- });
45
-
46
- it("uses the attention surface when attention is set", () => {
47
- const {toJSON} = renderWithTheme(
48
- <EditableCard attention description="123 Main Street" title="Home Address" />
49
- );
50
- const rendered = toJSON() as ReactTestRendererJSON;
51
- expect(rendered.props.style).toMatchObject({backgroundColor: "#F2F9FA"});
52
- });
53
-
54
- it("renders children below the text content", () => {
55
- const {getByText} = renderWithTheme(
56
- <EditableCard title="Home Address">
57
- <Text>Extra content</Text>
58
- </EditableCard>
59
- );
60
- expect(getByText("Extra content")).toBeTruthy();
61
- });
62
-
63
- it("renders with testID", () => {
64
- const {getByTestId} = renderWithTheme(
65
- <EditableCard testID="editable-card" title="Home Address" />
66
- );
67
- expect(getByTestId("editable-card")).toBeTruthy();
68
- });
69
- });