@marktiderman/genesis-ui-native 3.7.0 → 3.8.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 (87) hide show
  1. package/README.md +4 -1
  2. package/dist/{chunk-KH2RVAI5.js → chunk-DHONOH6K.js} +24 -210
  3. package/dist/chunk-DHONOH6K.js.map +1 -0
  4. package/dist/{chunk-O4BMDV7I.js → chunk-FGIIBON3.js} +333 -21
  5. package/dist/chunk-FGIIBON3.js.map +1 -0
  6. package/dist/{chunk-YWDDDYDI.js → chunk-FOJJB6AB.js} +2 -2
  7. package/dist/{chunk-YWDDDYDI.js.map → chunk-FOJJB6AB.js.map} +1 -1
  8. package/dist/{chunk-IXC3LO2K.js → chunk-JZ7RAGDQ.js} +44 -36
  9. package/dist/chunk-JZ7RAGDQ.js.map +1 -0
  10. package/dist/{chunk-RTYO24SC.js → chunk-PWS2HLDE.js} +63 -31
  11. package/dist/chunk-PWS2HLDE.js.map +1 -0
  12. package/dist/{chunk-3KFUS7O6.js → chunk-PWYMRUAK.js} +43 -30
  13. package/dist/chunk-PWYMRUAK.js.map +1 -0
  14. package/dist/{chunk-GBNIBHSU.js → chunk-T7FEVT62.js} +53 -12
  15. package/dist/chunk-T7FEVT62.js.map +1 -0
  16. package/dist/{chunk-7NDKIIOT.js → chunk-UZCJDMGE.js} +353 -19
  17. package/dist/chunk-UZCJDMGE.js.map +1 -0
  18. package/dist/components/index.d.ts +229 -23
  19. package/dist/components/index.js +5 -6
  20. package/dist/data/index.d.ts +2 -1
  21. package/dist/data/index.js +7 -12
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/hooks/index.d.ts +7 -3
  24. package/dist/hooks/index.js +2 -3
  25. package/dist/icons/lucide.d.ts +1 -1
  26. package/dist/icons/lucide.js +13 -3
  27. package/dist/icons/lucide.js.map +1 -1
  28. package/dist/{inbox-page-B7_Oi2fS.d.ts → inbox-page-BGqR_cBs.d.ts} +4 -1
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +8 -9
  31. package/dist/layouts/index.d.ts +12 -3
  32. package/dist/layouts/index.js +5 -6
  33. package/dist/{native-modules-DEJJQhDx.d.ts → native-modules-CeAaO2Dh.d.ts} +26 -2
  34. package/package.json +49 -1
  35. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  36. package/src/components/__tests__/bulk-bar.test.tsx +36 -0
  37. package/src/components/__tests__/button-haptic.test.tsx +22 -0
  38. package/src/components/__tests__/composer-bar.test.tsx +116 -1
  39. package/src/components/__tests__/gallery-grid.test.tsx +2 -2
  40. package/src/components/__tests__/library-round-5.test.tsx +121 -0
  41. package/src/components/__tests__/share-sheet.test.tsx +47 -0
  42. package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
  43. package/src/components/__tests__/tab-bar.test.tsx +43 -0
  44. package/src/components/__tests__/thread-list.test.tsx +137 -0
  45. package/src/components/__tests__/tier-badge.test.tsx +57 -0
  46. package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
  47. package/src/components/bulk-bar.tsx +91 -0
  48. package/src/components/button.tsx +74 -35
  49. package/src/components/choice-card.tsx +104 -0
  50. package/src/components/composer-bar.tsx +20 -19
  51. package/src/components/context-menu.tsx +101 -0
  52. package/src/components/gallery-grid.tsx +10 -4
  53. package/src/components/index.ts +18 -1
  54. package/src/components/inline-alert.tsx +36 -1
  55. package/src/components/input.tsx +3 -0
  56. package/src/components/progress.tsx +24 -2
  57. package/src/components/rating.tsx +35 -16
  58. package/src/components/share-sheet.tsx +127 -0
  59. package/src/components/sheet.tsx +9 -1
  60. package/src/components/swipe-row.tsx +74 -0
  61. package/src/components/tab-bar.tsx +133 -0
  62. package/src/components/tabs.tsx +2 -0
  63. package/src/components/text.tsx +3 -0
  64. package/src/components/textarea.tsx +3 -0
  65. package/src/components/thread-list.tsx +48 -23
  66. package/src/components/tier-badge.tsx +74 -0
  67. package/src/components/whats-new-sheet.tsx +89 -0
  68. package/src/data/resource-view/NativeRecordView.tsx +3 -8
  69. package/src/data/resource-view/use-native-resource-view.ts +2 -2
  70. package/src/hooks/index.ts +1 -1
  71. package/src/hooks/use-theme-roles.ts +3 -0
  72. package/src/icon-names.ts +12 -2
  73. package/src/icons/lucide.ts +27 -7
  74. package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
  75. package/src/layouts/__tests__/thread-page.test.tsx +89 -2
  76. package/src/layouts/inbox-page.tsx +28 -12
  77. package/src/layouts/thread-page.tsx +69 -8
  78. package/src/native-modules.tsx +16 -0
  79. package/dist/chunk-3KFUS7O6.js.map +0 -1
  80. package/dist/chunk-7NDKIIOT.js.map +0 -1
  81. package/dist/chunk-CAI7LGN6.js +0 -39
  82. package/dist/chunk-CAI7LGN6.js.map +0 -1
  83. package/dist/chunk-GBNIBHSU.js.map +0 -1
  84. package/dist/chunk-IXC3LO2K.js.map +0 -1
  85. package/dist/chunk-KH2RVAI5.js.map +0 -1
  86. package/dist/chunk-O4BMDV7I.js.map +0 -1
  87. package/dist/chunk-RTYO24SC.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  // @feat:inbox-thread
