@marktiderman/genesis-ui-native 2.0.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 (129) hide show
  1. package/dist/chunk-BAU4YQZV.js +760 -0
  2. package/dist/chunk-BAU4YQZV.js.map +1 -0
  3. package/dist/chunk-DGUM43GV.js +10 -0
  4. package/dist/chunk-DGUM43GV.js.map +1 -0
  5. package/dist/chunk-HNIEFTEL.js +43 -0
  6. package/dist/chunk-HNIEFTEL.js.map +1 -0
  7. package/dist/chunk-N4WHTQIO.js +20 -0
  8. package/dist/chunk-N4WHTQIO.js.map +1 -0
  9. package/dist/chunk-OHZD7KRO.js +11 -0
  10. package/dist/chunk-OHZD7KRO.js.map +1 -0
  11. package/dist/chunk-PTJ2KCLM.js +160 -0
  12. package/dist/chunk-PTJ2KCLM.js.map +1 -0
  13. package/dist/chunk-TXJT55JC.js +2213 -0
  14. package/dist/chunk-TXJT55JC.js.map +1 -0
  15. package/dist/chunk-ULS7I6ZS.js +183 -0
  16. package/dist/chunk-ULS7I6ZS.js.map +1 -0
  17. package/dist/chunk-ZVF6PONU.js +522 -0
  18. package/dist/chunk-ZVF6PONU.js.map +1 -0
  19. package/dist/components/index.d.ts +908 -0
  20. package/dist/components/index.js +8 -0
  21. package/dist/components/index.js.map +1 -0
  22. package/dist/data/index.d.ts +117 -0
  23. package/dist/data/index.js +770 -0
  24. package/dist/data/index.js.map +1 -0
  25. package/dist/hooks/index.d.ts +31 -0
  26. package/dist/hooks/index.js +5 -0
  27. package/dist/hooks/index.js.map +1 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.js +11 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/layouts/index.d.ts +364 -0
  32. package/dist/layouts/index.js +8 -0
  33. package/dist/layouts/index.js.map +1 -0
  34. package/dist/utils.d.ts +5 -0
  35. package/dist/utils.js +4 -0
  36. package/dist/utils.js.map +1 -0
  37. package/package.json +127 -0
  38. package/src/components/__tests__/accordion.test.tsx +122 -0
  39. package/src/components/__tests__/chip-group.test.tsx +45 -0
  40. package/src/components/__tests__/combobox.test.tsx +97 -0
  41. package/src/components/__tests__/drawer.test.tsx +98 -0
  42. package/src/components/__tests__/empty-state.test.tsx +66 -0
  43. package/src/components/__tests__/header-card.test.tsx +31 -0
  44. package/src/components/__tests__/layout.test.tsx +109 -0
  45. package/src/components/__tests__/list-item.test.tsx +31 -0
  46. package/src/components/__tests__/number-input.test.tsx +46 -0
  47. package/src/components/__tests__/pagination.test.tsx +43 -0
  48. package/src/components/__tests__/search-bar.test.tsx +41 -0
  49. package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
  50. package/src/components/__tests__/slider.test.tsx +134 -0
  51. package/src/components/__tests__/stepper.test.tsx +25 -0
  52. package/src/components/__tests__/toast.test.tsx +63 -0
  53. package/src/components/accordion.tsx +223 -0
  54. package/src/components/alert.tsx +131 -0
  55. package/src/components/avatar.tsx +68 -0
  56. package/src/components/badge.tsx +80 -0
  57. package/src/components/button.tsx +118 -0
  58. package/src/components/card.tsx +120 -0
  59. package/src/components/checkbox.tsx +60 -0
  60. package/src/components/chip-group.tsx +127 -0
  61. package/src/components/combobox.tsx +137 -0
  62. package/src/components/date-time-picker.tsx +127 -0
  63. package/src/components/dialog.tsx +131 -0
  64. package/src/components/drawer.tsx +131 -0
  65. package/src/components/dropdown-menu.tsx +133 -0
  66. package/src/components/empty-state.tsx +161 -0
  67. package/src/components/header-card.tsx +116 -0
  68. package/src/components/index.ts +259 -0
  69. package/src/components/inline-alert.tsx +150 -0
  70. package/src/components/input.tsx +51 -0
  71. package/src/components/label.tsx +35 -0
  72. package/src/components/layout/box.tsx +115 -0
  73. package/src/components/layout/flex.ts +24 -0
  74. package/src/components/layout/grid.tsx +73 -0
  75. package/src/components/layout/index.ts +27 -0
  76. package/src/components/layout/inline.tsx +63 -0
  77. package/src/components/layout/spacing.ts +116 -0
  78. package/src/components/layout/stack.tsx +58 -0
  79. package/src/components/list-item.tsx +108 -0
  80. package/src/components/number-input.tsx +119 -0
  81. package/src/components/pagination.tsx +132 -0
  82. package/src/components/popover.tsx +198 -0
  83. package/src/components/progress.tsx +50 -0
  84. package/src/components/radio-group.tsx +92 -0
  85. package/src/components/refresh-control.tsx +73 -0
  86. package/src/components/search-bar.tsx +128 -0
  87. package/src/components/section-list.tsx +54 -0
  88. package/src/components/segmented-control.tsx +79 -0
  89. package/src/components/select.tsx +178 -0
  90. package/src/components/separator.tsx +31 -0
  91. package/src/components/sheet.tsx +192 -0
  92. package/src/components/skeleton.tsx +104 -0
  93. package/src/components/slider.tsx +223 -0
  94. package/src/components/stepper.tsx +96 -0
  95. package/src/components/switch.tsx +35 -0
  96. package/src/components/tabs.tsx +147 -0
  97. package/src/components/text.tsx +62 -0
  98. package/src/components/textarea.tsx +52 -0
  99. package/src/components/toast.tsx +228 -0
  100. package/src/components/toggle.tsx +85 -0
  101. package/src/components/tooltip.tsx +104 -0
  102. package/src/data/NativeDataFilters.tsx +100 -0
  103. package/src/data/NativeDataPageShell.tsx +111 -0
  104. package/src/data/NativeDetailPanel.tsx +130 -0
  105. package/src/data/NativeEmptyState.tsx +46 -0
  106. package/src/data/NativeResourceForm.tsx +157 -0
  107. package/src/data/NativeResourceFormField.tsx +280 -0
  108. package/src/data/NativeResourcePage.tsx +505 -0
  109. package/src/data/index.ts +9 -0
  110. package/src/hooks/index.ts +16 -0
  111. package/src/hooks/use-genesis-extension.ts +81 -0
  112. package/src/hooks/use-reduced-motion.ts +32 -0
  113. package/src/hooks/use-theme-mode.ts +31 -0
  114. package/src/index.ts +5 -0
  115. package/src/layouts/__tests__/auth.test.tsx +150 -0
  116. package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
  117. package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
  118. package/src/layouts/__tests__/screen-container.test.tsx +79 -0
  119. package/src/layouts/__tests__/settings-page.test.tsx +107 -0
  120. package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
  121. package/src/layouts/auth.tsx +352 -0
  122. package/src/layouts/index.ts +61 -0
  123. package/src/layouts/nav-bar.tsx +200 -0
  124. package/src/layouts/notifications-page.tsx +274 -0
  125. package/src/layouts/screen-container.tsx +213 -0
  126. package/src/layouts/settings-page.tsx +195 -0
  127. package/src/layouts/settings-sub-page.tsx +183 -0
  128. package/src/nativewind.d.ts +40 -0
  129. package/src/utils.ts +6 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Layout primitives WIN test (promoted from Sanctiv incubator, PRD-46 WC-A4).
