@terreno/ui 0.29.0 → 0.31.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 (43) hide show
  1. package/LICENSE +21 -203
  2. package/dist/AiSuggestionBox.js +7 -12
  3. package/dist/AiSuggestionBox.js.map +1 -1
  4. package/dist/Common.d.ts +65 -0
  5. package/dist/Common.js.map +1 -1
  6. package/dist/EditableCard.d.ts +3 -0
  7. package/dist/EditableCard.js +23 -0
  8. package/dist/EditableCard.js.map +1 -0
  9. package/dist/Theme.js +1 -0
  10. package/dist/Theme.js.map +1 -1
  11. package/dist/ThumbsUpDownFeedback.d.ts +8 -0
  12. package/dist/ThumbsUpDownFeedback.js +60 -0
  13. package/dist/ThumbsUpDownFeedback.js.map +1 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/package.json +3 -2
  18. package/src/ActionSheet.test.tsx +80 -37
  19. package/src/AiSuggestionBox.test.tsx +2 -2
  20. package/src/AiSuggestionBox.tsx +17 -48
  21. package/src/Common.ts +75 -0
  22. package/src/ConsentHistory.test.tsx +224 -0
  23. package/src/ConsentNavigator.test.tsx +6 -8
  24. package/src/DataTable.test.tsx +15 -21
  25. package/src/DateTimeField.test.tsx +36 -0
  26. package/src/DraggableList.test.tsx +377 -0
  27. package/src/EditableCard.test.tsx +69 -0
  28. package/src/EditableCard.tsx +73 -0
  29. package/src/PickerSelect.test.tsx +23 -12
  30. package/src/SidebarNavigation.test.tsx +339 -0
  31. package/src/SignatureCaptureField.test.tsx +30 -0
  32. package/src/TapToEdit.test.tsx +8 -14
  33. package/src/Theme.tsx +1 -0
  34. package/src/ThumbsUpDownFeedback.test.tsx +100 -0
  35. package/src/ThumbsUpDownFeedback.tsx +118 -0
  36. package/src/Tooltip.test.tsx +1 -0
  37. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +108 -30
  38. package/src/__snapshots__/Card.test.tsx.snap +1 -0
  39. package/src/__snapshots__/EditableCard.test.tsx.snap +242 -0
  40. package/src/__snapshots__/SignatureCaptureField.test.tsx.snap +45 -0
  41. package/src/bunSetup.ts +11 -2
  42. package/src/generateConsentHistoryPdf.test.ts +253 -0
  43. package/src/index.tsx +2 -0
