@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
@@ -1,9 +1,9 @@
1
1
  // noExplicitAny: test mock typing
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
- import {afterAll, afterEach, beforeAll, describe, expect, it, mock} from "bun:test";
3
+ import {afterAll, afterEach, beforeAll, describe, expect, it, type Mock, mock} from "bun:test";
4
4
  import {act, render} from "@testing-library/react-native";
5
- import {createRef} from "react";
6
- import {Text} from "react-native";
5
+ import {createRef, type RefObject} from "react";
6
+ import {Animated, Dimensions, type KeyboardEvent, Text} from "react-native";
7
7
 
8
8
  import {
9
9
  ActionSheet,
@@ -614,6 +614,44 @@ describe("ActionSheet", () => {
614
614
  });
615
615
 
616
616
  describe("_onKeyboardShow", () => {
617
+ const timing = (Animated as unknown as {timing: Mock<(...args: never[]) => unknown>}).timing;
618
+
619
+ /**
620
+ * Focuses a field at `pageY` with a 40pt height and measures it synchronously, mirroring
621
+ * how UIManager.measure calls back on a real device.
622
+ */
623
+ const withFocusedField = (pageY: number, run: () => void): void => {
624
+ const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
625
+ const origState = MockTextInput.State;
626
+ const origMeasure = MockUIManager.measure;
627
+ MockTextInput.State = {currentlyFocusedField: () => 42};
628
+ MockUIManager.measure = (
629
+ _node: number,
630
+ callback: (
631
+ originX: number,
632
+ originY: number,
633
+ width: number,
634
+ height: number,
635
+ pageX: number,
636
+ pageY: number
637
+ ) => void
638
+ ): void => {
639
+ callback(0, 0, 100, 40, 0, pageY);
640
+ };
641
+ try {
642
+ run();
643
+ } finally {
644
+ MockTextInput.State = origState;
645
+ MockUIManager.measure = origMeasure;
646
+ }
647
+ };
648
+
649
+ const showKeyboard = (ref: RefObject<ActionSheet | null>, keyboardHeight: number): void => {
650
+ ref.current?._onKeyboardShow({
651
+ endCoordinates: {height: keyboardHeight, screenX: 0, screenY: 500, width: 400},
652
+ } as KeyboardEvent);
653
+ };
654
+
617
655
  it("sets keyboard state to true and handles no focused field", () => {
618
656
  const ref = createRef<ActionSheet>();
619
657
  render(
@@ -628,16 +666,16 @@ describe("ActionSheet", () => {
628
666
  MockTextInput.State = {
629
667
  currentlyFocusedField: () => null,
630
668
  };
669
+ const timingCallsBefore = timing.mock.calls.length;
631
670
  act(() => {
632
- (ref.current as any)._onKeyboardShow({
633
- endCoordinates: {height: 300, screenX: 0, screenY: 500, width: 400},
634
- });
671
+ showKeyboard(ref, 300);
635
672
  });
636
673
  expect(ref.current!.state.keyboard).toBe(true);
674
+ expect(timing.mock.calls.length).toBe(timingCallsBefore);
637
675
  MockTextInput.State = origState;
638
676
  });
639
677
 
640
- it("handles keyboard show with focused field", () => {
678
+ it("does not animate when the focused field stays above the keyboard", () => {
641
679
  const ref = createRef<ActionSheet>();
642
680
  render(
643
681
  <ThemeProvider>
@@ -646,26 +684,19 @@ describe("ActionSheet", () => {
646
684
  </ActionSheet>
647
685
  </ThemeProvider>
648
686
  );
649
- const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
650
- const origState = MockTextInput.State;
651
- const origMeasure = MockUIManager.measure;
652
- MockTextInput.State = {
653
- currentlyFocusedField: () => 42,
654
- };
655
- MockUIManager.measure = (_node: any, cb: any) => {
656
- cb(0, 0, 100, 40, 0, 400);
657
- };
658
- act(() => {
659
- (ref.current as any)._onKeyboardShow({
660
- endCoordinates: {height: 300, screenX: 0, screenY: 500, width: 400},
687
+ const timingCallsBefore = timing.mock.calls.length;
688
+ withFocusedField(400, () => {
689
+ act(() => {
690
+ showKeyboard(ref, 300);
661
691
  });
662
692
  });
663
693
  expect(ref.current!.state.keyboard).toBe(true);
664
- MockTextInput.State = origState;
665
- MockUIManager.measure = origMeasure;
694
+ // windowHeight (896) - keyboardHeight (300) - (pageY (400) + fieldHeight (40)) = 156 above
695
+ // the keyboard, so no animation is needed.
696
+ expect(timing.mock.calls.length).toBe(timingCallsBefore);
666
697
  });
667
698
 
668
- it("handles keyboard show with enough gap (no animation needed)", () => {
699
+ it("animates the sheet up by the overlap when the keyboard covers the focused field", () => {
669
700
  const ref = createRef<ActionSheet>();
670
701
  render(
671
702
  <ThemeProvider>
@@ -674,23 +705,35 @@ describe("ActionSheet", () => {
674
705
  </ActionSheet>
675
706
  </ThemeProvider>
676
707
  );
677
- const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
678
- const origState = MockTextInput.State;
679
- const origMeasure = MockUIManager.measure;
680
- MockTextInput.State = {
681
- currentlyFocusedField: () => 42,
682
- };
683
- MockUIManager.measure = (_node: any, cb: any) => {
684
- cb(0, 0, 100, 40, 0, 100);
685
- };
686
- act(() => {
687
- (ref.current as any)._onKeyboardShow({
688
- endCoordinates: {height: 100, screenX: 0, screenY: 500, width: 400},
708
+ const timingCallsBefore = timing.mock.calls.length;
709
+ withFocusedField(800, () => {
710
+ act(() => {
711
+ showKeyboard(ref, 300);
689
712
  });
690
713
  });
691
- expect(ref.current!.state.keyboard).toBe(true);
692
- MockTextInput.State = origState;
693
- MockUIManager.measure = origMeasure;
714
+ const {height: windowHeight} = Dimensions.get("window");
715
+ const gap = windowHeight - 300 - (800 + 40);
716
+ expect(timing.mock.calls.length).toBe(timingCallsBefore + 1);
717
+ expect(timing.mock.calls[timingCallsBefore][1].toValue).toBe(gap - 10);
718
+ });
719
+
720
+ it("shifts by the keyboard height instead of the overlap in position keyboard mode", () => {
721
+ const ref = createRef<ActionSheet>();
722
+ render(
723
+ <ThemeProvider>
724
+ <ActionSheet keyboardMode="position" ref={ref}>
725
+ <Text>Content</Text>
726
+ </ActionSheet>
727
+ </ThemeProvider>
728
+ );
729
+ const timingCallsBefore = timing.mock.calls.length;
730
+ withFocusedField(800, () => {
731
+ act(() => {
732
+ showKeyboard(ref, 300);
733
+ });
734
+ });
735
+ expect(timing.mock.calls.length).toBe(timingCallsBefore + 1);
736
+ expect(timing.mock.calls[timingCallsBefore][1].toValue).toBe(-(300 + 15));
694
737
  });
695
738
  });
696
739
 
@@ -458,8 +458,8 @@ describe("AiSuggestionBox in TextArea", () => {
458
458
  );
459
459
 
460
460
  expect(getByTestId("notes-ai-suggestion")).toBeTruthy();
461
- expect(getByTestId("notes-ai-suggestion-thumbs-up")).toBeTruthy();
462
- expect(getByTestId("notes-ai-suggestion-thumbs-down")).toBeTruthy();
461
+ expect(getByTestId("notes-ai-suggestion-feedback-positive")).toBeTruthy();
462
+ expect(getByTestId("notes-ai-suggestion-feedback-negative")).toBeTruthy();
463
463
  expect(getByTestId("notes-ai-suggestion-hide")).toBeTruthy();
464
464
  expect(getByTestId("notes-ai-suggestion-add")).toBeTruthy();
465
465
  });
@@ -1,12 +1,12 @@
1
1
  import {type FC, useCallback, useEffect, useState} from "react";
2
- import {Pressable, View} from "react-native";
2
+ import {View} from "react-native";
3
3
 
4
4
  import {Button} from "./Button";
5
- import type {AiSuggestionProps} from "./Common";
6
- import {Icon} from "./Icon";
5
+ import type {AiSuggestionProps, ThumbsUpDownFeedbackValue} from "./Common";
7
6
  import {SparklesIcon} from "./icons/SparklesIcon";
8
7
  import {Text} from "./Text";
9
8
  import {useTheme} from "./Theme";
9
+ import {ThumbsUpDownFeedback} from "./ThumbsUpDownFeedback";
10
10
 
11
11
  export interface AiSuggestionBoxProps extends AiSuggestionProps {
12
12
  testID?: string;
@@ -111,54 +111,23 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
111
111
  }
112
112
  }, [status, onShow]);
113
113
 
114
- const handleThumbsUp = useCallback(() => {
115
- if (!onFeedback) {
116
- return;
117
- }
118
- onFeedback(feedback === "like" ? null : "like");
119
- }, [onFeedback, feedback]);
120
-
121
- const handleThumbsDown = useCallback(() => {
122
- if (!onFeedback) {
123
- return;
124
- }
125
- onFeedback(feedback === "dislike" ? null : "dislike");
126
- }, [onFeedback, feedback]);
114
+ const handleFeedbackChange = useCallback(
115
+ (nextValue?: ThumbsUpDownFeedbackValue) => {
116
+ if (!onFeedback) {
117
+ return;
118
+ }
119
+ // ThumbsUpDownFeedback already clears a repeated selection, so undefined means "no feedback".
120
+ onFeedback(nextValue === undefined ? null : nextValue === "positive" ? "like" : "dislike");
121
+ },
122
+ [onFeedback]
123
+ );
127
124
 
128
125
  const renderFeedback = () => (
129
- <View
130
- style={{alignItems: "center", flexDirection: "row"}}
126
+ <ThumbsUpDownFeedback
127
+ onChange={handleFeedbackChange}
131
128
  testID={testID ? `${testID}-feedback` : undefined}
132
- >
133
- <Pressable
134
- accessibilityLabel="Thumbs up"
135
- accessibilityRole="button"
136
- onPress={handleThumbsUp}
137
- style={{alignItems: "center", height: 24, justifyContent: "center", width: 24}}
138
- testID={testID ? `${testID}-thumbs-up` : undefined}
139
- >
140
- <Icon
141
- color={feedback === "like" ? "secondaryDark" : "secondaryLight"}
142
- iconName="thumbs-up"
143
- size="md"
144
- type={feedback === "like" ? "solid" : "regular"}
145
- />
146
- </Pressable>
147
- <Pressable
148
- accessibilityLabel="Thumbs down"
149
- accessibilityRole="button"
150
- onPress={handleThumbsDown}
151
- style={{alignItems: "center", height: 24, justifyContent: "center", width: 24}}
152
- testID={testID ? `${testID}-thumbs-down` : undefined}
153
- >
154
- <Icon
155
- color={feedback === "dislike" ? "secondaryDark" : "secondaryLight"}
156
- iconName="thumbs-down"
157
- size="md"
158
- type={feedback === "dislike" ? "solid" : "regular"}
159
- />
160
- </Pressable>
161
- </View>
129
+ value={feedback === "like" ? "positive" : feedback === "dislike" ? "negative" : undefined}
130
+ />
162
131
  );
163
132
 
164
133
  if (status === "not-started" || status === "generating") {
package/src/Common.ts CHANGED
@@ -219,6 +219,7 @@ export interface TextThemeConfig {
219
219
  export interface SurfaceThemeConfig {
220
220
  base: keyof ThemePrimitiveColors;
221
221
  primary: keyof ThemePrimitiveColors;
222
+ secondaryExtraLight: keyof ThemePrimitiveColors;
222
223
  secondaryLight: keyof ThemePrimitiveColors;
223
224
  secondaryDark: keyof ThemePrimitiveColors;
224
225
  secondaryExtraDark: keyof ThemePrimitiveColors;
@@ -287,6 +288,7 @@ export interface TextTheme {
287
288
  export interface SurfaceTheme {
288
289
  base: string;
289
290
  primary: string;
291
+ secondaryExtraLight: string;
290
292
  secondaryLight: string;
291
293
  secondaryDark: string;
292
294
  secondaryExtraDark: string;
@@ -685,6 +687,51 @@ export type CardProps = BoxProps & {
685
687
  imageHeight?: number;
686
688
  };
687
689
 
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
+
688
735
  export interface ErrorBoundaryProps {
689
736
  onError?: (error: Error, stack: string) => void;
690
737
  children?: ReactNode;
@@ -1521,6 +1568,34 @@ export interface BadgeProps extends WithTestID {
1521
1568
  variant?: "iconOnly" | "numberOnly";
1522
1569
  }
1523
1570
 
1571
+ export type ThumbsUpDownFeedbackValue = "positive" | "negative";
1572
+
1573
+ export interface ThumbsUpDownFeedbackProps extends WithTestID {
1574
+ /**
1575
+ * If true, both options are non-interactive and rendered in a muted color.
1576
+ * @default false
1577
+ */
1578
+ disabled?: boolean;
1579
+ /**
1580
+ * Accessibility label for the negative (thumbs down) option.
1581
+ * @default "Thumbs down"
1582
+ */
1583
+ negativeAccessibilityLabel?: string;
1584
+ /**
1585
+ * Called with the newly selected value, or undefined when the current value is deselected.
1586
+ */
1587
+ onChange: (value?: ThumbsUpDownFeedbackValue) => void | Promise<void>;
1588
+ /**
1589
+ * Accessibility label for the positive (thumbs up) option.
1590
+ * @default "Thumbs up"
1591
+ */
1592
+ positiveAccessibilityLabel?: string;
1593
+ /**
1594
+ * The currently selected feedback. Leave undefined for no selection.
1595
+ */
1596
+ value?: ThumbsUpDownFeedbackValue;
1597
+ }
1598
+
1524
1599
  export interface SelectBadgeProps {
1525
1600
  /**
1526
1601
  * When status is "custom", determines the badge's background color.
@@ -0,0 +1,224 @@
1
+ import {afterAll, describe, expect, it, mock} from "bun:test";
2
+ import {act, fireEvent, waitFor} from "@testing-library/react-native";
3
+ import {Pressable} from "react-native";
4
+
5
+ // The download control is an IconButton wrapped in a Tooltip, which does not
6
+ // render its trigger in the test renderer. Mock it to a plain pressable that
7
+ // forwards onClick and testID, matching the InfoTooltipButton test pattern.
8
+ mock.module("./IconButton", () => ({
9
+ IconButton: ({
10
+ onClick,
11
+ testID,
12
+ loading,
13
+ }: {
14
+ onClick?: () => void;
15
+ testID?: string;
16
+ loading?: boolean;
17
+ }) => <Pressable disabled={loading} onPress={onClick} testID={testID} />,
18
+ }));
19
+
20
+ // Stub jsPDF so exercising the download handler does not write a PDF file to
21
+ // disk. Methods are no-ops; splitTextToSize returns an empty line set.
22
+ class StubJsPdf {
23
+ setFontSize(): void {}
24
+ setFont(): void {}
25
+ setDrawColor(): void {}
26
+ setTextColor(): void {}
27
+ text(): void {}
28
+ line(): void {}
29
+ addPage(): void {}
30
+ addImage(): void {}
31
+ splitTextToSize(): string[] {
32
+ return [];
33
+ }
34
+ save(): void {}
35
+ }
36
+
37
+ mock.module("jspdf", () => ({jsPDF: StubJsPdf}));
38
+
39
+ afterAll(() => {
40
+ mock.module("./IconButton", () => ({IconButton: mock(() => null)}));
41
+ });
42
+
43
+ import {ConsentHistory} from "./ConsentHistory";
44
+ import {renderWithTheme} from "./test-utils";
45
+ import type {ConsentHistoryEntry} from "./useConsentHistory";
46
+
47
+ type ConsentHistoryApi = Parameters<typeof ConsentHistory>[0]["api"];
48
+
49
+ const makeEntry = (overrides: Partial<ConsentHistoryEntry> = {}): ConsentHistoryEntry => ({
50
+ _id: "entry-1",
51
+ agreed: true,
52
+ agreedAt: "2026-01-02T03:04:05.000Z",
53
+ form: {
54
+ captureSignature: true,
55
+ checkboxes: [{label: "I have read the terms", required: true}],
56
+ slug: "tos",
57
+ title: "Terms of Service",
58
+ type: "terms",
59
+ version: 3,
60
+ },
61
+ ...overrides,
62
+ });
63
+
64
+ const createApi = (state: {
65
+ data?: unknown;
66
+ error?: unknown;
67
+ isLoading?: boolean;
68
+ refetch?: () => void;
69
+ }): ConsentHistoryApi => {
70
+ const api = {
71
+ enhanceEndpoints: () => ({
72
+ injectEndpoints: () => ({
73
+ useGetMyConsentsQuery: () => ({
74
+ data: state.data,
75
+ error: state.error,
76
+ isLoading: state.isLoading ?? false,
77
+ refetch: state.refetch ?? (() => {}),
78
+ }),
79
+ }),
80
+ }),
81
+ };
82
+ return api as unknown as ConsentHistoryApi;
83
+ };
84
+
85
+ describe("ConsentHistory", () => {
86
+ it("renders a spinner while loading", () => {
87
+ const {queryByTestId} = renderWithTheme(
88
+ <ConsentHistory api={createApi({isLoading: true})} title="History" />
89
+ );
90
+ expect(queryByTestId("consent-history-list")).toBeNull();
91
+ });
92
+
93
+ it("renders an error state with a retry button", async () => {
94
+ const refetch = mock(() => {});
95
+ const {getByText} = renderWithTheme(
96
+ <ConsentHistory api={createApi({error: new Error("boom"), refetch})} />
97
+ );
98
+ expect(getByText("Failed to load consent history")).toBeTruthy();
99
+
100
+ await act(async () => {
101
+ fireEvent.press(getByText("Retry"));
102
+ // Button debounces presses.
103
+ await new Promise((resolve) => setTimeout(resolve, 100));
104
+ });
105
+
106
+ await waitFor(() => {
107
+ expect(refetch).toHaveBeenCalled();
108
+ });
109
+ });
110
+
111
+ it("renders an empty state when there are no entries", () => {
112
+ const {getByText} = renderWithTheme(<ConsentHistory api={createApi({data: []})} />);
113
+ expect(getByText("No consent records found.")).toBeTruthy();
114
+ });
115
+
116
+ it("renders each entry with its form title, type and agreed badge", () => {
117
+ const {getByTestId, getByText} = renderWithTheme(
118
+ <ConsentHistory api={createApi({data: [makeEntry()]})} />
119
+ );
120
+ expect(getByTestId("consent-history-list")).toBeTruthy();
121
+ expect(getByText("Terms of Service")).toBeTruthy();
122
+ expect(getByText("terms")).toBeTruthy();
123
+ expect(getByText("Agreed")).toBeTruthy();
124
+ });
125
+
126
+ it("falls back to placeholder text when the form is missing and shows declined entries", () => {
127
+ const {getByText} = renderWithTheme(
128
+ <ConsentHistory api={createApi({data: [makeEntry({agreed: false, form: null})]})} />
129
+ );
130
+ expect(getByText("Unknown Form")).toBeTruthy();
131
+ expect(getByText("Declined")).toBeTruthy();
132
+ });
133
+
134
+ it("expands and collapses the entry details when pressed", () => {
135
+ const {getByTestId, queryByTestId} = renderWithTheme(
136
+ <ConsentHistory api={createApi({data: [makeEntry()]})} />
137
+ );
138
+ expect(queryByTestId("consent-history-item-details-entry-1")).toBeNull();
139
+ fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
140
+ expect(getByTestId("consent-history-item-details-entry-1")).toBeTruthy();
141
+ fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
142
+ expect(queryByTestId("consent-history-item-details-entry-1")).toBeNull();
143
+ });
144
+
145
+ it("shows every optional detail when expanded", () => {
146
+ const entry = makeEntry({
147
+ checkboxValues: {"0": true, "1": false},
148
+ contentSnapshot: "# Snapshot",
149
+ ipAddress: "10.0.0.1",
150
+ locale: "en-US",
151
+ signature: "data:image/png;base64,abc",
152
+ signedAt: "2026-01-02T03:05:00.000Z",
153
+ });
154
+ const {getByTestId, getByText} = renderWithTheme(
155
+ <ConsentHistory api={createApi({data: [entry]})} />
156
+ );
157
+ fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
158
+
159
+ expect(getByText("Version:")).toBeTruthy();
160
+ expect(getByText("3")).toBeTruthy();
161
+ expect(getByText("Locale:")).toBeTruthy();
162
+ expect(getByText("en-US")).toBeTruthy();
163
+ expect(getByText("Signed:")).toBeTruthy();
164
+ expect(getByText("IP Address:")).toBeTruthy();
165
+ expect(getByText("10.0.0.1")).toBeTruthy();
166
+ expect(getByText("Checkboxes")).toBeTruthy();
167
+ // Labelled from the form for index 0, generic fallback for index 1.
168
+ expect(getByText("I have read the terms")).toBeTruthy();
169
+ expect(getByText("Checkbox 1")).toBeTruthy();
170
+ expect(getByText("Yes")).toBeTruthy();
171
+ expect(getByText("No")).toBeTruthy();
172
+ expect(getByTestId("consent-history-signature-entry-1")).toBeTruthy();
173
+ expect(getByText("Form Content")).toBeTruthy();
174
+ });
175
+
176
+ it("renders raw date values that cannot be parsed and skips empty ones", () => {
177
+ const {getByTestId, getByText, queryByText} = renderWithTheme(
178
+ <ConsentHistory
179
+ api={createApi({data: [makeEntry({agreedAt: "not-a-date", signedAt: undefined})]})}
180
+ />
181
+ );
182
+ expect(getByText("not-a-date")).toBeTruthy();
183
+ fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
184
+ expect(queryByText("Signed:")).toBeNull();
185
+ });
186
+
187
+ it("renders nothing for a blank date", () => {
188
+ const {getByTestId} = renderWithTheme(
189
+ <ConsentHistory api={createApi({data: [makeEntry({agreedAt: ""})]})} />
190
+ );
191
+ expect(getByTestId("consent-history-item-entry-1")).toBeTruthy();
192
+ });
193
+
194
+ it("unwraps a paginated response body", () => {
195
+ const {getByTestId} = renderWithTheme(
196
+ <ConsentHistory api={createApi({data: {data: [makeEntry()]}})} />
197
+ );
198
+ expect(getByTestId("consent-history-item-entry-1")).toBeTruthy();
199
+ });
200
+
201
+ it("invokes PDF generation and resets the loading state after a download", async () => {
202
+ const originalError = console.error;
203
+ console.error = mock(() => {}) as unknown as typeof console.error;
204
+ try {
205
+ const {getByTestId} = renderWithTheme(
206
+ <ConsentHistory api={createApi({data: [makeEntry()]})} />
207
+ );
208
+ fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
209
+
210
+ await act(async () => {
211
+ fireEvent.press(getByTestId("consent-history-download-entry-1"));
212
+ });
213
+
214
+ // The button remains mounted after the async handler settles (loading
215
+ // state was toggled back off), regardless of whether PDF generation
216
+ // succeeded or threw in the headless test environment.
217
+ await waitFor(() => {
218
+ expect(getByTestId("consent-history-download-entry-1")).toBeTruthy();
219
+ });
220
+ } finally {
221
+ console.error = originalError;
222
+ }
223
+ });
224
+ });
@@ -1,5 +1,3 @@
1
- // noExplicitAny: test mock typing
2
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
1
  import {describe, expect, it, mock} from "bun:test";
4
2
  import React from "react";
5
3
  import {Pressable} from "react-native";
@@ -186,7 +184,7 @@ describe("ConsentNavigator", () => {
186
184
  };
187
185
 
188
186
  const {getByText} = renderWithTheme(
189
- <ConsentNavigator api={api as any}>
187
+ <ConsentNavigator api={api}>
190
188
  <Text>App Content</Text>
191
189
  </ConsentNavigator>
192
190
  );
@@ -212,7 +210,7 @@ describe("ConsentNavigator", () => {
212
210
  };
213
211
 
214
212
  const {getByText} = renderWithTheme(
215
- <ConsentNavigator api={api as any}>
213
+ <ConsentNavigator api={api}>
216
214
  <Text>App Content</Text>
217
215
  </ConsentNavigator>
218
216
  );
@@ -239,7 +237,7 @@ describe("ConsentNavigator", () => {
239
237
  };
240
238
 
241
239
  const {getByTestId, getByText} = renderWithTheme(
242
- <ConsentNavigator api={api as any} onError={onError}>
240
+ <ConsentNavigator api={api} onError={onError}>
243
241
  <Text>App Content</Text>
244
242
  </ConsentNavigator>
245
243
  );
@@ -284,7 +282,7 @@ describe("ConsentNavigator", () => {
284
282
  };
285
283
 
286
284
  const {getByTestId} = renderWithTheme(
287
- <ConsentNavigator api={api as any}>
285
+ <ConsentNavigator api={api}>
288
286
  <Text>App Content</Text>
289
287
  </ConsentNavigator>
290
288
  );
@@ -321,7 +319,7 @@ describe("ConsentNavigator", () => {
321
319
  };
322
320
 
323
321
  const {getByTestId} = renderWithTheme(
324
- <ConsentNavigator api={api as any} onError={onError}>
322
+ <ConsentNavigator api={api} onError={onError}>
325
323
  <Text>App Content</Text>
326
324
  </ConsentNavigator>
327
325
  );
@@ -361,7 +359,7 @@ describe("ConsentNavigator", () => {
361
359
  };
362
360
 
363
361
  const {getByTestId} = renderWithTheme(
364
- <ConsentNavigator api={api as any}>
362
+ <ConsentNavigator api={api}>
365
363
  <Text>App Content</Text>
366
364
  </ConsentNavigator>
367
365
  );