@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.
- package/dist/chunk-BAU4YQZV.js +760 -0
- package/dist/chunk-BAU4YQZV.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-HNIEFTEL.js +43 -0
- package/dist/chunk-HNIEFTEL.js.map +1 -0
- package/dist/chunk-N4WHTQIO.js +20 -0
- package/dist/chunk-N4WHTQIO.js.map +1 -0
- package/dist/chunk-OHZD7KRO.js +11 -0
- package/dist/chunk-OHZD7KRO.js.map +1 -0
- package/dist/chunk-PTJ2KCLM.js +160 -0
- package/dist/chunk-PTJ2KCLM.js.map +1 -0
- package/dist/chunk-TXJT55JC.js +2213 -0
- package/dist/chunk-TXJT55JC.js.map +1 -0
- package/dist/chunk-ULS7I6ZS.js +183 -0
- package/dist/chunk-ULS7I6ZS.js.map +1 -0
- package/dist/chunk-ZVF6PONU.js +522 -0
- package/dist/chunk-ZVF6PONU.js.map +1 -0
- package/dist/components/index.d.ts +908 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/data/index.d.ts +117 -0
- package/dist/data/index.js +770 -0
- package/dist/data/index.js.map +1 -0
- package/dist/hooks/index.d.ts +31 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/index.d.ts +364 -0
- package/dist/layouts/index.js +8 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +4 -0
- package/dist/utils.js.map +1 -0
- package/package.json +127 -0
- package/src/components/__tests__/accordion.test.tsx +122 -0
- package/src/components/__tests__/chip-group.test.tsx +45 -0
- package/src/components/__tests__/combobox.test.tsx +97 -0
- package/src/components/__tests__/drawer.test.tsx +98 -0
- package/src/components/__tests__/empty-state.test.tsx +66 -0
- package/src/components/__tests__/header-card.test.tsx +31 -0
- package/src/components/__tests__/layout.test.tsx +109 -0
- package/src/components/__tests__/list-item.test.tsx +31 -0
- package/src/components/__tests__/number-input.test.tsx +46 -0
- package/src/components/__tests__/pagination.test.tsx +43 -0
- package/src/components/__tests__/search-bar.test.tsx +41 -0
- package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
- package/src/components/__tests__/slider.test.tsx +134 -0
- package/src/components/__tests__/stepper.test.tsx +25 -0
- package/src/components/__tests__/toast.test.tsx +63 -0
- package/src/components/accordion.tsx +223 -0
- package/src/components/alert.tsx +131 -0
- package/src/components/avatar.tsx +68 -0
- package/src/components/badge.tsx +80 -0
- package/src/components/button.tsx +118 -0
- package/src/components/card.tsx +120 -0
- package/src/components/checkbox.tsx +60 -0
- package/src/components/chip-group.tsx +127 -0
- package/src/components/combobox.tsx +137 -0
- package/src/components/date-time-picker.tsx +127 -0
- package/src/components/dialog.tsx +131 -0
- package/src/components/drawer.tsx +131 -0
- package/src/components/dropdown-menu.tsx +133 -0
- package/src/components/empty-state.tsx +161 -0
- package/src/components/header-card.tsx +116 -0
- package/src/components/index.ts +259 -0
- package/src/components/inline-alert.tsx +150 -0
- package/src/components/input.tsx +51 -0
- package/src/components/label.tsx +35 -0
- package/src/components/layout/box.tsx +115 -0
- package/src/components/layout/flex.ts +24 -0
- package/src/components/layout/grid.tsx +73 -0
- package/src/components/layout/index.ts +27 -0
- package/src/components/layout/inline.tsx +63 -0
- package/src/components/layout/spacing.ts +116 -0
- package/src/components/layout/stack.tsx +58 -0
- package/src/components/list-item.tsx +108 -0
- package/src/components/number-input.tsx +119 -0
- package/src/components/pagination.tsx +132 -0
- package/src/components/popover.tsx +198 -0
- package/src/components/progress.tsx +50 -0
- package/src/components/radio-group.tsx +92 -0
- package/src/components/refresh-control.tsx +73 -0
- package/src/components/search-bar.tsx +128 -0
- package/src/components/section-list.tsx +54 -0
- package/src/components/segmented-control.tsx +79 -0
- package/src/components/select.tsx +178 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +192 -0
- package/src/components/skeleton.tsx +104 -0
- package/src/components/slider.tsx +223 -0
- package/src/components/stepper.tsx +96 -0
- package/src/components/switch.tsx +35 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/text.tsx +62 -0
- package/src/components/textarea.tsx +52 -0
- package/src/components/toast.tsx +228 -0
- package/src/components/toggle.tsx +85 -0
- package/src/components/tooltip.tsx +104 -0
- package/src/data/NativeDataFilters.tsx +100 -0
- package/src/data/NativeDataPageShell.tsx +111 -0
- package/src/data/NativeDetailPanel.tsx +130 -0
- package/src/data/NativeEmptyState.tsx +46 -0
- package/src/data/NativeResourceForm.tsx +157 -0
- package/src/data/NativeResourceFormField.tsx +280 -0
- package/src/data/NativeResourcePage.tsx +505 -0
- package/src/data/index.ts +9 -0
- package/src/hooks/index.ts +16 -0
- package/src/hooks/use-genesis-extension.ts +81 -0
- package/src/hooks/use-reduced-motion.ts +32 -0
- package/src/hooks/use-theme-mode.ts +31 -0
- package/src/index.ts +5 -0
- package/src/layouts/__tests__/auth.test.tsx +150 -0
- package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
- package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
- package/src/layouts/__tests__/screen-container.test.tsx +79 -0
- package/src/layouts/__tests__/settings-page.test.tsx +107 -0
- package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
- package/src/layouts/auth.tsx +352 -0
- package/src/layouts/index.ts +61 -0
- package/src/layouts/nav-bar.tsx +200 -0
- package/src/layouts/notifications-page.tsx +274 -0
- package/src/layouts/screen-container.tsx +213 -0
- package/src/layouts/settings-page.tsx +195 -0
- package/src/layouts/settings-sub-page.tsx +183 -0
- package/src/nativewind.d.ts +40 -0
- package/src/utils.ts +6 -0
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"description": "Genesis React Native components (NativeWind v4-5). Part of the Genesis framework.",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/marktiderman/genesis.git",
|
|
11
|
+
"directory": "packages/ui-native"
|
|
12
|
+
},
|
|
13
|
+
"license": "UNLICENSED",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": false
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"source": "./src/index.ts",
|
|
22
|
+
"react-native": "./src/index.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"react-native": "./src/index.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./components": {
|
|
36
|
+
"types": "./dist/components/index.d.ts",
|
|
37
|
+
"react-native": "./src/components/index.ts",
|
|
38
|
+
"import": "./dist/components/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./data": {
|
|
41
|
+
"types": "./dist/data/index.d.ts",
|
|
42
|
+
"react-native": "./src/data/index.ts",
|
|
43
|
+
"import": "./dist/data/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./hooks": {
|
|
46
|
+
"types": "./dist/hooks/index.d.ts",
|
|
47
|
+
"react-native": "./src/hooks/index.ts",
|
|
48
|
+
"import": "./dist/hooks/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./layouts": {
|
|
51
|
+
"types": "./dist/layouts/index.d.ts",
|
|
52
|
+
"react-native": "./src/layouts/index.ts",
|
|
53
|
+
"import": "./dist/layouts/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./utils": {
|
|
56
|
+
"types": "./dist/utils.d.ts",
|
|
57
|
+
"react-native": "./src/utils.ts",
|
|
58
|
+
"import": "./dist/utils.js",
|
|
59
|
+
"default": "./dist/utils.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
64
|
+
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0",
|
|
65
|
+
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
66
|
+
"@tanstack/react-query": "^5.0.0",
|
|
67
|
+
"clsx": "^2.0.0",
|
|
68
|
+
"expo-haptics": ">=14.0.0",
|
|
69
|
+
"lucide-react-native": ">=0.400.0",
|
|
70
|
+
"nativewind": "^4.0.0 || ^5.0.0-preview",
|
|
71
|
+
"react": "^19.0.0",
|
|
72
|
+
"react-hook-form": "^7.0.0",
|
|
73
|
+
"react-native": ">=0.76.0",
|
|
74
|
+
"react-native-gesture-handler": ">=2.0.0",
|
|
75
|
+
"react-native-keyboard-controller": ">=1.0.0",
|
|
76
|
+
"react-native-reanimated": ">=3.0.0",
|
|
77
|
+
"react-native-safe-area-context": ">=4.0.0",
|
|
78
|
+
"tailwind-merge": "^3.0.0",
|
|
79
|
+
"zod": "^3.0.0 || ^4.0.0",
|
|
80
|
+
"@marktiderman/genesis-core": "^1.0.0",
|
|
81
|
+
"@marktiderman/genesis-design-system": "^1.0.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"react-native": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@gorhom/bottom-sheet": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"react-native-gesture-handler": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"react-native-reanimated": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@react-native-community/datetimepicker": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"react-native-keyboard-controller": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"expo-haptics": {
|
|
103
|
+
"optional": true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"class-variance-authority": "^0.7.1"
|
|
108
|
+
},
|
|
109
|
+
"devDependencies": {
|
|
110
|
+
"@testing-library/react": "^16.3.2",
|
|
111
|
+
"@types/react": "^19.2.14",
|
|
112
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
113
|
+
"happy-dom": "^20.9.0",
|
|
114
|
+
"react": "^19.2.5",
|
|
115
|
+
"react-dom": "^19.2.5",
|
|
116
|
+
"tsup": "^8.3.0",
|
|
117
|
+
"typescript": "^5.9.3",
|
|
118
|
+
"vitest": "^2.1.0"
|
|
119
|
+
},
|
|
120
|
+
"scripts": {
|
|
121
|
+
"build": "tsup",
|
|
122
|
+
"dev": "tsup --watch",
|
|
123
|
+
"clean": "rm -rf dist",
|
|
124
|
+
"typecheck": "tsc --noEmit",
|
|
125
|
+
"test": "vitest run"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
NativeAccordion,
|
|
5
|
+
NativeAccordionContent,
|
|
6
|
+
NativeAccordionItem,
|
|
7
|
+
NativeAccordionTrigger,
|
|
8
|
+
} from "../accordion";
|
|
9
|
+
|
|
10
|
+
describe("NativeAccordion", () => {
|
|
11
|
+
it("expands a single item by default and collapses on second press", () => {
|
|
12
|
+
render(
|
|
13
|
+
<NativeAccordion testID="acc">
|
|
14
|
+
<NativeAccordionItem value="a">
|
|
15
|
+
<NativeAccordionTrigger>A</NativeAccordionTrigger>
|
|
16
|
+
<NativeAccordionContent>Body A</NativeAccordionContent>
|
|
17
|
+
</NativeAccordionItem>
|
|
18
|
+
<NativeAccordionItem value="b">
|
|
19
|
+
<NativeAccordionTrigger>B</NativeAccordionTrigger>
|
|
20
|
+
<NativeAccordionContent>Body B</NativeAccordionContent>
|
|
21
|
+
</NativeAccordionItem>
|
|
22
|
+
</NativeAccordion>
|
|
23
|
+
);
|
|
24
|
+
expect(screen.queryByTestId("accordion-content-a")).toBeNull();
|
|
25
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-a"));
|
|
26
|
+
expect(screen.getByTestId("accordion-content-a")).toBeTruthy();
|
|
27
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-a"));
|
|
28
|
+
expect(screen.queryByTestId("accordion-content-a")).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("only allows one open at a time in single mode", () => {
|
|
32
|
+
render(
|
|
33
|
+
<NativeAccordion>
|
|
34
|
+
<NativeAccordionItem value="a">
|
|
35
|
+
<NativeAccordionTrigger>A</NativeAccordionTrigger>
|
|
36
|
+
<NativeAccordionContent>Body A</NativeAccordionContent>
|
|
37
|
+
</NativeAccordionItem>
|
|
38
|
+
<NativeAccordionItem value="b">
|
|
39
|
+
<NativeAccordionTrigger>B</NativeAccordionTrigger>
|
|
40
|
+
<NativeAccordionContent>Body B</NativeAccordionContent>
|
|
41
|
+
</NativeAccordionItem>
|
|
42
|
+
</NativeAccordion>
|
|
43
|
+
);
|
|
44
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-a"));
|
|
45
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-b"));
|
|
46
|
+
expect(screen.queryByTestId("accordion-content-a")).toBeNull();
|
|
47
|
+
expect(screen.getByTestId("accordion-content-b")).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("auto-applies isLast to the final accordion item", () => {
|
|
51
|
+
// Auto-detection: the last <NativeAccordionItem> renders without
|
|
52
|
+
// border-b, the others keep it. We assert via accessible labels +
|
|
53
|
+
// by checking the className prop on the rendered DOM nodes.
|
|
54
|
+
render(
|
|
55
|
+
<NativeAccordion testID="acc">
|
|
56
|
+
<NativeAccordionItem value="a">
|
|
57
|
+
<NativeAccordionTrigger>A</NativeAccordionTrigger>
|
|
58
|
+
<NativeAccordionContent>Body A</NativeAccordionContent>
|
|
59
|
+
</NativeAccordionItem>
|
|
60
|
+
<NativeAccordionItem value="b">
|
|
61
|
+
<NativeAccordionTrigger>B</NativeAccordionTrigger>
|
|
62
|
+
<NativeAccordionContent>Body B</NativeAccordionContent>
|
|
63
|
+
</NativeAccordionItem>
|
|
64
|
+
<NativeAccordionItem value="c">
|
|
65
|
+
<NativeAccordionTrigger>C</NativeAccordionTrigger>
|
|
66
|
+
<NativeAccordionContent>Body C</NativeAccordionContent>
|
|
67
|
+
</NativeAccordionItem>
|
|
68
|
+
</NativeAccordion>
|
|
69
|
+
);
|
|
70
|
+
// The trigger Pressable is inside an item View; walk to that
|
|
71
|
+
// grandparent to inspect its className.
|
|
72
|
+
const triggerA = screen.getByTestId("accordion-trigger-a");
|
|
73
|
+
const triggerC = screen.getByTestId("accordion-trigger-c");
|
|
74
|
+
const itemA = triggerA.parentElement as HTMLElement;
|
|
75
|
+
const itemC = triggerC.parentElement as HTMLElement;
|
|
76
|
+
// First two items keep the divider; the auto-detected last item drops it.
|
|
77
|
+
// Use a word-boundary regex so `border-border` (which textually contains
|
|
78
|
+
// `border-b` as a substring) doesn't false-match.
|
|
79
|
+
expect(itemA?.className).toMatch(/(^|\s)border-b(\s|$)/);
|
|
80
|
+
expect(itemC?.className).not.toMatch(/(^|\s)border-b(\s|$)/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("respects explicit isLast={false} on the trailing child", () => {
|
|
84
|
+
// Manual override should win over auto-detection so consumers can
|
|
85
|
+
// keep the bottom border on the last item (e.g. when the accordion
|
|
86
|
+
// is followed by other content with its own top border).
|
|
87
|
+
render(
|
|
88
|
+
<NativeAccordion>
|
|
89
|
+
<NativeAccordionItem value="a">
|
|
90
|
+
<NativeAccordionTrigger>A</NativeAccordionTrigger>
|
|
91
|
+
<NativeAccordionContent>Body A</NativeAccordionContent>
|
|
92
|
+
</NativeAccordionItem>
|
|
93
|
+
<NativeAccordionItem value="b" isLast={false}>
|
|
94
|
+
<NativeAccordionTrigger>B</NativeAccordionTrigger>
|
|
95
|
+
<NativeAccordionContent>Body B</NativeAccordionContent>
|
|
96
|
+
</NativeAccordionItem>
|
|
97
|
+
</NativeAccordion>
|
|
98
|
+
);
|
|
99
|
+
const triggerB = screen.getByTestId("accordion-trigger-b");
|
|
100
|
+
const itemB = triggerB.parentElement as HTMLElement;
|
|
101
|
+
expect(itemB?.className).toMatch(/(^|\s)border-b(\s|$)/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("multiple mode keeps both open", () => {
|
|
105
|
+
render(
|
|
106
|
+
<NativeAccordion type="multiple">
|
|
107
|
+
<NativeAccordionItem value="a">
|
|
108
|
+
<NativeAccordionTrigger>A</NativeAccordionTrigger>
|
|
109
|
+
<NativeAccordionContent>Body A</NativeAccordionContent>
|
|
110
|
+
</NativeAccordionItem>
|
|
111
|
+
<NativeAccordionItem value="b">
|
|
112
|
+
<NativeAccordionTrigger>B</NativeAccordionTrigger>
|
|
113
|
+
<NativeAccordionContent>Body B</NativeAccordionContent>
|
|
114
|
+
</NativeAccordionItem>
|
|
115
|
+
</NativeAccordion>
|
|
116
|
+
);
|
|
117
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-a"));
|
|
118
|
+
fireEvent.click(screen.getByTestId("accordion-trigger-b"));
|
|
119
|
+
expect(screen.getByTestId("accordion-content-a")).toBeTruthy();
|
|
120
|
+
expect(screen.getByTestId("accordion-content-b")).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { NativeChip, NativeChipGroup } from "../chip-group";
|
|
5
|
+
|
|
6
|
+
function Multiple() {
|
|
7
|
+
const [v, setV] = useState<string | string[]>([]);
|
|
8
|
+
return (
|
|
9
|
+
<NativeChipGroup mode="multiple" value={v} onChange={setV}>
|
|
10
|
+
<NativeChip value="a">A</NativeChip>
|
|
11
|
+
<NativeChip value="b">B</NativeChip>
|
|
12
|
+
<NativeChip value="c">C</NativeChip>
|
|
13
|
+
</NativeChipGroup>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Single() {
|
|
18
|
+
const [v, setV] = useState<string | string[]>("a");
|
|
19
|
+
return (
|
|
20
|
+
<NativeChipGroup mode="single" value={v} onChange={setV}>
|
|
21
|
+
<NativeChip value="a">A</NativeChip>
|
|
22
|
+
<NativeChip value="b">B</NativeChip>
|
|
23
|
+
</NativeChipGroup>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("NativeChipGroup", () => {
|
|
28
|
+
it("toggles chip selection in multiple mode", () => {
|
|
29
|
+
render(<Multiple />);
|
|
30
|
+
const a = screen.getByTestId("chip-a");
|
|
31
|
+
expect(a.getAttribute("aria-selected")).toBe("false");
|
|
32
|
+
fireEvent.click(a);
|
|
33
|
+
expect(screen.getByTestId("chip-a").getAttribute("aria-selected")).toBe("true");
|
|
34
|
+
fireEvent.click(screen.getByTestId("chip-a"));
|
|
35
|
+
expect(screen.getByTestId("chip-a").getAttribute("aria-selected")).toBe("false");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("single mode swaps the single selection", () => {
|
|
39
|
+
render(<Single />);
|
|
40
|
+
expect(screen.getByTestId("chip-a").getAttribute("aria-selected")).toBe("true");
|
|
41
|
+
fireEvent.click(screen.getByTestId("chip-b"));
|
|
42
|
+
expect(screen.getByTestId("chip-b").getAttribute("aria-selected")).toBe("true");
|
|
43
|
+
expect(screen.getByTestId("chip-a").getAttribute("aria-selected")).toBe("false");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { NativeCombobox, type NativeComboboxOption } from "../combobox";
|
|
5
|
+
|
|
6
|
+
const options: NativeComboboxOption[] = [
|
|
7
|
+
{ value: "a", label: "Apple" },
|
|
8
|
+
{ value: "b", label: "Banana" },
|
|
9
|
+
{ value: "c", label: "Cherry" },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
function Wrapper() {
|
|
13
|
+
const [v, setV] = useState<string | undefined>();
|
|
14
|
+
return (
|
|
15
|
+
<NativeCombobox
|
|
16
|
+
testID="cb"
|
|
17
|
+
options={options}
|
|
18
|
+
value={v}
|
|
19
|
+
onChange={setV}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("NativeCombobox", () => {
|
|
25
|
+
it("shows options on focus and filters by query", () => {
|
|
26
|
+
render(<Wrapper />);
|
|
27
|
+
const input = screen.getByTestId("cb-input") as HTMLInputElement;
|
|
28
|
+
fireEvent.focus(input);
|
|
29
|
+
expect(screen.getByTestId("cb-option-a")).toBeTruthy();
|
|
30
|
+
expect(screen.getByTestId("cb-option-b")).toBeTruthy();
|
|
31
|
+
fireEvent.change(input, { target: { value: "ba" } });
|
|
32
|
+
expect(screen.queryByTestId("cb-option-a")).toBeNull();
|
|
33
|
+
expect(screen.getByTestId("cb-option-b")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("selects an option on press", () => {
|
|
37
|
+
render(<Wrapper />);
|
|
38
|
+
fireEvent.focus(screen.getByTestId("cb-input"));
|
|
39
|
+
fireEvent.click(screen.getByTestId("cb-option-c"));
|
|
40
|
+
expect((screen.getByTestId("cb-input") as HTMLInputElement).value).toBe(
|
|
41
|
+
"Cherry"
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("closes the dropdown on input blur without selecting", () => {
|
|
46
|
+
// CR finding (PR #30 / fixed PR #34): the dropdown had no way to
|
|
47
|
+
// dismiss without picking an option. Blur now closes the popup
|
|
48
|
+
// (with a 120ms delay so an option-press can still register).
|
|
49
|
+
// Use fake timers + act() so the React state update inside the
|
|
50
|
+
// timer callback flushes synchronously.
|
|
51
|
+
vi.useFakeTimers();
|
|
52
|
+
try {
|
|
53
|
+
render(<Wrapper />);
|
|
54
|
+
const input = screen.getByTestId("cb-input");
|
|
55
|
+
fireEvent.focus(input);
|
|
56
|
+
expect(screen.getByTestId("cb-option-a")).toBeTruthy();
|
|
57
|
+
fireEvent.blur(input);
|
|
58
|
+
act(() => {
|
|
59
|
+
vi.advanceTimersByTime(150);
|
|
60
|
+
});
|
|
61
|
+
expect(screen.queryByTestId("cb-option-a")).toBeNull();
|
|
62
|
+
} finally {
|
|
63
|
+
vi.useRealTimers();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("renders the option list inside a ScrollView (keyboardShouldPersistTaps)", () => {
|
|
68
|
+
// The list must be scrollable when content exceeds the dropdown
|
|
69
|
+
// height. The rn-mock aliases ScrollView -> View, but the
|
|
70
|
+
// keyboardShouldPersistTaps prop survives onto the DOM as a custom
|
|
71
|
+
// attribute (lowercased). We assert it's present, which proves the
|
|
72
|
+
// wrap exists at the source level.
|
|
73
|
+
const many: NativeComboboxOption[] = Array.from({ length: 30 }, (_, i) => ({
|
|
74
|
+
value: `v${i}`,
|
|
75
|
+
label: `Option ${i}`,
|
|
76
|
+
}));
|
|
77
|
+
render(
|
|
78
|
+
<NativeCombobox testID="cb" options={many} onChange={() => {}} />
|
|
79
|
+
);
|
|
80
|
+
fireEvent.focus(screen.getByTestId("cb-input"));
|
|
81
|
+
// Walk up from the first option to find a node carrying the
|
|
82
|
+
// keyboardShouldPersistTaps attribute (the ScrollView wrapper).
|
|
83
|
+
let node: HTMLElement | null = screen.getByTestId("cb-option-v0");
|
|
84
|
+
let foundScrollWrapper = false;
|
|
85
|
+
while (node) {
|
|
86
|
+
if (
|
|
87
|
+
node.getAttribute("keyboardshouldpersisttaps") === "handled" ||
|
|
88
|
+
node.getAttribute("keyboardShouldPersistTaps") === "handled"
|
|
89
|
+
) {
|
|
90
|
+
foundScrollWrapper = true;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
node = node.parentElement;
|
|
94
|
+
}
|
|
95
|
+
expect(foundScrollWrapper).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawer unit tests — covers the PR #30 CR finding (PR #34 fixed) that
|
|
3
|
+
* PanResponder closures captured stale `side` / `drawerWidth` /
|
|
4
|
+
* `onOpenChange` from initial render. We can't actually drive a swipe
|
|
5
|
+
* in the rn-mock env (PanResponder is stubbed to `{panHandlers:{}}`),
|
|
6
|
+
* but we CAN assert the handler config is rebuilt when the props it
|
|
7
|
+
* depends on change. That's the contract — `useMemo` keyed on the
|
|
8
|
+
* right deps.
|
|
9
|
+
*/
|
|
10
|
+
import { render } from "@testing-library/react";
|
|
11
|
+
import { describe, expect, it, vi } from "vitest";
|
|
12
|
+
import { PanResponder } from "react-native";
|
|
13
|
+
import { NativeDrawer } from "../drawer";
|
|
14
|
+
|
|
15
|
+
describe("NativeDrawer", () => {
|
|
16
|
+
it("rebuilds PanResponder when `side` changes (no stale closure)", () => {
|
|
17
|
+
const spy = vi.spyOn(PanResponder, "create");
|
|
18
|
+
const onOpenChange = vi.fn();
|
|
19
|
+
|
|
20
|
+
const { rerender } = render(
|
|
21
|
+
<NativeDrawer open onOpenChange={onOpenChange} side="left">
|
|
22
|
+
<span data-testid="content">menu</span>
|
|
23
|
+
</NativeDrawer>
|
|
24
|
+
);
|
|
25
|
+
const afterMount = spy.mock.calls.length;
|
|
26
|
+
expect(afterMount).toBeGreaterThanOrEqual(1);
|
|
27
|
+
|
|
28
|
+
rerender(
|
|
29
|
+
<NativeDrawer open onOpenChange={onOpenChange} side="right">
|
|
30
|
+
<span data-testid="content">menu</span>
|
|
31
|
+
</NativeDrawer>
|
|
32
|
+
);
|
|
33
|
+
expect(spy.mock.calls.length).toBeGreaterThan(afterMount);
|
|
34
|
+
|
|
35
|
+
spy.mockRestore();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("rebuilds PanResponder when `width` changes", () => {
|
|
39
|
+
const spy = vi.spyOn(PanResponder, "create");
|
|
40
|
+
const onOpenChange = vi.fn();
|
|
41
|
+
|
|
42
|
+
const { rerender } = render(
|
|
43
|
+
<NativeDrawer open onOpenChange={onOpenChange} width={240}>
|
|
44
|
+
<span>menu</span>
|
|
45
|
+
</NativeDrawer>
|
|
46
|
+
);
|
|
47
|
+
const afterMount = spy.mock.calls.length;
|
|
48
|
+
|
|
49
|
+
rerender(
|
|
50
|
+
<NativeDrawer open onOpenChange={onOpenChange} width={320}>
|
|
51
|
+
<span>menu</span>
|
|
52
|
+
</NativeDrawer>
|
|
53
|
+
);
|
|
54
|
+
expect(spy.mock.calls.length).toBeGreaterThan(afterMount);
|
|
55
|
+
spy.mockRestore();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("PanResponder release handler closes drawer on far-enough swipe (uses fresh side)", () => {
|
|
59
|
+
// Capture the latest config and drive its onPanResponderRelease with
|
|
60
|
+
// a synthetic gesture state past the dismiss threshold for `side="right"`.
|
|
61
|
+
// If the closure had baked in `side="left"` from a prior render, the
|
|
62
|
+
// dx>0 swipe would NOT trigger dismiss (left-side drawer dismisses
|
|
63
|
+
// on negative dx). The fact that it dismisses confirms the closure
|
|
64
|
+
// is fresh.
|
|
65
|
+
const configs: Array<Parameters<typeof PanResponder.create>[0]> = [];
|
|
66
|
+
const spy = vi
|
|
67
|
+
.spyOn(PanResponder, "create")
|
|
68
|
+
.mockImplementation((cfg) => {
|
|
69
|
+
configs.push(cfg);
|
|
70
|
+
return { panHandlers: {} } as unknown as ReturnType<
|
|
71
|
+
typeof PanResponder.create
|
|
72
|
+
>;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const onOpenChange = vi.fn();
|
|
76
|
+
const { rerender } = render(
|
|
77
|
+
<NativeDrawer open onOpenChange={onOpenChange} side="left" width={300}>
|
|
78
|
+
<span>menu</span>
|
|
79
|
+
</NativeDrawer>
|
|
80
|
+
);
|
|
81
|
+
rerender(
|
|
82
|
+
<NativeDrawer open onOpenChange={onOpenChange} side="right" width={300}>
|
|
83
|
+
<span>menu</span>
|
|
84
|
+
</NativeDrawer>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const latest = configs[configs.length - 1];
|
|
88
|
+
expect(latest).toBeDefined();
|
|
89
|
+
// For side="right", dismiss when dx > drawerWidth/3 == 100.
|
|
90
|
+
latest?.onPanResponderRelease?.(
|
|
91
|
+
{} as never,
|
|
92
|
+
{ dx: 150, dy: 0 } as never
|
|
93
|
+
);
|
|
94
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
95
|
+
|
|
96
|
+
spy.mockRestore();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { NativeEmptyState } from "../empty-state";
|
|
4
|
+
|
|
5
|
+
describe("NativeEmptyState (E6 web parity)", () => {
|
|
6
|
+
it("renders illustration + title + body + primary action with testID hooks", () => {
|
|
7
|
+
render(
|
|
8
|
+
<NativeEmptyState
|
|
9
|
+
testID="es"
|
|
10
|
+
variant="first-run"
|
|
11
|
+
illustration={<span data-testid="art">art</span>}
|
|
12
|
+
title="Welcome"
|
|
13
|
+
body="Save things here."
|
|
14
|
+
primaryAction={
|
|
15
|
+
<button data-testid="cta" type="button">
|
|
16
|
+
Add entry
|
|
17
|
+
</button>
|
|
18
|
+
}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByTestId("es")).toBeTruthy();
|
|
22
|
+
expect(screen.getByTestId("es-title").textContent).toBe("Welcome");
|
|
23
|
+
expect(screen.getByTestId("es-body").textContent).toBe("Save things here.");
|
|
24
|
+
expect(screen.getByTestId("es-primary-action")).toBeTruthy();
|
|
25
|
+
expect(screen.getByTestId("art")).toBeTruthy();
|
|
26
|
+
expect(screen.getByTestId("cta")).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("supports both primary + secondary actions stacked", () => {
|
|
30
|
+
render(
|
|
31
|
+
<NativeEmptyState
|
|
32
|
+
testID="es2"
|
|
33
|
+
variant="no-results"
|
|
34
|
+
title="Nothing"
|
|
35
|
+
primaryAction={<button type="button">Retry</button>}
|
|
36
|
+
secondaryAction={<button type="button">Clear</button>}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
expect(screen.getByTestId("es2-primary-action")).toBeTruthy();
|
|
40
|
+
expect(screen.getByTestId("es2-secondary-action")).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("falls back to description for back-compat with C3 API", () => {
|
|
44
|
+
render(
|
|
45
|
+
<NativeEmptyState
|
|
46
|
+
testID="es3"
|
|
47
|
+
variant="error"
|
|
48
|
+
description="Legacy body"
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
expect(screen.getByTestId("es3-body").textContent).toBe("Legacy body");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("renders details only in dev environments", () => {
|
|
55
|
+
render(
|
|
56
|
+
<NativeEmptyState
|
|
57
|
+
testID="es4"
|
|
58
|
+
variant="error"
|
|
59
|
+
title="Boom"
|
|
60
|
+
details="stack trace x"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
// NODE_ENV under vitest is "test", which we treat as non-production.
|
|
64
|
+
expect(screen.getByTestId("es4-details").textContent).toBe("stack trace x");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { NativeHeaderCard } from "../header-card";
|
|
4
|
+
|
|
5
|
+
describe("NativeHeaderCard", () => {
|
|
6
|
+
it("renders title, body, footer slots", () => {
|
|
7
|
+
render(
|
|
8
|
+
<NativeHeaderCard
|
|
9
|
+
testID="test-card"
|
|
10
|
+
title="Profile"
|
|
11
|
+
description="Account details"
|
|
12
|
+
body={<span data-testid="body-content">Body</span>}
|
|
13
|
+
footer={<button type="button">Save</button>}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
expect(screen.getByTestId("test-card")).toBeTruthy();
|
|
17
|
+
expect(screen.getByTestId("test-card-title").textContent).toBe("Profile");
|
|
18
|
+
expect(screen.getByTestId("test-card-description").textContent).toBe(
|
|
19
|
+
"Account details"
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByTestId("test-card-body")).toBeTruthy();
|
|
22
|
+
expect(screen.getByTestId("body-content")).toBeTruthy();
|
|
23
|
+
expect(screen.getByTestId("test-card-footer")).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("omits body and footer when not provided", () => {
|
|
27
|
+
render(<NativeHeaderCard testID="t" title="Title only" />);
|
|
28
|
+
expect(screen.queryByTestId("t-body")).toBeNull();
|
|
29
|
+
expect(screen.queryByTestId("t-footer")).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
});
|