package/src/bunSetup.ts CHANGED
@@ -303,9 +303,12 @@ mock.module("react-native", () => {
303
303
  };
304
304
  const UIManager = {
305
305
  getViewManagerConfig: mock(() => ({})),
306
+ measure: mock(() => {}),
306
307
  setLayoutAnimationEnabledExperimental: mock(() => {}),
307
308
  };
308
- const findNodeHandle = mock(() => null);
309
+ // Node handles are opaque numbers in React Native; pass them through so code that
310
+ // measures the currently focused field can be exercised in tests.
311
+ const findNodeHandle = mock((node: unknown) => (typeof node === "number" ? node : null));
309
312
  const requireNativeComponent = mock((name: string) => name);
310
313
  const TurboModuleRegistry = {
311
314
  get: mock(() => null),
@@ -756,6 +759,11 @@ mock.module("@expo/vector-icons/FontAwesome6", () => ({
756
759
  default: mock(() => null),
757
760
  }));
758
761
 
762
+ // Mock @expo/vector-icons/MaterialIcons
763
+ mock.module("@expo/vector-icons/MaterialIcons", () => ({
764
+ default: mock(() => null),
765
+ }));
766
+
759
767
  // Mock linkify-it - need to mock the Hyperlink component directly instead
760
768
  mock.module("./Hyperlink", () => ({
761
769
  Hyperlink: ({children}: MockComponentProps) => React.createElement("View", {}, children),
@@ -1112,12 +1120,13 @@ mock.module("react-native/Libraries/LayoutAnimation/LayoutAnimation", () => ({
1112
1120
  mock.module("react-native/Libraries/ReactNative/UIManager", () => ({
1113
1121
  default: {
1114
1122
  getViewManagerConfig: mock(() => ({})),
1123
+ measure: mock(() => {}),
1115
1124
  setLayoutAnimationEnabledExperimental: mock(() => {}),
1116
1125
  },
1117
1126
  }));
1118
1127
 
1119
1128
  mock.module("react-native/Libraries/Renderer/shims/ReactNative", () => ({
1120
- findNodeHandle: mock(() => null),
1129
+ findNodeHandle: mock((node: unknown) => (typeof node === "number" ? node : null)),
1121
1130
  }));
1122
1131
 
1123
1132
  mock.module("react-native/Libraries/Components/StatusBar/StatusBar", () => ({
@@ -0,0 +1,253 @@
1
+ import {beforeEach, describe, expect, it, mock} from "bun:test";
2
+
3
+ import type {ConsentHistoryEntry} from "./useConsentHistory";
4
+
5
+ interface PdfCall {
6
+ args: unknown[];
7
+ method: string;
8
+ }
9
+
10
+ interface MockDoc {
11
+ calls: PdfCall[];
12
+ savedFilename?: string;
13
+ }
14
+
15
+ let docs: MockDoc[] = [];
16
+ let addImageShouldThrow = false;
17
+
18
+ class MockJsPdf {
19
+ calls: PdfCall[] = [];
20
+ savedFilename?: string;
21
+
22
+ constructor(..._args: unknown[]) {
23
+ docs.push(this as unknown as MockDoc);
24
+ }
25
+
26
+ private record(method: string, args: unknown[]): void {
27
+ this.calls.push({args, method});
28
+ }
29
+
30
+ setFontSize(...args: unknown[]): void {
31
+ this.record("setFontSize", args);
32
+ }
33
+
34
+ setFont(...args: unknown[]): void {
35
+ this.record("setFont", args);
36
+ }
37
+
38
+ setDrawColor(...args: unknown[]): void {
39
+ this.record("setDrawColor", args);
40
+ }
41
+
42
+ setTextColor(...args: unknown[]): void {
43
+ this.record("setTextColor", args);
44
+ }
45
+
46
+ text(...args: unknown[]): void {
47
+ this.record("text", args);
48
+ }
49
+
50
+ line(...args: unknown[]): void {
51
+ this.record("line", args);
52
+ }
53
+
54
+ addPage(...args: unknown[]): void {
55
+ this.record("addPage", args);
56
+ }
57
+
58
+ addImage(...args: unknown[]): void {
59
+ this.record("addImage", args);
60
+ if (addImageShouldThrow) {
61
+ throw new Error("cannot embed image");
62
+ }
63
+ }
64
+
65
+ splitTextToSize(textValue: string, ..._rest: unknown[]): string[] {
66
+ this.record("splitTextToSize", [textValue]);
67
+ return String(textValue).split("\n");
68
+ }
69
+
70
+ save(...args: unknown[]): void {
71
+ this.record("save", args);
72
+ this.savedFilename = String(args[0]);
73
+ }
74
+ }
75
+
76
+ mock.module("jspdf", () => ({jsPDF: MockJsPdf}));
77
+
78
+ const {generateConsentHistoryPdf} = await import("./generateConsentHistoryPdf");
79
+
80
+ const lastDoc = (): MockDoc => docs[docs.length - 1]!;
81
+
82
+ const textStrings = (doc: MockDoc): string[] =>
83
+ doc.calls.filter((c) => c.method === "text").map((c) => String(c.args[0]));
84
+
85
+ const wasCalled = (doc: MockDoc, method: string): boolean =>
86
+ doc.calls.some((c) => c.method === method);
87
+
88
+ const baseEntry: ConsentHistoryEntry = {
89
+ _id: "response-1",
90
+ agreed: true,
91
+ agreedAt: "2024-01-15T10:30:00.000Z",
92
+ form: {
93
+ captureSignature: true,
94
+ checkboxes: [
95
+ {label: "I agree to the terms", required: true},
96
+ {label: "I consent to data use", required: false},
97
+ ],
98
+ slug: "privacy-policy",
99
+ title: "Privacy Policy",
100
+ type: "consent",
101
+ version: 3,
102
+ },
103
+ };
104
+
105
+ describe("generateConsentHistoryPdf", () => {
106
+ beforeEach(() => {
107
+ docs = [];
108
+ addImageShouldThrow = false;
109
+ });
110
+
111
+ it("renders a complete consent record with every section", async () => {
112
+ const entry: ConsentHistoryEntry = {
113
+ ...baseEntry,
114
+ checkboxValues: {"0": true, "1": false, "2": true},
115
+ contentSnapshot: "First line of the snapshot\nSecond line of the snapshot",
116
+ formVersionSnapshot: 3,
117
+ ipAddress: "203.0.113.7",
118
+ locale: "en-US",
119
+ signature: "data:image/png;base64,AAAA",
120
+ signedAt: "2024-01-15T10:31:00.000Z",
121
+ userAgent: "Mozilla/5.0",
122
+ };
123
+
124
+ await generateConsentHistoryPdf(entry);
125
+
126
+ const doc = lastDoc();
127
+ const texts = textStrings(doc);
128
+ expect(texts).toContain("Consent Record");
129
+ expect(texts).toContain("Privacy Policy");
130
+ expect(texts).toContain("Response Details");
131
+ expect(texts).toContain("Checkbox Responses");
132
+ expect(texts).toContain("Audit Trail");
133
+ expect(texts).toContain("Signature");
134
+ expect(texts).toContain("Content Snapshot");
135
+ // Known checkbox labels render with their check state.
136
+ expect(texts).toContain("[x] I agree to the terms");
137
+ expect(texts).toContain("[ ] I consent to data use");
138
+ // Unknown checkbox index falls back to a generated label.
139
+ expect(texts).toContain("[x] Checkbox 2");
140
+ // Agreed decision.
141
+ expect(texts.some((t) => t === "Agreed")).toBe(true);
142
+ // Snapshot lines are split and rendered individually.
143
+ expect(texts).toContain("First line of the snapshot");
144
+ expect(texts).toContain("Second line of the snapshot");
145
+ // Image embedded as PNG.
146
+ const image = doc.calls.find((c) => c.method === "addImage");
147
+ expect(image?.args[1]).toBe("PNG");
148
+ // Footer includes the response id.
149
+ expect(texts.some((t) => t.includes("Response ID: response-1"))).toBe(true);
150
+ // Saved with a slug-based filename.
151
+ expect(doc.savedFilename).toContain("consent-privacy-policy-");
152
+ expect(doc.savedFilename?.endsWith(".pdf")).toBe(true);
153
+ });
154
+
155
+ it("handles a minimal declined entry with no optional sections", async () => {
156
+ const entry: ConsentHistoryEntry = {
157
+ _id: "",
158
+ agreed: false,
159
+ agreedAt: "",
160
+ form: null,
161
+ };
162
+
163
+ await generateConsentHistoryPdf(entry);
164
+
165
+ const doc = lastDoc();
166
+ const texts = textStrings(doc);
167
+ expect(texts).toContain("Unknown Form");
168
+ expect(texts.some((t) => t === "Declined")).toBe(true);
169
+ expect(texts).not.toContain("Checkbox Responses");
170
+ expect(texts).not.toContain("Audit Trail");
171
+ expect(texts).not.toContain("Signature");
172
+ expect(texts).not.toContain("Content Snapshot");
173
+ expect(wasCalled(doc, "addImage")).toBe(false);
174
+ // No _id means no response-id footer line.
175
+ expect(texts.some((t) => t.includes("Response ID:"))).toBe(false);
176
+ // Falls back to "response" in the filename when there is no slug.
177
+ expect(doc.savedFilename).toContain("consent-response-");
178
+ });
179
+
180
+ it("embeds a JPEG signature when the data URI is not PNG", async () => {
181
+ const entry: ConsentHistoryEntry = {
182
+ ...baseEntry,
183
+ signature: "data:image/jpeg;base64,BBBB",
184
+ };
185
+
186
+ await generateConsentHistoryPdf(entry);
187
+
188
+ const doc = lastDoc();
189
+ const image = doc.calls.find((c) => c.method === "addImage");
190
+ expect(image?.args[1]).toBe("JPEG");
191
+ });
192
+
193
+ it("falls back to a placeholder when the signature image cannot be embedded", async () => {
194
+ addImageShouldThrow = true;
195
+ const entry: ConsentHistoryEntry = {
196
+ ...baseEntry,
197
+ signature: "data:image/png;base64,CCCC",
198
+ };
199
+
200
+ await generateConsentHistoryPdf(entry);
201
+
202
+ const doc = lastDoc();
203
+ const texts = textStrings(doc);
204
+ expect(texts).toContain("(Signature image could not be embedded)");
205
+ });
206
+
207
+ it("adds pages when content overflows the page height", async () => {
208
+ const manyLines = Array.from({length: 200}, (_v, i) => `Line ${i}`).join("\n");
209
+ const entry: ConsentHistoryEntry = {
210
+ ...baseEntry,
211
+ contentSnapshot: manyLines,
212
+ };
213
+
214
+ await generateConsentHistoryPdf(entry);
215
+
216
+ const doc = lastDoc();
217
+ expect(wasCalled(doc, "addPage")).toBe(true);
218
+ });
219
+
220
+ it("uses the audit-trail form version when the form has no version", async () => {
221
+ const entry: ConsentHistoryEntry = {
222
+ _id: "id-2",
223
+ agreed: true,
224
+ agreedAt: "2024-01-15T10:30:00.000Z",
225
+ form: null,
226
+ formVersionSnapshot: 7,
227
+ };
228
+
229
+ await generateConsentHistoryPdf(entry);
230
+
231
+ const doc = lastDoc();
232
+ const texts = textStrings(doc);
233
+ // formVersion resolves from formVersionSnapshot in Response Details...
234
+ expect(texts).toContain("Audit Trail");
235
+ // ...and the snapshot version shows up as a value.
236
+ expect(texts.some((t) => t === "7")).toBe(true);
237
+ });
238
+
239
+ it("renders raw invalid dates and skips empty dates via formatDate", async () => {
240
+ const entry: ConsentHistoryEntry = {
241
+ ...baseEntry,
242
+ agreedAt: "not-a-real-date",
243
+ signedAt: "",
244
+ };
245
+
246
+ await generateConsentHistoryPdf(entry);
247
+
248
+ const doc = lastDoc();
249
+ const texts = textStrings(doc);
250
+ // Invalid date string is passed through unchanged.
251
+ expect(texts).toContain("not-a-real-date");
252
+ });
253
+ });
package/src/index.tsx CHANGED
@@ -28,6 +28,7 @@ export * from "./DateUtilities";
28
28
  export * from "./DecimalRangeActionSheet";
29
29
  export * from "./DismissButton";
30
30
  export {DraggableList} from "./DraggableList";
31
+ export * from "./EditableCard";
31
32
  export * from "./EmailField";
32
33
  export {default as EmojiSelector} from "./EmojiSelector";
33
34
  export * from "./ErrorBoundary";
@@ -104,6 +105,7 @@ export * from "./Text";
104
105
  export * from "./TextArea";
105
106
  export * from "./TextField";
106
107
  export * from "./Theme";
108
+ export * from "./ThumbsUpDownFeedback";
107
109
  export * from "./Toast";
108
110
  export {Tooltip} from "./Tooltip";
109
111
  export * from "./TypedSignatureField";