@marktiderman/genesis-ui-native 3.5.1 → 3.7.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 (96) hide show
  1. package/README.md +115 -7
  2. package/dist/{chunk-ONH2PCGH.js → chunk-3KFUS7O6.js} +9 -15
  3. package/dist/chunk-3KFUS7O6.js.map +1 -0
  4. package/dist/{chunk-LBVD7XXL.js → chunk-7NDKIIOT.js} +627 -20
  5. package/dist/chunk-7NDKIIOT.js.map +1 -0
  6. package/dist/chunk-CAI7LGN6.js +39 -0
  7. package/dist/chunk-CAI7LGN6.js.map +1 -0
  8. package/dist/{chunk-ABVSSJNT.js → chunk-GBNIBHSU.js} +198 -168
  9. package/dist/chunk-GBNIBHSU.js.map +1 -0
  10. package/dist/chunk-IXC3LO2K.js +410 -0
  11. package/dist/chunk-IXC3LO2K.js.map +1 -0
  12. package/dist/{chunk-GHYUNNNU.js → chunk-KH2RVAI5.js} +174 -93
  13. package/dist/chunk-KH2RVAI5.js.map +1 -0
  14. package/dist/{chunk-6KWEAGRD.js → chunk-O4BMDV7I.js} +110 -17
  15. package/dist/chunk-O4BMDV7I.js.map +1 -0
  16. package/dist/chunk-RTYO24SC.js +105 -0
  17. package/dist/chunk-RTYO24SC.js.map +1 -0
  18. package/dist/{chunk-D5RKSPMH.js → chunk-YWDDDYDI.js} +4 -3
  19. package/dist/chunk-YWDDDYDI.js.map +1 -0
  20. package/dist/components/index.d.ts +382 -10
  21. package/dist/components/index.js +6 -5
  22. package/dist/data/index.d.ts +68 -4
  23. package/dist/data/index.js +231 -30
  24. package/dist/data/index.js.map +1 -1
  25. package/dist/hooks/index.d.ts +90 -2
  26. package/dist/hooks/index.js +3 -3
  27. package/dist/icons/lucide.d.ts +1 -1
  28. package/dist/icons/lucide.js +7 -1
  29. package/dist/icons/lucide.js.map +1 -1
  30. package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
  31. package/dist/index.d.ts +8 -5
  32. package/dist/index.js +9 -8
  33. package/dist/layouts/index.d.ts +40 -51
  34. package/dist/layouts/index.js +6 -4
  35. package/dist/{native-modules-PwnGltOU.d.ts → native-modules-DEJJQhDx.d.ts} +55 -1
  36. package/package.json +101 -4
  37. package/src/__tests__/doctor-rules.test.ts +87 -0
  38. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  39. package/src/components/__tests__/button-haptic.test.tsx +52 -0
  40. package/src/components/__tests__/composer-bar.test.tsx +79 -0
  41. package/src/components/__tests__/gallery-card.test.tsx +59 -0
  42. package/src/components/__tests__/gallery-grid.test.tsx +160 -0
  43. package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
  44. package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
  45. package/src/components/__tests__/lightbox.test.tsx +141 -0
  46. package/src/components/__tests__/live-indicator.test.tsx +72 -0
  47. package/src/components/__tests__/rating.test.tsx +82 -0
  48. package/src/components/__tests__/thread-list.test.tsx +219 -0
  49. package/src/components/button.tsx +18 -1
  50. package/src/components/composer-bar.tsx +276 -0
  51. package/src/components/drawer.tsx +15 -9
  52. package/src/components/gallery-card.tsx +109 -0
  53. package/src/components/gallery-grid.tsx +285 -0
  54. package/src/components/gallery-layout.ts +2 -0
  55. package/src/components/gallery-types.ts +2 -0
  56. package/src/components/index.ts +44 -0
  57. package/src/components/lightbox-zoom.tsx +282 -0
  58. package/src/components/lightbox.tsx +342 -0
  59. package/src/components/live-indicator.tsx +139 -0
  60. package/src/components/rating.tsx +128 -0
  61. package/src/components/skeleton.tsx +9 -4
  62. package/src/components/thread-list.tsx +457 -0
  63. package/src/components/toast.tsx +7 -4
  64. package/src/data/NativeConflictSheet.tsx +181 -0
  65. package/src/data/NativeResourceForm.tsx +15 -1
  66. package/src/data/index.ts +2 -0
  67. package/src/data/resource-view/NativeRecordView.tsx +85 -8
  68. package/src/data/resource-view/NativeResourceView.tsx +79 -32
  69. package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
  70. package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
  71. package/src/hooks/__tests__/use-haptics.test.tsx +146 -0
  72. package/src/hooks/__tests__/use-motion.test.tsx +106 -0
  73. package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
  74. package/src/hooks/index.ts +5 -0
  75. package/src/hooks/use-haptics.ts +64 -0
  76. package/src/hooks/use-motion.ts +128 -0
  77. package/src/hooks/use-press-feedback.ts +87 -0
  78. package/src/hooks/use-thread-jump.ts +110 -0
  79. package/src/icon-names.ts +6 -0
  80. package/src/icons/lucide.ts +12 -0
  81. package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
  82. package/src/layouts/__tests__/thread-page.test.tsx +114 -14
  83. package/src/layouts/inbox-page.tsx +6 -55
  84. package/src/layouts/index.ts +2 -0
  85. package/src/layouts/thread-page.tsx +326 -262
  86. package/src/native-modules.tsx +20 -2
  87. package/dist/chunk-6KWEAGRD.js.map +0 -1
  88. package/dist/chunk-7PCWEY6R.js +0 -27
  89. package/dist/chunk-7PCWEY6R.js.map +0 -1
  90. package/dist/chunk-ABVSSJNT.js.map +0 -1
  91. package/dist/chunk-D5RKSPMH.js.map +0 -1
  92. package/dist/chunk-GHYUNNNU.js.map +0 -1
  93. package/dist/chunk-LBVD7XXL.js.map +0 -1
  94. package/dist/chunk-ONH2PCGH.js.map +0 -1
  95. package/dist/chunk-Z3AQYVUA.js +0 -36
  96. package/dist/chunk-Z3AQYVUA.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ /** NativeGalleryGrid: justified rows from the measured width, tappable tiles. */