3
+ *
4
+ * Proves the keystone: Stack / Inline / Box / Grid compose a spaced layout
5
+ * and pull every gap/padding from the `spaceScale` DESIGN TOKEN — never a
6
+ * hard-coded literal. The token-driven assertions below recompute the
7
+ * expected NativeWind class FROM `spaceScale`, so a primitive that hard-codes
8
+ * spacing (e.g. `gap-2` for `md`) diverges from the token and fails.
9
+ *
10
+ * Genesis vitest convention: react-native is aliased to test-utils/rn-mock,
11
+ * which renders <View> as a <div> carrying `className` + `data-testid`. `cn`
12
+ * (clsx + tailwind-merge) runs for real, so we assert the merged className
13
+ * exactly as a consumer's NativeWind scanner would see it.
14
+ */
15
+
16
+ import { render, screen } from "@testing-library/react";
17
+ import { describe, expect, it } from "vitest";
18
+ import { Box } from "../layout/box";
19
+ import { Grid } from "../layout/grid";
20
+ import { Inline } from "../layout/inline";
21
+ import { Stack } from "../layout/stack";
22
+ import { type SpaceToken, spaceScale, spacingClass } from "../layout/spacing";
23
+
24
+ const ALL_TOKENS = Object.keys(spaceScale) as SpaceToken[];
25
+
26
+ function classOf(testID: string): string {
27
+ return screen.getByTestId(testID).getAttribute("class") ?? "";
28
+ }
29
+
30
+ describe("layout primitives — composition", () => {
31
+ it("all four primitives render a host View", () => {
32
+ render(
33
+ <>
34
+ <Stack testID="stack" />
35
+ <Inline testID="inline" />
36
+ <Box testID="box" />
37
+ <Grid testID="grid" />
38
+ </>,
39
+ );
40
+ expect(screen.getByTestId("stack")).toBeTruthy();
41
+ expect(screen.getByTestId("inline")).toBeTruthy();
42
+ expect(screen.getByTestId("box")).toBeTruthy();
43
+ expect(screen.getByTestId("grid")).toBeTruthy();
44
+ });
45
+
46
+ it("Stack composes a vertical column", () => {
47
+ render(<Stack testID="stack" />);
48
+ expect(classOf("stack")).toContain("flex-col");
49
+ });
50
+
51
+ it("Inline composes a horizontal row and can wrap", () => {
52
+ render(<Inline testID="inline" wrap gap="sm" />);
53
+ const cls = classOf("inline");
54
+ expect(cls).toContain("flex-row");
55
+ expect(cls).toContain("flex-wrap");
56
+ });
57
+
58
+ it("Grid composes equal-width cells across rows (3 items, 2 columns → 4 flex-1 cells)", () => {
59
+ render(
60
+ <Grid testID="grid" columns={2}>
61
+ <span>a</span>
62
+ <span>b</span>
63
+ <span>c</span>
64
+ </Grid>,
65
+ );
66
+ // 3 children + 1 padding cell so the short final row stays aligned.
67
+ const flexCells = screen
68
+ .getByTestId("grid")
69
+ .querySelectorAll(".flex-1");
70
+ expect(flexCells).toHaveLength(4);
71
+ });
72
+ });
73
+
74
+ describe("layout primitives — spacing comes from the design token, not a literal", () => {
75
+ it("the spacing token is the source of truth (md === 12px on the 4px grid)", () => {
76
+ expect(spaceScale.md).toBe(12);
77
+ expect(spacingClass("gap", "md")).toBe("gap-3"); // 12 / 4
78
+ });
79
+
80
+ it("Stack gap resolves THROUGH the token for every step", () => {
81
+ for (const token of ALL_TOKENS) {
82
+ const { unmount } = render(<Stack testID="s" gap={token} />);
83
+ // Expected class derived from spaceScale — a hard-coded literal in
84
+ // Stack would not match and this assertion would fail.
85
+ expect(classOf("s")).toContain(spacingClass("gap", token));
86
+ unmount();
87
+ }
88
+ });
89
+
90
+ it("Inline gap resolves through the token", () => {
91
+ render(<Inline testID="i" gap="lg" />);
92
+ expect(classOf("i")).toContain(spacingClass("gap", "lg"));
93
+ });
94
+
95
+ it("Box maps padding + margin tokens to token-derived classes", () => {
96
+ render(<Box testID="b" p="lg" px="sm" my="xl" />);
97
+ const cls = classOf("b");
98
+ expect(cls).toContain(spacingClass("p", "lg"));
99
+ expect(cls).toContain(spacingClass("px", "sm"));
100
+ expect(cls).toContain(spacingClass("my", "xl"));
101
+ });
102
+
103
+ it("Box bg maps to a semantic surface token class, never a raw hex", () => {
104
+ render(<Box testID="b" bg="canvas" />);
105
+ const cls = classOf("b");
106
+ expect(cls).toContain("bg-background");
107
+ expect(cls).not.toMatch(/#[0-9a-fA-F]{3,8}/);
108
+ });
109
+ });
@@ -0,0 +1,31 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { NativeListItem } from "../list-item";
4
+
5
+ describe("NativeListItem", () => {
6
+ it("renders title + subtitle", () => {
7
+ render(<NativeListItem testID="row" title="Title" subtitle="Sub" />);
8
+ const node = screen.getByTestId("row");
9
+ expect(node.textContent).toContain("Title");
10
+ expect(node.textContent).toContain("Sub");
11
+ });
12
+
13
+ it("renders as a button when onPress is provided", () => {
14
+ const onPress = vi.fn();
15
+ render(<NativeListItem testID="row" title="Tap me" onPress={onPress} />);
16
+ fireEvent.click(screen.getByTestId("row"));
17
+ expect(onPress).toHaveBeenCalledTimes(1);
18
+ });
19
+
20
+ it("disables interaction when disabled", () => {
21
+ const onPress = vi.fn();
22
+ render(
23
+ <NativeListItem testID="row" title="X" onPress={onPress} disabled />
24
+ );
25
+ expect(screen.getByTestId("row").getAttribute("aria-disabled")).toBe("true");
26
+ // The accessibility attribute alone isn't enough — verify the handler is
27
+ // genuinely suppressed when disabled.
28
+ fireEvent.click(screen.getByTestId("row"));
29
+ expect(onPress).not.toHaveBeenCalled();
30
+ });
31
+ });
@@ -0,0 +1,46 @@
1
+ import { useState } from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it } from "vitest";
4
+ import { NativeNumberInput } from "../number-input";
5
+
6
+ function Wrapper(props: { initial?: number; min?: number; max?: number; step?: number }) {
7
+ const [v, setV] = useState(props.initial ?? 1);
8
+ return (
9
+ <NativeNumberInput
10
+ testID="qty"
11
+ value={v}
12
+ onChange={setV}
13
+ min={props.min}
14
+ max={props.max}
15
+ step={props.step}
16
+ />
17
+ );
18
+ }
19
+
20
+ describe("NativeNumberInput", () => {
21
+ it("increments on + press", () => {
22
+ render(<Wrapper initial={2} />);
23
+ fireEvent.click(screen.getByTestId("qty-increment"));
24
+ expect((screen.getByTestId("qty-field") as HTMLInputElement).value).toBe("3");
25
+ });
26
+
27
+ it("decrements on − press", () => {
28
+ render(<Wrapper initial={5} />);
29
+ fireEvent.click(screen.getByTestId("qty-decrement"));
30
+ expect((screen.getByTestId("qty-field") as HTMLInputElement).value).toBe("4");
31
+ });
32
+
33
+ it("clamps to min", () => {
34
+ render(<Wrapper initial={1} min={1} />);
35
+ fireEvent.click(screen.getByTestId("qty-decrement"));
36
+ expect((screen.getByTestId("qty-field") as HTMLInputElement).value).toBe("1");
37
+ expect(screen.getByTestId("qty-decrement").getAttribute("aria-disabled")).toBe("true");
38
+ });
39
+
40
+ it("clamps to max", () => {
41
+ render(<Wrapper initial={5} max={5} />);
42
+ fireEvent.click(screen.getByTestId("qty-increment"));
43
+ expect((screen.getByTestId("qty-field") as HTMLInputElement).value).toBe("5");
44
+ expect(screen.getByTestId("qty-increment").getAttribute("aria-disabled")).toBe("true");
45
+ });
46
+ });
@@ -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 { NativePagination } from "../pagination";
5
+
6
+ function Wrapper({ count = 5 }: { count?: number }) {
7
+ const [page, setPage] = useState(0);
8
+ return (
9
+ <NativePagination
10
+ testID="pg"
11
+ pageCount={count}
12
+ page={page}
13
+ onChange={setPage}
14
+ />
15
+ );
16
+ }
17
+
18
+ describe("NativePagination", () => {
19
+ it("renders prev/next + numbered buttons", () => {
20
+ render(<Wrapper />);
21
+ expect(screen.getByTestId("pg-prev")).toBeTruthy();
22
+ expect(screen.getByTestId("pg-next")).toBeTruthy();
23
+ expect(screen.getByTestId("pg-page-0")).toBeTruthy();
24
+ expect(screen.getByTestId("pg-page-4")).toBeTruthy();
25
+ });
26
+
27
+ it("disables prev on the first page", () => {
28
+ render(<Wrapper />);
29
+ expect(screen.getByTestId("pg-prev").getAttribute("aria-disabled")).toBe("true");
30
+ });
31
+
32
+ it("advances on next press", () => {
33
+ render(<Wrapper />);
34
+ fireEvent.click(screen.getByTestId("pg-next"));
35
+ expect(screen.getByTestId("pg-page-1").getAttribute("aria-selected")).toBe("true");
36
+ });
37
+
38
+ it("shows trailing ellipsis when count exceeds maxVisible", () => {
39
+ render(<Wrapper count={20} />);
40
+ expect(screen.getByTestId("pg-page-0")).toBeTruthy();
41
+ expect(screen.queryByTestId("pg-page-19")).toBeNull();
42
+ });
43
+ });
@@ -0,0 +1,41 @@
1
+ import { useState } from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { NativeSearchBar } from "../search-bar";
5
+
6
+ function Wrapper(props: { onSubmit?: (v: string) => void }) {
7
+ const [v, setV] = useState("");
8
+ return (
9
+ <NativeSearchBar
10
+ testID="s"
11
+ value={v}
12
+ onChange={setV}
13
+ onSubmit={props.onSubmit}
14
+ />
15
+ );
16
+ }
17
+
18
+ describe("NativeSearchBar", () => {
19
+ it("clears value on the clear button press", () => {
20
+ const Init = () => {
21
+ const [v, setV] = useState("hello");
22
+ return <NativeSearchBar testID="s" value={v} onChange={setV} />;
23
+ };
24
+ render(<Init />);
25
+ expect((screen.getByTestId("s-input") as HTMLInputElement).value).toBe(
26
+ "hello"
27
+ );
28
+ fireEvent.click(screen.getByTestId("s-clear"));
29
+ expect((screen.getByTestId("s-input") as HTMLInputElement).value).toBe("");
30
+ });
31
+
32
+ it("fires onSubmit on Enter", () => {
33
+ const onSubmit = vi.fn();
34
+ render(<Wrapper onSubmit={onSubmit} />);
35
+ fireEvent.change(screen.getByTestId("s-input"), {
36
+ target: { value: "query" },
37
+ });
38
+ fireEvent.keyDown(screen.getByTestId("s-input"), { key: "Enter" });
39
+ expect(onSubmit).toHaveBeenCalledWith("query");
40
+ });
41
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Combined small-component tests: segmented control, empty state,
3
+ * inline alert, banner, section list header. One smoke test each
4
+ * covering the primary render + (where applicable) interaction.
5
+ */
6
+ import { useState } from "react";
7
+ import { fireEvent, render, screen } from "@testing-library/react";
8
+ import { describe, expect, it, vi } from "vitest";
9
+ import { NativeSegmentedControl } from "../segmented-control";
10
+ import { NativeEmptyState } from "../empty-state";
11
+ import { NativeInlineAlert, NativeBanner } from "../inline-alert";
12
+ import { NativeSectionListHeader } from "../section-list";
13
+
14
+ function Segmented() {
15
+ const [v, setV] = useState<"a" | "b" | "c">("a");
16
+ return (
17
+ <NativeSegmentedControl<"a" | "b" | "c">
18
+ testID="seg"
19
+ options={[
20
+ { value: "a", label: "A" },
21
+ { value: "b", label: "B" },
22
+ { value: "c", label: "C" },
23
+ ]}
24
+ value={v}
25
+ onChange={setV}
26
+ />
27
+ );
28
+ }
29
+
30
+ describe("Small primitives", () => {
31
+ it("segmented control selects an option", () => {
32
+ render(<Segmented />);
33
+ expect(screen.getByTestId("seg-option-a").getAttribute("aria-selected")).toBe(
34
+ "true"
35
+ );
36
+ fireEvent.click(screen.getByTestId("seg-option-c"));
37
+ expect(screen.getByTestId("seg-option-c").getAttribute("aria-selected")).toBe(
38
+ "true"
39
+ );
40
+ });
41
+
42
+ it("empty state renders variant-specific defaults", () => {
43
+ render(
44
+ <NativeEmptyState
45
+ variant="error"
46
+ description="Could not load."
47
+ />
48
+ );
49
+ const node = screen.getByTestId("empty-state-error");
50
+ expect(node.textContent).toContain("Something went wrong");
51
+ expect(node.textContent).toContain("Could not load.");
52
+ });
53
+
54
+ it("inline alert dismiss fires callback", () => {
55
+ const onDismiss = vi.fn();
56
+ render(
57
+ <NativeInlineAlert
58
+ testID="alert"
59
+ variant="warning"
60
+ title="Heads up"
61
+ onDismiss={onDismiss}
62
+ />
63
+ );
64
+ fireEvent.click(screen.getByTestId("alert-dismiss"));
65
+ expect(onDismiss).toHaveBeenCalledTimes(1);
66
+ });
67
+
68
+ it("banner renders a header role", () => {
69
+ render(
70
+ <NativeBanner testID="b" variant="info" title="Note" description="x" />
71
+ );
72
+ expect(screen.getByTestId("b")).toBeTruthy();
73
+ });
74
+
75
+ it("section list header renders title", () => {
76
+ render(<NativeSectionListHeader title="General" testID="hdr" />);
77
+ expect(screen.getByTestId("hdr").textContent).toBe("General");
78
+ });
79
+ });
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Slider unit tests — focused on the two regressions PR #30 CR review
3
+ * flagged and which PR #34 fixed:
4
+ *
5
+ * 1. PanResponder closure must be re-derived when value/width/min/max
6
+ * change. We can't drive a real gesture in the rn-mock environment
7
+ * (PanResponder.create returns `{panHandlers:{}}`), so we instead
8
+ * assert that PanResponder.create is invoked with HANDLER objects
9
+ * that close over the LATEST props by spying on the factory and
10
+ * driving the captured handler manually.
11
+ *
12
+ * 2. snap() math must respect non-zero `min`. The exported component
13
+ * exposes this only indirectly through the accessibility value; we
14
+ * assert the visible thumb position + accessibilityValue.now reflect
15
+ * a correctly snapped grid.
16
+ */
17
+ import { render, screen } from "@testing-library/react";
18
+ import { describe, expect, it, vi } from "vitest";
19
+ import { PanResponder } from "react-native";
20
+ import { NativeSlider } from "../slider";
21
+
22
+ describe("NativeSlider", () => {
23
+ it("renders the current value via accessibilityValue", () => {
24
+ render(<NativeSlider value={42} onChange={() => {}} testID="s" />);
25
+ const root = screen.getByTestId("s");
26
+ expect(root.getAttribute("aria-valuenow")).toBe("42");
27
+ expect(root.getAttribute("aria-valuemin")).toBe("0");
28
+ expect(root.getAttribute("aria-valuemax")).toBe("100");
29
+ });
30
+
31
+ it("respects non-zero min on the accessibility value (snap math grid base)", () => {
32
+ // With min=1 step=2, valid values are 1,3,5,7,9. The slider is a
33
+ // controlled component so the displayed value is whatever the
34
+ // consumer passes — but accessibilityValue.min must reflect `min`,
35
+ // not zero, so platform rotor adjusts on the right grid.
36
+ render(
37
+ <NativeSlider
38
+ value={5}
39
+ min={1}
40
+ max={9}
41
+ step={2}
42
+ onChange={() => {}}
43
+ testID="s"
44
+ />
45
+ );
46
+ const root = screen.getByTestId("s");
47
+ expect(root.getAttribute("aria-valuemin")).toBe("1");
48
+ expect(root.getAttribute("aria-valuemax")).toBe("9");
49
+ });
50
+
51
+ it("recreates PanResponder when value/min/max/step change (no stale closure)", () => {
52
+ // Spy on PanResponder.create. The slider must call create() at least
53
+ // once on mount and AGAIN when controlled props change, otherwise
54
+ // the original CR finding stands (handlers freeze at mount-time
55
+ // closure values). useMemo with the right dep array gives us this.
56
+ //
57
+ // Use a STABLE onChange ref across renders — inline `() => {}` would
58
+ // change identity on every render and inflate the create() count for
59
+ // the wrong reason, masking whether `value`/`min`/etc. were the actual
60
+ // trigger (CR feedback on PR #38).
61
+ const stableOnChange = vi.fn();
62
+ const spy = vi.spyOn(PanResponder, "create");
63
+ const { rerender } = render(
64
+ <NativeSlider value={10} min={0} max={100} step={1} onChange={stableOnChange} />
65
+ );
66
+ const callsAfterMount = spy.mock.calls.length;
67
+ expect(callsAfterMount).toBeGreaterThanOrEqual(1);
68
+
69
+ // New value -> new closure required.
70
+ rerender(
71
+ <NativeSlider value={50} min={0} max={100} step={1} onChange={stableOnChange} />
72
+ );
73
+ expect(spy.mock.calls.length).toBeGreaterThan(callsAfterMount);
74
+
75
+ // New min -> new closure required.
76
+ const callsAfterValueChange = spy.mock.calls.length;
77
+ rerender(
78
+ <NativeSlider value={50} min={5} max={100} step={1} onChange={stableOnChange} />
79
+ );
80
+ expect(spy.mock.calls.length).toBeGreaterThan(callsAfterValueChange);
81
+
82
+ // Same props (and same onChange identity) -> NO new create. This proves
83
+ // the dep array is correct: it doesn't churn on every render.
84
+ const callsAfterMinChange = spy.mock.calls.length;
85
+ rerender(
86
+ <NativeSlider value={50} min={5} max={100} step={1} onChange={stableOnChange} />
87
+ );
88
+ expect(spy.mock.calls.length).toBe(callsAfterMinChange);
89
+
90
+ spy.mockRestore();
91
+ });
92
+
93
+ it("PanResponder onPanResponderMove computes delta against fresh value", () => {
94
+ // Capture the handler config passed to create(); invoke it manually
95
+ // with a synthetic pan-move and verify onChange uses the LATEST value
96
+ // closure (not the mount-time value).
97
+ const calls: Array<Parameters<typeof PanResponder.create>[0]> = [];
98
+ const spy = vi
99
+ .spyOn(PanResponder, "create")
100
+ .mockImplementation((cfg) => {
101
+ calls.push(cfg);
102
+ return { panHandlers: {} } as unknown as ReturnType<
103
+ typeof PanResponder.create
104
+ >;
105
+ });
106
+
107
+ const onChange = vi.fn();
108
+ const { rerender } = render(
109
+ <NativeSlider value={20} min={0} max={100} step={1} onChange={onChange} />
110
+ );
111
+ // Force a re-render with a new `value`.
112
+ rerender(
113
+ <NativeSlider value={80} min={0} max={100} step={1} onChange={onChange} />
114
+ );
115
+
116
+ // Latest config closes over value=80. With width=0 (no layout in the
117
+ // happy-dom env) the move handler short-circuits — instead assert
118
+ // onPanResponderGrant captures the LATEST value (which is what fixes
119
+ // the stale-closure bug at the source level).
120
+ const latest = calls[calls.length - 1];
121
+ expect(latest).toBeDefined();
122
+
123
+ // Drive grant + move: in the absence of a width measurement the move
124
+ // is a no-op, but grant should at least not throw and the latest
125
+ // handler must reference the latest closure. We assert the closure
126
+ // is fresh by checking that onChange wasn't called with a stale
127
+ // value (negative coverage — if the handler had baked in the old
128
+ // value it would have become observable through grant side effects;
129
+ // for the slider grant only assigns to a ref).
130
+ expect(() => latest?.onPanResponderGrant?.({} as never, {} as never)).not.toThrow();
131
+
132
+ spy.mockRestore();
133
+ });
134
+ });
@@ -0,0 +1,25 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { describe, expect, it } from "vitest";
3
+ import { NativeStepper } from "../stepper";
4
+
5
+ describe("NativeStepper", () => {
6
+ it("renders all step dots and exposes accessibilityValue", () => {
7
+ render(
8
+ <NativeStepper
9
+ testID="stp"
10
+ steps={[
11
+ { label: "One" },
12
+ { label: "Two" },
13
+ { label: "Three" },
14
+ ]}
15
+ current={1}
16
+ />
17
+ );
18
+ expect(screen.getByTestId("stp-dot-0")).toBeTruthy();
19
+ expect(screen.getByTestId("stp-dot-1")).toBeTruthy();
20
+ expect(screen.getByTestId("stp-dot-2")).toBeTruthy();
21
+ const root = screen.getByTestId("stp");
22
+ expect(root.getAttribute("aria-valuenow")).toBe("2");
23
+ expect(root.getAttribute("aria-valuemax")).toBe("3");
24
+ });
25
+ });
@@ -0,0 +1,63 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { NativeToastProvider, useToast } from "../toast";
4
+
5
+ function TestHarness() {
6
+ const toast = useToast();
7
+ return (
8
+ <button
9
+ type="button"
10
+ data-testid="trigger"
11
+ onClick={() =>
12
+ toast.show({ title: "Saved", description: "All good." })
13
+ }
14
+ >
15
+ show
16
+ </button>
17
+ );
18
+ }
19
+
20
+ describe("NativeToast", () => {
21
+ it("queues + renders a toast on show()", () => {
22
+ render(
23
+ <NativeToastProvider disableAnimation>
24
+ <TestHarness />
25
+ </NativeToastProvider>
26
+ );
27
+ expect(screen.queryByTestId("native-toast")).toBeNull();
28
+ fireEvent.click(screen.getByTestId("trigger"));
29
+ expect(screen.getByTestId("native-toast")).toBeTruthy();
30
+ // Outer alert region carries the joined label so screen readers announce
31
+ // both the title and description in one polite-live-region utterance.
32
+ expect(screen.getByLabelText("Saved. All good.")).toBeTruthy();
33
+ });
34
+
35
+ it("dismisses on press", () => {
36
+ render(
37
+ <NativeToastProvider disableAnimation>
38
+ <TestHarness />
39
+ </NativeToastProvider>
40
+ );
41
+ fireEvent.click(screen.getByTestId("trigger"));
42
+ fireEvent.click(screen.getByTestId("native-toast"));
43
+ expect(screen.queryByTestId("native-toast")).toBeNull();
44
+ });
45
+
46
+ it("throws if useToast is called without provider", () => {
47
+ function Bare() {
48
+ useToast();
49
+ return null;
50
+ }
51
+ // jsdom logs an error to console; suppress it for the test.
52
+ const errSpy = vi
53
+ .spyOn(console, "error")
54
+ .mockImplementation(() => undefined);
55
+ try {
56
+ expect(() => render(<Bare />)).toThrow(/NativeToastProvider/);
57
+ } finally {
58
+ // Always restore — otherwise an assertion failure here would leak the
59
+ // console.error spy into subsequent tests.
60
+ errSpy.mockRestore();
61
+ }
62
+ });
63
+ });