2
- import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
3
3
  import { describe, expect, it, vi } from "vitest";
4
4
  import { GenesisModulesProvider } from "../../native-modules";
5
5
  import { NativeComposerBar } from "../composer-bar";
@@ -76,4 +76,119 @@ describe("NativeComposerBar", () => {
76
76
  render(<NativeComposerBar {...base} leading={<i data-testid="attach" />} trailing={<i data-testid="mic" />} above={<i data-testid="reply-to" />} testID="c" />);
77
77
  for (const id of ["attach", "mic", "reply-to"]) expect(screen.getByTestId(id)).toBeTruthy();
78
78
  });
79
+
80
+ describe("hasContent", () => {
81
+ it("sends with no text when it's true (attachments waiting)", () => {
82
+ const onSend = vi.fn();
83
+ render(<NativeComposerBar {...base} onSend={onSend} value="" hasContent testID="c" />);
84
+ fireEvent.click(screen.getByTestId("c-send"));
85
+ expect(onSend).toHaveBeenCalledTimes(1);
86
+ });
87
+
88
+ it("won't send written text when it's false", () => {
89
+ const onSend = vi.fn();
90
+ render(<NativeComposerBar {...base} onSend={onSend} value="Hi" hasContent={false} testID="c" />);
91
+ expect(screen.getByTestId("c-send").getAttribute("aria-disabled")).toBe("true");
92
+ fireEvent.click(screen.getByTestId("c-send"));
93
+ expect(onSend).not.toHaveBeenCalled();
94
+ });
95
+ });
96
+
97
+ describe("idleAction", () => {
98
+ const mic = <i data-testid="mic" />;
99
+
100
+ it("takes Send's place while there's nothing to send, and gives it back", () => {
101
+ const { rerender } = render(<NativeComposerBar {...base} value="" idleAction={mic} testID="c" />);
102
+ expect(screen.getByTestId("c-idle").contains(screen.getByTestId("mic"))).toBe(true);
103
+ expect(screen.queryByTestId("c-send")).toBeNull();
104
+ rerender(<NativeComposerBar {...base} value="Hi" idleAction={mic} testID="c" />);
105
+ expect(screen.queryByTestId("mic")).toBeNull();
106
+ expect(screen.getByTestId("c-send")).toBeTruthy();
107
+ });
108
+
109
+ it("follows hasContent, not the text", () => {
110
+ const { rerender } = render(<NativeComposerBar {...base} value="" hasContent idleAction={mic} testID="c" />);
111
+ expect(screen.queryByTestId("mic")).toBeNull();
112
+ rerender(<NativeComposerBar {...base} value="Hi" hasContent={false} idleAction={mic} testID="c" />);
113
+ expect(screen.getByTestId("mic")).toBeTruthy();
114
+ });
115
+
116
+ it("gives way to the spinner while sending", () => {
117
+ render(<NativeComposerBar {...base} value="" sending idleAction={mic} testID="c" />);
118
+ expect(screen.queryByTestId("mic")).toBeNull();
119
+ expect(screen.getByTestId("c-sending")).toBeTruthy();
120
+ });
121
+
122
+ it("stays the same view when a recording replaces the input (a held touch keeps its responder)", () => {
123
+ const { rerender } = render(<NativeComposerBar {...base} value="" hasContent={false} idleAction={mic} testID="c" />);
124
+ const before = screen.getByTestId("mic");
125
+ rerender(<NativeComposerBar {...base} value="" hasContent={false} idleAction={mic} replaceInput={<i data-testid="wave" />} testID="c" />);
126
+ expect(screen.getByTestId("mic")).toBe(before);
127
+ });
128
+ });
129
+
130
+ describe("replaceInput", () => {
131
+ it("replaces leading and the input, and leaves trailing to the caller", () => {
132
+ render(<NativeComposerBar {...base} leading={<i data-testid="attach" />} trailing={<i data-testid="emoji" />} replaceInput={<i data-testid="wave" />} testID="c" />);
133
+ expect(screen.getByTestId("wave")).toBeTruthy();
134
+ expect(screen.queryByTestId("attach")).toBeNull();
135
+ expect(screen.queryByTestId("c-input")).toBeNull();
136
+ expect(screen.getByTestId("emoji")).toBeTruthy();
137
+ });
138
+ });
139
+
140
+ describe("sendActions", () => {
141
+ const later = { id: "later", label: "Send later", onPress: vi.fn() };
142
+ const silent = { id: "silent", label: "Send silently", onPress: vi.fn() };
143
+
144
+ it("has no accessibility actions without any", () => {
145
+ render(<NativeComposerBar {...base} value="Hi" testID="c" />);
146
+ expect(screen.getByTestId("c-send").getAttribute("data-a11y-actions")).toBeNull();
147
+ });
148
+
149
+ it("runs a single action straight away on touch and hold", () => {
150
+ const onPress = vi.fn();
151
+ render(<NativeComposerBar {...base} value="Hi" sendActions={[{ ...later, onPress }]} testID="c" />);
152
+ fireEvent.contextMenu(screen.getByTestId("c-send"));
153
+ expect(onPress).toHaveBeenCalledTimes(1);
154
+ expect(screen.queryByTestId("c-send-menu")).toBeNull();
155
+ });
156
+
157
+ it("opens a menu with a Cancel for several", async () => {
158
+ const onPress = vi.fn();
159
+ render(<NativeComposerBar {...base} value="Hi" sendActions={[later, { ...silent, onPress }]} sendActionsTitle="Send" testID="c" />);
160
+ fireEvent.contextMenu(screen.getByTestId("c-send"));
161
+ await act(async () => {});
162
+ expect(screen.getByTestId("c-send-menu-title").textContent).toBe("Send");
163
+ expect(screen.getByTestId("c-send-menu-action-later").textContent).toBe("Send later");
164
+ expect(screen.getByTestId("c-send-menu-cancel")).toBeTruthy();
165
+ fireEvent.click(screen.getByTestId("c-send-menu-action-silent"));
166
+ await waitFor(() => expect(onPress).toHaveBeenCalledTimes(1));
167
+ });
168
+
169
+ it("offers each as an accessibility action on Send, only while it can send", () => {
170
+ const { rerender } = render(<NativeComposerBar {...base} value="Hi" sendActions={[later, silent]} testID="c" />);
171
+ expect(screen.getByTestId("c-send").getAttribute("data-a11y-actions")).toBe("later,silent");
172
+ rerender(<NativeComposerBar {...base} value="" sendActions={[later, silent]} testID="c" />);
173
+ expect(screen.getByTestId("c-send").getAttribute("data-a11y-actions")).toBeNull();
174
+ });
175
+ });
176
+
177
+ describe("editable", () => {
178
+ it("when false, nothing sends and the input reads as disabled", () => {
179
+ const onSend = vi.fn();
180
+ render(<NativeComposerBar {...base} onSend={onSend} value="Hi" editable={false} testID="c" />);
181
+ expect(screen.getByTestId("c-input").hasAttribute("disabled")).toBe(true);
182
+ expect(screen.getByTestId("c-send").getAttribute("aria-disabled")).toBe("true");
183
+ fireEvent.click(screen.getByTestId("c-send"));
184
+ expect(onSend).not.toHaveBeenCalled();
185
+ });
186
+ });
187
+
188
+ it("passes the selection through to onSelectionChange", () => {
189
+ const onSelectionChange = vi.fn();
190
+ render(<NativeComposerBar {...base} value="Hi" onSelectionChange={onSelectionChange} testID="c" />);
191
+ fireEvent.select(screen.getByTestId("c-input"));
192
+ expect(onSelectionChange).toHaveBeenCalled();
193
+ });
79
194
  });