2
+ import { act, fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { GALLERY_DEFAULTS, type GalleryItem } from "../gallery-types";
5
+ import { NativeGalleryGrid } from "../gallery-grid";
6
+
7
+ const items: GalleryItem[] = Array.from({ length: 5 }, (_, i) => ({
8
+ id: `p${i}`,
9
+ src: `https://example.test/${i}.jpg`,
10
+ alt: `Photo ${i}`,
11
+ width: 400,
12
+ height: 300,
13
+ }));
14
+
15
+ const style = (el: HTMLElement) => JSON.parse(el.dataset.style!) as { width: number; height: number };
16
+
17
+ /** Measure the grid: the shim turns a `layout` DOM event into onLayout. */
18
+ function measure(el: HTMLElement, width: number) {
19
+ act(() => {
20
+ el.dispatchEvent(new CustomEvent("layout", { detail: { width, height: 0 } }));
21
+ });
22
+ }
23
+
24
+ describe("NativeGalleryGrid", () => {
25
+ it("draws nothing until the container is measured, then a tile per item", () => {
26
+ render(<NativeGalleryGrid items={items} testID="g" />);
27
+ expect(screen.queryByTestId("g-item-p0")).toBeNull();
28
+ measure(screen.getByTestId("g"), 600);
29
+ expect(screen.getAllByTestId(/^g-item-/)).toHaveLength(5);
30
+ });
31
+
32
+ it("grid layout: square tiles, `columns` per row", () => {
33
+ render(<NativeGalleryGrid items={items} layout="grid" columns={2} gap={10} testID="g" />);
34
+ measure(screen.getByTestId("g"), 210);
35
+ expect(style(screen.getByTestId("g-item-p0"))).toEqual({ width: 100, height: 100 });
36
+ expect(screen.getAllByTestId(/^g-item-/)).toHaveLength(5);
37
+ expect(screen.queryAllByRole("button")).toHaveLength(0);
38
+ });
39
+
40
+ it("justified layout: rows fill the width and tiles are buttons with onItemPress", () => {
41
+ const onItemPress = vi.fn();
42
+ render(<NativeGalleryGrid items={items} rowHeight={100} gap={4} onItemPress={onItemPress} testID="g" />);
43
+ measure(screen.getByTestId("g"), 600);
44
+ const tiles = screen.getAllByRole("button");
45
+ expect(tiles).toHaveLength(5);
46
+ expect(tiles[0].getAttribute("aria-label")).toBe("Photo 0");
47
+ const first = style(tiles[0]);
48
+ expect(first.height).toBeGreaterThan(0);
49
+ fireEvent.click(screen.getByTestId("g-item-p2"));
50
+ expect(onItemPress).toHaveBeenCalledWith(items[2], 2);
51
+ });
52
+
53
+ it("renderItem replaces the tile's content", () => {
54
+ render(<NativeGalleryGrid items={items.slice(0, 1)} renderItem={(it) => <span data-testid={`custom-${it.id}`}>x</span>} testID="g" />);
55
+ measure(screen.getByTestId("g"), 300);
56
+ expect(screen.getByTestId("custom-p0")).toBeTruthy();
57
+ });
58
+ });
59
+
60
+ describe("NativeGalleryGrid additions", () => {
61
+ it("overlays renderBadges on the default tile", () => {
62
+ render(<NativeGalleryGrid items={items.slice(0, 2)} renderBadges={(it) => <span data-testid={`b-${it.id}`}>new</span>} testID="g" />);
63
+ measure(screen.getByTestId("g"), 600);
64
+ expect(screen.getByTestId("g-badges-p0").contains(screen.getByTestId("b-p0"))).toBe(true);
65
+ });
66
+
67
+ it("a press only selects when onSelectionChange is set, not also onItemPress", () => {
68
+ const onItemPress = vi.fn();
69
+ const onSelectionChange = vi.fn();
70
+ render(<NativeGalleryGrid items={items} onItemPress={onItemPress} onSelectionChange={onSelectionChange} testID="g" />);
71
+ measure(screen.getByTestId("g"), 600);
72
+ fireEvent.click(screen.getByTestId("g-item-p0"));
73
+ expect(onSelectionChange).toHaveBeenCalledTimes(1);
74
+ expect(onItemPress).not.toHaveBeenCalled();
75
+ });
76
+
77
+ it("toggles selection on press, ringing selected tiles", () => {
78
+ const onSelectionChange = vi.fn();
79
+ render(<NativeGalleryGrid items={items} selected={["p1"]} onSelectionChange={onSelectionChange} testID="g" />);
80
+ measure(screen.getByTestId("g"), 600);
81
+ const chosen = screen.getByTestId("g-item-p1");
82
+ expect(chosen.getAttribute("aria-selected")).toBe("true");
83
+ expect(chosen.className).toContain("border-ring");
84
+ expect(screen.getByTestId("g-item-p0").getAttribute("aria-selected")).toBe("false");
85
+ fireEvent.click(screen.getByTestId("g-item-p0"));
86
+ expect(onSelectionChange).toHaveBeenCalledWith(["p1", "p0"], { item: items[0], index: 0 });
87
+ fireEvent.click(chosen);
88
+ expect(onSelectionChange).toHaveBeenLastCalledWith([], { item: items[1], index: 1 });
89
+ });
90
+
91
+ it("calls loadMore only when scrolling nears the end, not on measure or on new items", () => {
92
+ const loadMore = vi.fn();
93
+ const many = Array.from({ length: 60 }, (_, i) => ({ id: `m${i}`, src: `https://example.test/m${i}.jpg`, width: 400, height: 300 }));
94
+ const { rerender } = render(<NativeGalleryGrid items={many} loadMore={loadMore} testID="g" />);
95
+ measure(screen.getByTestId("g"), 600);
96
+ rerender(<NativeGalleryGrid items={[...many, { id: "x", src: "https://example.test/x.jpg" }]} loadMore={loadMore} testID="g" />);
97
+ expect(loadMore).not.toHaveBeenCalled();
98
+ act(() => {
99
+ screen.getByTestId("g-list").dispatchEvent(new Event("endreached"));
100
+ });
101
+ expect(loadMore).toHaveBeenCalledTimes(1);
102
+ });
103
+
104
+ it("renders the rows through a list with a header and footer, and sizes grid tiles by aspectRatio", () => {
105
+ render(
106
+ <NativeGalleryGrid items={items} layout="grid" columns={2} gap={10} aspectRatio={2} header={<span>Top</span>} footer={<span>More</span>} testID="g" />,
107
+ );
108
+ measure(screen.getByTestId("g"), 210);
109
+ expect(screen.getByTestId("g-list").textContent).toMatch(/^Top.*More$/);
110
+ expect(style(screen.getByTestId("g-item-p0"))).toEqual({ width: 100, height: 50 });
111
+ });
112
+
113
+ it("still takes the deprecated onNearEnd and getGroup", () => {
114
+ const onNearEnd = vi.fn();
115
+ render(<NativeGalleryGrid items={items} onNearEnd={onNearEnd} getGroup={() => "All"} testID="g" />);
116
+ measure(screen.getByTestId("g"), 600);
117
+ act(() => {
118
+ screen.getByTestId("g-list").dispatchEvent(new Event("endreached"));
119
+ });
120
+ expect(onNearEnd).toHaveBeenCalledTimes(1);
121
+ expect(screen.getByTestId("g-group-All")).toBeTruthy();
122
+ });
123
+
124
+ it("draws an item with no image as a neutral tile with its words, still named and pressable", () => {
125
+ const onItemPress = vi.fn();
126
+ render(<NativeGalleryGrid items={[{ id: "n", src: "", alt: "Untitled", caption: "No photo yet" }]} onItemPress={onItemPress} testID="g" />);
127
+ measure(screen.getByTestId("g"), 300);
128
+ const tile = screen.getByTestId("g-item-n");
129
+ expect(tile.getAttribute("aria-label")).toBe("Untitled");
130
+ expect(tile.querySelector("img")).toBeNull();
131
+ expect(screen.getByTestId("g-placeholder-n").textContent).toBe("UntitledNo photo yet");
132
+ fireEvent.click(tile);
133
+ expect(onItemPress).toHaveBeenCalledWith(expect.objectContaining({ id: "n" }), 0);
134
+ });
135
+
136
+ it("names a plain (not pressable) placeholder tile as an image", () => {
137
+ render(<NativeGalleryGrid items={[{ id: "n", src: "", alt: "Untitled" }]} testID="g" />);
138
+ measure(screen.getByTestId("g"), 300);
139
+ const placeholder = screen.getByTestId("g-placeholder-n");
140
+ expect(placeholder.getAttribute("role")).toBe("image");
141
+ expect(placeholder.getAttribute("aria-label")).toBe("Untitled");
142
+ });
143
+
144
+ it("shares the web's defaults", () => {
145
+ expect(GALLERY_DEFAULTS).toEqual({ rowHeight: 180, gap: 4, columns: 3 });
146
+ });
147
+
148
+ it("groups items in order of first appearance under headers", () => {
149
+ const grouped = items.map((it, i) => ({ ...it, caption: i % 2 ? "Odd" : "Even" }));
150
+ const onItemPress = vi.fn();
151
+ render(<NativeGalleryGrid items={grouped} groupBy={(it) => it.caption!} onItemPress={onItemPress} testID="g" />);
152
+ measure(screen.getByTestId("g"), 600);
153
+ const headers = screen.getAllByRole("header").map((h) => h.textContent);
154
+ expect(headers).toEqual(["Even", "Odd"]);
155
+ expect(screen.getByTestId("g-group-Odd").textContent).toBe("Odd");
156
+ expect(screen.getAllByTestId("g-row-Odd").some((row) => row.contains(screen.getByTestId("g-item-p1")))).toBe(true);
157
+ fireEvent.click(screen.getByTestId("g-item-p3"));
158
+ expect(onItemPress).toHaveBeenCalledWith(grouped[3], 3);
159
+ });
160
+ });
@@ -0,0 +1,50 @@
1
+ /** NativeLightbox re-snaps to the current page when the width changes (rotation). */
2
+ import { act, render, screen } from "@testing-library/react";
3
+ import { forwardRef, useImperativeHandle } from "react";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { NativeLightbox } from "../lightbox";
6
+
7
+ const scrollToIndex = vi.fn();
8
+ const listProps: { current: Record<string, unknown> } = { current: {} };
9
+
10
+ vi.mock("react-native", async (importOriginal) => {
11
+ const actual = await importOriginal<Record<string, unknown>>();
12
+ const Original = actual.FlatList as React.ComponentType<Record<string, unknown>>;
13
+ const FlatList = forwardRef<{ scrollToIndex: typeof scrollToIndex }, Record<string, unknown>>((props, ref) => {
14
+ useImperativeHandle(ref, () => ({ scrollToIndex }));
15
+ listProps.current = props;
16
+ return <Original {...props} />;
17
+ });
18
+ return { ...actual, FlatList };
19
+ });
20
+
21
+ const items = [
22
+ { id: "a", src: "https://example.test/a.jpg" },
23
+ { id: "b", src: "https://example.test/b.jpg" },
24
+ ];
25
+
26
+ describe("NativeLightbox rotation", () => {
27
+ it("scrolls back to the current page, unanimated, when the width changes", () => {
28
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={() => undefined} testID="lb" />);
29
+ expect(scrollToIndex).toHaveBeenLastCalledWith({ index: 1, animated: true });
30
+ scrollToIndex.mockClear();
31
+ act(() => {
32
+ screen.getByTestId("lb-content").dispatchEvent(new CustomEvent("layout", { detail: { width: 812, height: 375 } }));
33
+ });
34
+ expect(scrollToIndex).toHaveBeenCalledWith({ index: 1, animated: false });
35
+ });
36
+
37
+ it("scrolls back when a swipe's page isn't taken by the parent", () => {
38
+ vi.useFakeTimers();
39
+ const onIndexChange = vi.fn();
40
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={onIndexChange} testID="lb" />);
41
+ scrollToIndex.mockClear();
42
+ act(() => {
43
+ (listProps.current.onMomentumScrollEnd as (e: unknown) => void)({ nativeEvent: { contentOffset: { x: 9999, y: 0 } } });
44
+ });
45
+ expect(onIndexChange).toHaveBeenCalledWith(1);
46
+ act(() => vi.runAllTimers());
47
+ expect(scrollToIndex).toHaveBeenCalledWith(expect.objectContaining({ index: 0 }));
48
+ vi.useRealTimers();
49
+ });
50
+ });
@@ -0,0 +1,33 @@
1
+ /** The zoom and dismiss rules NativeLightbox's photo pages use (moved from genesis-chat's viewer). */
2
+ import { describe, expect, it } from "vitest";
3
+ import {
4
+ LIGHTBOX_DISMISS_DISTANCE,
5
+ LIGHTBOX_MAX_ZOOM,
6
+ lightboxPanLimit,
7
+ lightboxPinchScale,
8
+ lightboxShouldDismiss,
9
+ lightboxTouchDistance,
10
+ } from "../lightbox-zoom";
11
+
12
+ describe("lightbox zoom rules", () => {
13
+ it("closes on a long pull or a quick flick down, not a nudge", () => {
14
+ expect(lightboxShouldDismiss(LIGHTBOX_DISMISS_DISTANCE + 1, 0)).toBe(true);
15
+ expect(lightboxShouldDismiss(30, 1.5)).toBe(true);
16
+ expect(lightboxShouldDismiss(20, 3)).toBe(false);
17
+ expect(lightboxShouldDismiss(60, 0.2)).toBe(false);
18
+ });
19
+
20
+ it("zooms with the fingers' spread, between 0.8× and the maximum", () => {
21
+ expect(lightboxPinchScale(1, 100, 200)).toBe(2);
22
+ expect(lightboxPinchScale(2, 100, 1000)).toBe(LIGHTBOX_MAX_ZOOM);
23
+ expect(lightboxPinchScale(1, 100, 10)).toBe(0.8);
24
+ expect(lightboxPinchScale(1.5, 0, 50)).toBe(1.5);
25
+ });
26
+
27
+ it("measures two touches, and pans only as far as the zoomed photo reaches", () => {
28
+ expect(lightboxTouchDistance([{ pageX: 0, pageY: 0 }, { pageX: 3, pageY: 4 }])).toBe(5);
29
+ expect(lightboxTouchDistance([{ pageX: 0, pageY: 0 }])).toBe(0);
30
+ expect(lightboxPanLimit(1, 400)).toBe(0);
31
+ expect(lightboxPanLimit(2, 400)).toBe(200);
32
+ });
33
+ });
@@ -0,0 +1,141 @@
1
+ /** NativeLightbox: a full-screen pager with close, counter, caption and actions. */
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import type { GalleryItem } from "../gallery-types";
5
+ import { NativeLightbox } from "../lightbox";
6
+
7
+ const items: GalleryItem[] = [
8
+ { id: "a", src: "https://example.test/a.jpg", alt: "First", caption: "Warm-up" },
9
+ { id: "b", src: "https://example.test/b.jpg", alt: "Second", caption: "Lift" },
10
+ { id: "c", src: "https://example.test/c.jpg" },
11
+ ];
12
+
13
+ describe("NativeLightbox", () => {
14
+ it("renders nothing while closed", () => {
15
+ render(<NativeLightbox open={false} onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} testID="lb" />);
16
+ expect(screen.queryByTestId("lb")).toBeNull();
17
+ });
18
+
19
+ it("shows every page, the counter and the current caption on a dark full-screen modal", () => {
20
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={() => undefined} testID="lb" />);
21
+ expect(screen.getByTestId("lb").getAttribute("data-presentation-style")).toBe("overFullScreen");
22
+ // The backdrop is its own layer, so a pull down can fade it.
23
+ const backdrop = screen.getByTestId("lb-content").firstElementChild as HTMLElement;
24
+ expect(JSON.parse(backdrop.dataset.style!).backgroundColor).toBe("#000000");
25
+ expect(screen.getByTestId("lb-counter").textContent).toBe("2 / 3");
26
+ expect(screen.getByTestId("lb-caption").textContent).toBe("Lift");
27
+ expect(screen.getByTestId("lb-page-a")).toBeTruthy();
28
+ expect(screen.getByTestId("lb-page-c")).toBeTruthy();
29
+ });
30
+
31
+ it("closes from the top-left button", () => {
32
+ const onOpenChange = vi.fn();
33
+ render(<NativeLightbox open onOpenChange={onOpenChange} items={items} index={0} onIndexChange={() => undefined} testID="lb" />);
34
+ const close = screen.getByTestId("lb-close");
35
+ expect(close.getAttribute("aria-label")).toBe("Close");
36
+ fireEvent.click(close);
37
+ expect(onOpenChange).toHaveBeenCalledWith(false);
38
+ });
39
+
40
+ it("renders custom caption and actions for the current item", () => {
41
+ render(
42
+ <NativeLightbox
43
+ open
44
+ onOpenChange={() => undefined}
45
+ items={items}
46
+ index={2}
47
+ onIndexChange={() => undefined}
48
+ renderCaption={(it, i) => <span data-testid="cap">{`${it.id}#${i}`}</span>}
49
+ renderActions={(it) => <span data-testid="act">{it.id}</span>}
50
+ testID="lb"
51
+ />,
52
+ );
53
+ expect(screen.getByTestId("cap").textContent).toBe("c#2");
54
+ expect(screen.getByTestId("lb-actions").contains(screen.getByTestId("act"))).toBe(true);
55
+ expect(screen.getByTestId("lb-counter").textContent).toBe("3 / 3");
56
+ });
57
+
58
+ it("shows no counter for a single picture", () => {
59
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items.slice(0, 1)} index={0} onIndexChange={() => undefined} testID="lb" />);
60
+ expect(screen.queryByTestId("lb-counter")).toBeNull();
61
+ });
62
+
63
+ it("clamps an out-of-range index", () => {
64
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={9} onIndexChange={() => undefined} testID="lb" />);
65
+ expect(screen.getByTestId("lb-counter").textContent).toBe("3 / 3");
66
+ });
67
+ });
68
+
69
+ describe("NativeLightbox additions", () => {
70
+ it("renderMedia replaces each page's picture", () => {
71
+ render(
72
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} renderMedia={(it, i) => <span data-testid={`m-${it.id}`}>{i}</span>} testID="lb" />,
73
+ );
74
+ expect(screen.getByTestId("lb-page-b").contains(screen.getByTestId("m-b"))).toBe(true);
75
+ expect(screen.getByTestId("m-c").textContent).toBe("2");
76
+ expect(screen.queryByRole("img")).toBeNull();
77
+ });
78
+
79
+ it("shows title and description in the top bar and labels the viewer with the title", () => {
80
+ render(
81
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} title="Session photos" description="3 March" testID="lb" />,
82
+ );
83
+ expect(screen.getByTestId("lb-title").textContent).toBe("Session photos");
84
+ expect(screen.getByTestId("lb-title").getAttribute("role")).toBe("header");
85
+ expect(screen.getByTestId("lb-description").textContent).toBe("3 March");
86
+ expect(screen.getByTestId("lb-content").getAttribute("aria-label")).toBe("Session photos");
87
+ expect(screen.getByTestId("lb-counter").textContent).toBe("1 / 3");
88
+ });
89
+
90
+ it("gives screen readers an adjustable pager that reads the position and steps through the items", () => {
91
+ const onIndexChange = vi.fn();
92
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={onIndexChange} testID="lb" />);
93
+ const pager = screen.getByTestId("lb-pager-a11y");
94
+ expect(pager.getAttribute("role")).toBe("adjustable");
95
+ expect(pager.getAttribute("aria-label")).toBe("Second");
96
+ expect(pager.getAttribute("aria-valuetext")).toBe("2 of 3");
97
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "increment" }));
98
+ expect(onIndexChange).toHaveBeenLastCalledWith(2);
99
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "decrement" }));
100
+ expect(onIndexChange).toHaveBeenLastCalledWith(0);
101
+ });
102
+
103
+ it("names a picture with no alt by its position, and leaves renderMedia pages to themselves", () => {
104
+ render(
105
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={2} onIndexChange={() => undefined} renderMedia={(it) => <span>video {it.id}</span>} testID="lb" />,
106
+ );
107
+ expect(screen.getByTestId("lb-pager-a11y").getAttribute("aria-label")).toBe("Photo 3 of 3");
108
+ expect(screen.getByTestId("lb-page-c").textContent).toBe("video c");
109
+ expect(screen.queryByTestId("lb-photo-c")).toBeNull();
110
+ });
111
+
112
+ it("with renderMedia, keeps the pages ungrouped so their own controls stay reachable, and the counter is the pager", () => {
113
+ const onIndexChange = vi.fn();
114
+ render(
115
+ <NativeLightbox
116
+ open
117
+ onOpenChange={() => undefined}
118
+ items={items}
119
+ index={0}
120
+ onIndexChange={onIndexChange}
121
+ renderMedia={(it) => <button data-testid={`play-${it.id}`}>Play</button>}
122
+ testID="lb"
123
+ />,
124
+ );
125
+ const pages = screen.getByTestId("lb-pages");
126
+ expect(pages.getAttribute("role")).toBeNull();
127
+ expect(pages.contains(screen.getByTestId("play-a"))).toBe(true);
128
+ const pager = screen.getByTestId("lb-pager-a11y");
129
+ expect(pager.contains(screen.getByTestId("lb-counter"))).toBe(true);
130
+ expect(pager.getAttribute("role")).toBe("adjustable");
131
+ expect(pager.getAttribute("aria-valuetext")).toBe("1 of 3");
132
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "increment" }));
133
+ expect(onIndexChange).toHaveBeenLastCalledWith(1);
134
+ });
135
+
136
+ it("zooms the built-in photo pages, and lets the words change", () => {
137
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} labels={{ close: "Fermer" }} testID="lb" />);
138
+ expect(screen.getByTestId("lb-photo-a")).toBeTruthy();
139
+ expect(screen.getByTestId("lb-close").getAttribute("aria-label")).toBe("Fermer");
140
+ });
141
+ });
@@ -0,0 +1,72 @@
1
+ /** NativeLiveIndicator: a polite text live region with a red dot when live, grey when not. */
2
+ import { render, screen } from "@testing-library/react";
3
+ import { AccessibilityInfo } from "react-native";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { NativeLiveIndicator } from "../live-indicator";
6
+
7
+ describe("NativeLiveIndicator", () => {
8
+ it("is a pill reading 'Live' with a destructive dot by default", () => {
9
+ render(<NativeLiveIndicator testID="li" />);
10
+ const root = screen.getByTestId("li");
11
+ expect(root.getAttribute("role")).toBe("text");
12
+ expect(root.getAttribute("aria-label")).toBe("Live");
13
+ expect(screen.getByTestId("li-label").textContent).toBe("Live");
14
+ expect(screen.getByTestId("li-dot").className).toContain("bg-destructive");
15
+ });
16
+
17
+ it("goes muted and says so when not live", () => {
18
+ render(<NativeLiveIndicator live={false} label="On air" testID="li" />);
19
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Not on air");
20
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground");
21
+ expect(screen.getByTestId("li-label").textContent).toBe("On air");
22
+ });
23
+
24
+ it("dot variant keeps the label for screen readers only", () => {
25
+ render(<NativeLiveIndicator variant="dot" testID="li" />);
26
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Live");
27
+ expect(screen.queryByTestId("li-label")).toBeNull();
28
+ expect(screen.getByTestId("li-dot")).toBeTruthy();
29
+ });
30
+ });
31
+
32
+ describe("NativeLiveIndicator additions", () => {
33
+ it("state overrides live, offline is a faint dot", () => {
34
+ render(<NativeLiveIndicator live state="offline" testID="li" />);
35
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground/50");
36
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Offline");
37
+ });
38
+
39
+ it("state idle matches live={false}", () => {
40
+ render(<NativeLiveIndicator state="idle" testID="li" />);
41
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground");
42
+ expect(screen.getByTestId("li-dot").className).not.toContain("/50");
43
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Idle");
44
+ });
45
+
46
+ it("shows detail after the label and announces it", () => {
47
+ render(<NativeLiveIndicator detail="12 watching" testID="li" />);
48
+ expect(screen.getByTestId("li-detail").textContent).toBe("12 watching");
49
+ expect(screen.getByTestId("li-detail").className).toContain("text-muted-foreground");
50
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Live, 12 watching");
51
+ });
52
+ });
53
+
54
+ describe("NativeLiveIndicator label and announcements", () => {
55
+ it("shows the state's own label unless one is given", () => {
56
+ const { rerender } = render(<NativeLiveIndicator state="idle" testID="li" />);
57
+ expect(screen.getByTestId("li-label").textContent).toBe("Idle");
58
+ rerender(<NativeLiveIndicator state="offline" testID="li" />);
59
+ expect(screen.getByTestId("li-label").textContent).toBe("Offline");
60
+ rerender(<NativeLiveIndicator state="offline" label="Stream" testID="li" />);
61
+ expect(screen.getByTestId("li-label").textContent).toBe("Stream");
62
+ });
63
+
64
+ it("announces a state change after mount, not the first render", () => {
65
+ const spy = vi.spyOn(AccessibilityInfo as unknown as Record<string, () => void>, "announceForAccessibilityWithOptions");
66
+ const { rerender } = render(<NativeLiveIndicator testID="li" />);
67
+ expect(spy).not.toHaveBeenCalled();
68
+ rerender(<NativeLiveIndicator state="offline" testID="li" />);
69
+ expect(spy).toHaveBeenCalledWith("Offline", { queue: true });
70
+ spy.mockRestore();
71
+ });
72
+ });
@@ -0,0 +1,82 @@
1
+ /** NativeRating: one image when read-only, radios when tappable. */
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import type { ReactNode } from "react";
4
+ import { GenesisModulesProvider, type GenesisModules } from "../../native-modules";
5
+ import { describe, expect, it, vi } from "vitest";
6
+ import { NativeRating, nextRating } from "../rating";
7
+
8
+ describe("NativeRating", () => {
9
+ it("is a single image labelled 'N of M stars' when read-only", () => {
10
+ render(<NativeRating value={3} testID="r" />);
11
+ const root = screen.getByTestId("r");
12
+ expect(root.getAttribute("role")).toBe("image");
13
+ expect(root.getAttribute("aria-label")).toBe("3 of 5 stars");
14
+ expect(screen.queryAllByRole("radio")).toHaveLength(0);
15
+ expect(screen.getByTestId("r-star-5")).toBeTruthy();
16
+ });
17
+
18
+ it("honours max and label, and rounds the value", () => {
19
+ render(<NativeRating value={7.6} max={10} label="hearts" testID="r" />);
20
+ expect(screen.getByTestId("r").getAttribute("aria-label")).toBe("hearts: 8 of 10 stars");
21
+ expect(screen.getByTestId("r-star-10")).toBeTruthy();
22
+ expect(screen.queryByTestId("r-star-11")).toBeNull();
23
+ });
24
+
25
+ it("is a radiogroup of selectable stars with onChange", () => {
26
+ const onChange = vi.fn();
27
+ render(<NativeRating value={2} onChange={onChange} testID="r" />);
28
+ expect(screen.getByTestId("r").getAttribute("role")).toBe("radiogroup");
29
+ const radios = screen.getAllByRole("radio");
30
+ expect(radios).toHaveLength(5);
31
+ expect(screen.getByTestId("r-star-2").getAttribute("aria-selected")).toBe("true");
32
+ expect(screen.getByTestId("r-star-3").getAttribute("aria-selected")).toBe("false");
33
+ fireEvent.click(screen.getByTestId("r-star-4"));
34
+ expect(onChange).toHaveBeenCalledWith(4);
35
+ });
36
+ });
37
+
38
+ describe("NativeRating additions", () => {
39
+ it("nextRating clears when the current value is pressed again", () => {
40
+ expect(nextRating(3, 3)).toBe(0);
41
+ expect(nextRating(3, 4)).toBe(4);
42
+ expect(nextRating(0, 1)).toBe(1);
43
+ });
44
+
45
+ it("pressing the current star reports 0", () => {
46
+ const onChange = vi.fn();
47
+ render(<NativeRating value={2} onChange={onChange} testID="r" />);
48
+ fireEvent.click(screen.getByTestId("r-star-2"));
49
+ expect(onChange).toHaveBeenCalledWith(0);
50
+ });
51
+
52
+ it("readOnly wins over onChange, and getLabel writes the label", () => {
53
+ render(<NativeRating value={4} onChange={() => undefined} readOnly getLabel={(v, m) => `Rated ${v}/${m}`} testID="r" />);
54
+ const root = screen.getByTestId("r");
55
+ expect(root.getAttribute("role")).toBe("image");
56
+ expect(root.getAttribute("aria-label")).toBe("Rated 4/5");
57
+ expect(screen.queryAllByRole("radio")).toHaveLength(0);
58
+ });
59
+ });
60
+
61
+ describe("NativeRating accessibility", () => {
62
+ it("names the read-only control by label, then the count", () => {
63
+ render(<NativeRating value={3} label="Service rating" testID="r" />);
64
+ expect(screen.getByTestId("r").getAttribute("aria-label")).toBe("Service rating: 3 of 5 stars");
65
+ });
66
+
67
+ it("applies getLabel to each radio as well as the value", () => {
68
+ render(<NativeRating value={2} onChange={() => undefined} getLabel={(v, m) => `${v}/${m} hearts`} testID="r" />);
69
+ expect(screen.getByTestId("r-star-4").getAttribute("aria-label")).toBe("4/5 hearts");
70
+ expect(screen.getByTestId("r").getAttribute("aria-valuetext")).toBe("2/5 hearts");
71
+ });
72
+
73
+ it("distinguishes filled from empty fallback stars without colour", () => {
74
+ const modules = {
75
+ icons: { star: (p: { fill?: unknown; testID?: string }) => <i data-testid={p.testID} data-fill={String(p.fill)} /> },
76
+ } as unknown as GenesisModules;
77
+ const wrap = (node: ReactNode) => <GenesisModulesProvider modules={modules}>{node}</GenesisModulesProvider>;
78
+ render(wrap(<NativeRating value={1} testID="r" />));
79
+ expect(screen.getByTestId("r-star-1").getAttribute("data-fill")).not.toBe("none");
80
+ expect(screen.getByTestId("r-star-2").getAttribute("data-fill")).toBe("none");
81
+ });
82
+ });