@@ -22,9 +22,9 @@ function measure(el: HTMLElement, width: number) {
22
22
  }
23
23
 
24
24
  describe("NativeGalleryGrid", () => {
25
- it("draws nothing until the container is measured, then a tile per item", () => {
25
+ it("draws on the first paint (regression: an iOS large-title inset needs the list at mount), then a tile per item", () => {
26
26
  render(<NativeGalleryGrid items={items} testID="g" />);
27
- expect(screen.queryByTestId("g-item-p0")).toBeNull();
27
+ expect(screen.getByTestId("g-item-p0")).toBeTruthy();
28
28
  measure(screen.getByTestId("g"), 600);
29
29
  expect(screen.getAllByTestId(/^g-item-/)).toHaveLength(5);
30
30
  });
@@ -0,0 +1,121 @@
1
+ /** The round-5 additions: alert slots, progress colours, rating touch/tone, NativeChoiceCard. */
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { NativeBanner, NativeInlineAlert } from "../inline-alert";
5
+ import { NativeProgress } from "../progress";
6
+ import { NativeRating } from "../rating";
7
+ import { NativeChoiceCard } from "../choice-card";
8
+
9
+ const style = (el: HTMLElement) => JSON.parse(el.dataset.style ?? "{}") as Record<string, unknown>;
10
+
11
+ describe("NativeInlineAlert / NativeBanner slots", () => {
12
+ it("renders children and actions under the description", () => {
13
+ const onRetry = vi.fn();
14
+ render(
15
+ <NativeInlineAlert
16
+ testID="alert"
17
+ variant="destructive"
18
+ title="Fix 2 answers"
19
+ description="Before you send"
20
+ actions={<button onClick={onRetry}>Review</button>}
21
+ >
22
+ <span>Email</span>
23
+ </NativeInlineAlert>,
24
+ );
25
+ expect(screen.getByTestId("alert-content").textContent).toBe("Email");
26
+ fireEvent.click(screen.getByText("Review"));
27
+ expect(onRetry).toHaveBeenCalledTimes(1);
28
+ expect(screen.getByTestId("alert-actions")).toBeTruthy();
29
+ });
30
+
31
+ it("draws no slot wrappers when they are empty", () => {
32
+ render(<NativeBanner testID="banner" title="Offline" />);
33
+ expect(screen.queryByTestId("banner-content")).toBeNull();
34
+ expect(screen.queryByTestId("banner-actions")).toBeNull();
35
+ });
36
+
37
+ it("the banner takes the same slots", () => {
38
+ render(<NativeBanner testID="banner" title="Offline" actions={<span>Retry</span>} />);
39
+ expect(screen.getByTestId("banner-actions").textContent).toBe("Retry");
40
+ });
41
+ });
42
+
43
+ describe("NativeProgress colours", () => {
44
+ it("takes the fill and track as colour values", () => {
45
+ render(<NativeProgress testID="p" value={40} indicatorColor="red" trackColor="blue" />);
46
+ const track = screen.getByTestId("p");
47
+ expect(style(track).backgroundColor).toBe("blue");
48
+ const fill = track.firstElementChild as HTMLElement;
49
+ expect(style(fill)).toEqual({ width: "40%", backgroundColor: "red" });
50
+ });
51
+
52
+ it("leaves the classes alone without them", () => {
53
+ render(<NativeProgress testID="p" value={10} />);
54
+ const track = screen.getByTestId("p");
55
+ expect(track.dataset.style).toBeUndefined();
56
+ expect(style(track.firstElementChild as HTMLElement)).toEqual({ width: "10%" });
57
+ });
58
+ });
59
+
60
+ describe("NativeRating touch, tone, clearable, disabled", () => {
61
+ it("touch gives each star a 44pt target", () => {
62
+ render(<NativeRating value={2} onChange={() => undefined} size="touch" testID="r" />);
63
+ expect(screen.getByTestId("r-star-1").className).toContain("h-11 w-11");
64
+ });
65
+
66
+ it("clearable={false} keeps the chosen star when it is pressed again", () => {
67
+ const onChange = vi.fn();
68
+ render(<NativeRating value={3} onChange={onChange} clearable={false} testID="r" />);
69
+ fireEvent.click(screen.getByTestId("r-star-3"));
70
+ expect(onChange).not.toHaveBeenCalled();
71
+ fireEvent.click(screen.getByTestId("r-star-4"));
72
+ expect(onChange).toHaveBeenCalledWith(4);
73
+ });
74
+
75
+ it("disabled stars can't be pressed", () => {
76
+ const onChange = vi.fn();
77
+ render(<NativeRating value={1} onChange={onChange} disabled testID="r" />);
78
+ fireEvent.click(screen.getByTestId("r-star-4"));
79
+ expect(onChange).not.toHaveBeenCalled();
80
+ });
81
+
82
+ it("tone=primary still renders every star", () => {
83
+ render(<NativeRating value={2} tone="primary" testID="r" />);
84
+ expect(screen.getByTestId("r-star-5")).toBeTruthy();
85
+ });
86
+ });
87
+
88
+ describe("NativeChoiceCard", () => {
89
+ it("is one radio named by title and description", () => {
90
+ const onPress = vi.fn();
91
+ render(<NativeChoiceCard testID="c" title="Weekly" description="Every Monday" selected={false} onPress={onPress} />);
92
+ const card = screen.getByTestId("c");
93
+ expect(card.getAttribute("role")).toBe("radio");
94
+ expect(card.getAttribute("aria-label")).toBe("Weekly, Every Monday");
95
+ fireEvent.click(card);
96
+ expect(onPress).toHaveBeenCalledTimes(1);
97
+ });
98
+
99
+ it("is a checkbox with multiple, and shows the selected state", () => {
100
+ render(<NativeChoiceCard testID="c" title="Photos" selected multiple onPress={() => undefined} />);
101
+ const card = screen.getByTestId("c");
102
+ expect(card.getAttribute("role")).toBe("checkbox");
103
+ expect(card.className).toContain("border-primary");
104
+ expect(screen.getByTestId("c-indicator").textContent).toBe("✓");
105
+ });
106
+
107
+ it("renders media and marks an invalid answer", () => {
108
+ render(
109
+ <NativeChoiceCard testID="c" title="Red" selected={false} invalid media={<span>img</span>} onPress={() => undefined} />,
110
+ );
111
+ expect(screen.getByTestId("c-media").textContent).toBe("img");
112
+ expect(screen.getByTestId("c").className).toContain("border-destructive");
113
+ });
114
+
115
+ it("does not fire when disabled", () => {
116
+ const onPress = vi.fn();
117
+ render(<NativeChoiceCard testID="c" title="Red" selected={false} disabled onPress={onPress} />);
118
+ fireEvent.click(screen.getByTestId("c"));
119
+ expect(onPress).not.toHaveBeenCalled();
120
+ });
121
+ });
@@ -0,0 +1,47 @@
1
+ import { act, fireEvent, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import { Share, Text } from "react-native";
4
+ import { NativeShareSheet } from "../share-sheet";
5
+
6
+ afterEach(() => vi.restoreAllMocks());
7
+
8
+ describe("NativeShareSheet", () => {
9
+ it("says it is loading while the link is null", async () => {
10
+ render(<NativeShareSheet open onOpenChange={() => {}} url={null} />);
11
+ expect(await screen.findByTestId("native-share-sheet-loading")).toBeTruthy();
12
+ expect(screen.getByText("Share your page")).toBeTruthy();
13
+ });
14
+
15
+ it("shows the link, the host's QR code, and copies through onCopy", async () => {
16
+ const onCopy = vi.fn(async () => {});
17
+ render(
18
+ <NativeShareSheet
19
+ open
20
+ onOpenChange={() => {}}
21
+ noun="form"
22
+ url="https://acme.test/f/1"
23
+ renderQr={(url) => <Text testID="qr">{url}</Text>}
24
+ onCopy={onCopy}
25
+ />,
26
+ );
27
+ expect(await screen.findByText("Share your form")).toBeTruthy();
28
+ expect(screen.getByTestId("qr").textContent).toBe("https://acme.test/f/1");
29
+ await act(async () => {
30
+ fireEvent.click(screen.getByTestId("native-share-sheet-copy"));
31
+ });
32
+ expect(onCopy).toHaveBeenCalledWith("https://acme.test/f/1");
33
+ expect(screen.getByText("Copied")).toBeTruthy();
34
+ });
35
+
36
+ it("shares through the system sheet, which Copy also uses without onCopy", async () => {
37
+ const share = vi.spyOn(Share, "share").mockResolvedValue({ action: "sharedAction" } as never);
38
+ render(<NativeShareSheet open onOpenChange={() => {}} url="https://acme.test/p" name="Intake" />);
39
+ fireEvent.click(await screen.findByTestId("native-share-sheet-share"));
40
+ expect(screen.queryByTestId("native-share-sheet-qr")).toBeNull();
41
+ await act(async () => {
42
+ fireEvent.click(screen.getByTestId("native-share-sheet-copy"));
43
+ });
44
+ expect(share).toHaveBeenCalledTimes(2);
45
+ expect(share.mock.calls[0]![0]).toMatchObject({ url: "https://acme.test/p", title: "Intake" });
46
+ });
47
+ });
@@ -0,0 +1,215 @@
1
+ // @feat:inbox-thread
2
+ import { forwardRef, useImperativeHandle, useState, type ReactNode } from "react";
3
+ import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
4
+ import { Platform } from "react-native";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import { GenesisModulesProvider } from "../../native-modules";
7
+ import { NativeContextMenu } from "../context-menu";
8
+ import { NativeSheetProvider } from "../sheet";
9
+ import { NativeSwipeRow } from "../swipe-row";
10
+
11
+ const haptics = () => ({
12
+ impactAsync: vi.fn(() => Promise.resolve()),
13
+ selectionAsync: vi.fn(() => Promise.resolve()),
14
+ notificationAsync: vi.fn(() => Promise.resolve()),
15
+ ImpactFeedbackStyle: { Light: "light", Medium: "medium" },
16
+ NotificationFeedbackType: { Success: "s", Warning: "w", Error: "e" },
17
+ });
18
+
19
+ /** Draws both sides at once, as ReanimatedSwipeable has them behind the row. */
20
+ function fakeSwipeable(close: () => void) {
21
+ return forwardRef<unknown, Record<string, any>>(function Swipeable(props, ref) {
22
+ useImperativeHandle(ref, () => ({ close }));
23
+ return (
24
+ <div data-testid={props.testID} onClick={() => props.onSwipeableWillOpen?.()}>
25
+ <div data-testid="left">{props.renderLeftActions?.()}</div>
26
+ <div data-testid="right">{props.renderRightActions?.()}</div>
27
+ {props.children as ReactNode}
28
+ </div>
29
+ );
30
+ });
31
+ }
32
+
33
+ afterEach(() => vi.useRealTimers());
34
+
35
+ describe("NativeSwipeRow", () => {
36
+ const actions = [
37
+ { id: "pin", label: "Pin", onPress: vi.fn(), side: "leading" as const },
38
+ { id: "delete", label: "Delete", onPress: vi.fn(), destructive: true },
39
+ ];
40
+
41
+ it("draws only the row without the module", () => {
42
+ render(
43
+ <NativeSwipeRow actions={actions} testID="s">
44
+ <i data-testid="row" />
45
+ </NativeSwipeRow>,
46
+ );
47
+ expect(screen.getByTestId("row")).toBeTruthy();
48
+ expect(screen.queryByTestId("s")).toBeNull();
49
+ });
50
+
51
+ it("puts each action on its side, trailing by default", () => {
52
+ const Swipeable = fakeSwipeable(vi.fn());
53
+ render(
54
+ <GenesisModulesProvider modules={{ swipeable: Swipeable as never }}>
55
+ <NativeSwipeRow actions={actions} testID="s">
56
+ <i data-testid="row" />
57
+ </NativeSwipeRow>
58
+ </GenesisModulesProvider>,
59
+ );
60
+ expect(screen.getByTestId("left").contains(screen.getByTestId("s-action-pin"))).toBe(true);
61
+ expect(screen.getByTestId("right").contains(screen.getByTestId("s-action-delete"))).toBe(true);
62
+ });
63
+
64
+ it("closes, then runs the action", () => {
65
+ const close = vi.fn();
66
+ const onPress = vi.fn();
67
+ const Swipeable = fakeSwipeable(close);
68
+ render(
69
+ <GenesisModulesProvider modules={{ swipeable: Swipeable as never }}>
70
+ <NativeSwipeRow actions={[{ id: "a", label: "A", onPress }]} testID="s" />
71
+ </GenesisModulesProvider>,
72
+ );
73
+ fireEvent.click(screen.getByTestId("s-action-a"));
74
+ expect(close).toHaveBeenCalled();
75
+ expect(onPress).toHaveBeenCalledTimes(1);
76
+ });
77
+
78
+ it("taps medium when a swipe opens", () => {
79
+ const h = haptics();
80
+ const Swipeable = fakeSwipeable(vi.fn());
81
+ render(
82
+ <GenesisModulesProvider modules={{ swipeable: Swipeable as never, haptics: h as never }}>
83
+ <NativeSwipeRow actions={actions} testID="s" />
84
+ </GenesisModulesProvider>,
85
+ );
86
+ fireEvent.click(screen.getByTestId("s"));
87
+ expect(h.impactAsync).toHaveBeenCalledWith("medium");
88
+ });
89
+ });
90
+
91
+ describe("NativeContextMenu", () => {
92
+ const base = { open: true, onOpenChange: vi.fn(), testID: "m" };
93
+
94
+ it("lists its actions with a title and Cancel, and Cancel only closes", async () => {
95
+ const onPress = vi.fn();
96
+ const onOpenChange = vi.fn();
97
+ render(<NativeContextMenu {...base} onOpenChange={onOpenChange} title="Thread" actions={[{ id: "a", label: "Archive", onPress }]} />);
98
+ await act(async () => {});
99
+ expect(screen.getByTestId("m-title").textContent).toBe("Thread");
100
+ expect(screen.getByTestId("m-action-a").textContent).toBe("Archive");
101
+ fireEvent.click(screen.getByTestId("m-cancel"));
102
+ expect(onOpenChange).toHaveBeenCalledWith(false);
103
+ expect(onPress).not.toHaveBeenCalled();
104
+ });
105
+
106
+ const onPlatform = (name: string) => {
107
+ const os = Platform.OS;
108
+ (Platform as { OS: string }).OS = name;
109
+ return () => void ((Platform as { OS: string }).OS = os);
110
+ };
111
+ const onIos = () => onPlatform("ios");
112
+
113
+ it("runs an action after closing, and on iOS not before the sheet has gone, with a fallback if it never says", async () => {
114
+ const restore = onIos();
115
+ const onPress = vi.fn();
116
+ const onOpenChange = vi.fn();
117
+ render(<NativeContextMenu {...base} onOpenChange={onOpenChange} actions={[{ id: "a", label: "Archive", onPress }]} />);
118
+ await act(async () => {});
119
+ vi.useFakeTimers();
120
+ fireEvent.click(screen.getByTestId("m-action-a"));
121
+ expect(onOpenChange).toHaveBeenCalledWith(false);
122
+ expect(onPress).not.toHaveBeenCalled();
123
+ act(() => vi.advanceTimersByTime(700));
124
+ expect(onPress).toHaveBeenCalledTimes(1);
125
+ restore();
126
+ });
127
+
128
+ it("runs on iOS as soon as the sheet says it has gone, once", async () => {
129
+ const restore = onIos();
130
+ const library = {
131
+ BottomSheetModal: forwardRef<unknown, Record<string, any>>(function Modal(props, ref) {
132
+ useImperativeHandle(ref, () => ({ present: () => undefined, dismiss: () => props.onDismiss?.() }));
133
+ return <div>{props.children}</div>;
134
+ }),
135
+ BottomSheetView: ({ children, testID }: { children?: ReactNode; testID?: string }) => <div data-testid={testID}>{children}</div>,
136
+ BottomSheetBackdrop: () => null,
137
+ BottomSheetModalProvider: ({ children }: { children?: ReactNode }) => <>{children}</>,
138
+ };
139
+ const onPress = vi.fn();
140
+ function Menu() {
141
+ const [open, setOpen] = useState(true);
142
+ return <NativeContextMenu open={open} onOpenChange={setOpen} testID="m" actions={[{ id: "a", label: "Archive", onPress }]} />;
143
+ }
144
+ render(
145
+ <NativeSheetProvider bottomSheet={library}>
146
+ <Menu />
147
+ </NativeSheetProvider>,
148
+ );
149
+ await act(async () => {});
150
+ vi.useFakeTimers();
151
+ fireEvent.click(screen.getByTestId("m-action-a"));
152
+ expect(onPress).toHaveBeenCalledTimes(1);
153
+ act(() => vi.advanceTimersByTime(700));
154
+ expect(onPress).toHaveBeenCalledTimes(1);
155
+ restore();
156
+ });
157
+
158
+ it("runs once on a double tap, on either platform", async () => {
159
+ const restoreAndroid = onPlatform("android");
160
+ const onPress = vi.fn();
161
+ render(<NativeContextMenu {...base} actions={[{ id: "a", label: "Delete", onPress, destructive: true }]} />);
162
+ await act(async () => {});
163
+ fireEvent.click(screen.getByTestId("m-action-a"));
164
+ fireEvent.click(screen.getByTestId("m-action-a"));
165
+ expect(onPress).toHaveBeenCalledTimes(1);
166
+ restoreAndroid();
167
+ const restore = onIos();
168
+ cleanup();
169
+ const onIosPress = vi.fn();
170
+ render(<NativeContextMenu {...base} actions={[{ id: "a", label: "Delete", onPress: onIosPress, destructive: true }]} />);
171
+ await act(async () => {});
172
+ vi.useFakeTimers();
173
+ fireEvent.click(screen.getByTestId("m-action-a"));
174
+ fireEvent.click(screen.getByTestId("m-action-a"));
175
+ act(() => vi.advanceTimersByTime(700));
176
+ expect(onIosPress).toHaveBeenCalledTimes(1);
177
+ restore();
178
+ });
179
+
180
+ it("can run again after it opens again", async () => {
181
+ const restore = onPlatform("android");
182
+ const onPress = vi.fn();
183
+ const { rerender } = render(<NativeContextMenu {...base} actions={[{ id: "a", label: "Archive", onPress }]} />);
184
+ await act(async () => {});
185
+ fireEvent.click(screen.getByTestId("m-action-a"));
186
+ rerender(<NativeContextMenu {...base} open={false} actions={[{ id: "a", label: "Archive", onPress }]} />);
187
+ rerender(<NativeContextMenu {...base} open actions={[{ id: "a", label: "Archive", onPress }]} />);
188
+ await act(async () => {});
189
+ fireEvent.click(screen.getByTestId("m-action-a"));
190
+ expect(onPress).toHaveBeenCalledTimes(2);
191
+ restore();
192
+ });
193
+
194
+ it("taps medium once as it opens", async () => {
195
+ const h = haptics();
196
+ const { rerender } = render(
197
+ <GenesisModulesProvider modules={{ haptics: h as never }}>
198
+ <NativeContextMenu {...base} open={false} actions={[]} />
199
+ </GenesisModulesProvider>,
200
+ );
201
+ expect(h.impactAsync).not.toHaveBeenCalled();
202
+ rerender(
203
+ <GenesisModulesProvider modules={{ haptics: h as never }}>
204
+ <NativeContextMenu {...base} open actions={[]} />
205
+ </GenesisModulesProvider>,
206
+ );
207
+ rerender(
208
+ <GenesisModulesProvider modules={{ haptics: h as never }}>
209
+ <NativeContextMenu {...base} open actions={[]} />
210
+ </GenesisModulesProvider>,
211
+ );
212
+ await act(async () => {});
213
+ expect(h.impactAsync).toHaveBeenCalledTimes(1);
214
+ });
215
+ });
@@ -0,0 +1,43 @@
1
+ import { useState } from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it } from "vitest";
4
+ import { Text } from "react-native";
5
+ import { NativeTabBar, type NativeTabBarItem } from "../tab-bar";
6
+
7
+ const items = (n: number): NativeTabBarItem[] =>
8
+ Array.from({ length: n }, (_, i) => ({ key: `t${i + 1}`, label: `Tab ${i + 1}`, icon: <Text>*</Text> }));
9
+
10
+ function Bar({ n, max }: { n: number; max?: number }) {
11
+ const [value, setValue] = useState("t1");
12
+ return (
13
+ <>
14
+ <Text testID="current">{value}</Text>
15
+ <NativeTabBar items={items(n)} value={value} onChange={setValue} {...(max ? { max } : {})} />
16
+ </>
17
+ );
18
+ }
19
+
20
+ describe("NativeTabBar", () => {
21
+ it("shows up to five tabs and switches between them", () => {
22
+ render(<Bar n={5} />);
23
+ expect(screen.queryByTestId("native-tab-bar-more")).toBeNull();
24
+ fireEvent.click(screen.getByTestId("native-tab-bar-t3"));
25
+ expect(screen.getByTestId("current").textContent).toBe("t3");
26
+ expect(screen.getByTestId("native-tab-bar-t3").getAttribute("aria-selected")).toBe("true");
27
+ });
28
+
29
+ it("past five, the fifth slot is More and its sheet holds the rest", async () => {
30
+ render(<Bar n={7} />);
31
+ expect(screen.queryByTestId("native-tab-bar-t5")).toBeNull();
32
+ fireEvent.click(screen.getByTestId("native-tab-bar-more"));
33
+ fireEvent.click(await screen.findByTestId("native-tab-bar-t7"));
34
+ expect(screen.getByTestId("current").textContent).toBe("t7");
35
+ });
36
+
37
+ it("honours max", () => {
38
+ render(<Bar n={4} max={3} />);
39
+ expect(screen.getByTestId("native-tab-bar-t2")).toBeTruthy();
40
+ expect(screen.queryByTestId("native-tab-bar-t3")).toBeNull();
41
+ expect(screen.getByTestId("native-tab-bar-more")).toBeTruthy();
42
+ });
43
+ });