@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
AuthBranding,
|
|
5
|
+
AuthForm,
|
|
6
|
+
ForgotPasswordLink,
|
|
7
|
+
SocialAuthRow,
|
|
8
|
+
} from "../auth";
|
|
9
|
+
|
|
10
|
+
describe("AuthBranding", () => {
|
|
11
|
+
it("renders logo, headline, and subhead slots", () => {
|
|
12
|
+
render(
|
|
13
|
+
<AuthBranding
|
|
14
|
+
testID="brand"
|
|
15
|
+
logo={<span data-testid="brand-logo-content">L</span>}
|
|
16
|
+
headline="Welcome to Genesis"
|
|
17
|
+
subhead="Sign in to continue"
|
|
18
|
+
/>,
|
|
19
|
+
);
|
|
20
|
+
expect(screen.getByTestId("brand-logo")).toBeTruthy();
|
|
21
|
+
expect(screen.getByTestId("brand-headline").textContent).toBe(
|
|
22
|
+
"Welcome to Genesis",
|
|
23
|
+
);
|
|
24
|
+
expect(screen.getByTestId("brand-subhead").textContent).toBe(
|
|
25
|
+
"Sign in to continue",
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("omits slots when not provided", () => {
|
|
30
|
+
render(<AuthBranding testID="brand" headline="Just a title" />);
|
|
31
|
+
expect(screen.queryByTestId("brand-logo")).toBeNull();
|
|
32
|
+
expect(screen.queryByTestId("brand-subhead")).toBeNull();
|
|
33
|
+
expect(screen.getByTestId("brand-headline")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("SocialAuthRow", () => {
|
|
38
|
+
it("renders one button per provider and dispatches onPress", () => {
|
|
39
|
+
const apple = vi.fn();
|
|
40
|
+
const google = vi.fn();
|
|
41
|
+
render(
|
|
42
|
+
<SocialAuthRow
|
|
43
|
+
testID="social"
|
|
44
|
+
providers={[
|
|
45
|
+
{ id: "apple", label: "Continue with Apple", onPress: apple },
|
|
46
|
+
{ id: "google", label: "Continue with Google", onPress: google },
|
|
47
|
+
]}
|
|
48
|
+
/>,
|
|
49
|
+
);
|
|
50
|
+
fireEvent.click(screen.getByTestId("social-apple"));
|
|
51
|
+
expect(apple).toHaveBeenCalled();
|
|
52
|
+
fireEvent.click(screen.getByTestId("social-google"));
|
|
53
|
+
expect(google).toHaveBeenCalled();
|
|
54
|
+
expect(screen.getByTestId("social-separator")).toBeTruthy();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("hides separator when separator=null", () => {
|
|
58
|
+
render(
|
|
59
|
+
<SocialAuthRow
|
|
60
|
+
testID="social"
|
|
61
|
+
separator={null}
|
|
62
|
+
providers={[
|
|
63
|
+
{ id: "apple", label: "Continue", onPress: () => {} },
|
|
64
|
+
]}
|
|
65
|
+
/>,
|
|
66
|
+
);
|
|
67
|
+
expect(screen.queryByTestId("social-separator")).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("renders nothing when providers list is empty", () => {
|
|
71
|
+
render(<SocialAuthRow testID="social" providers={[]} />);
|
|
72
|
+
expect(screen.queryByTestId("social")).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("AuthForm", () => {
|
|
77
|
+
it("submits values when form is valid", () => {
|
|
78
|
+
const onSubmit = vi.fn();
|
|
79
|
+
render(<AuthForm testID="auth" onSubmit={onSubmit} />);
|
|
80
|
+
fireEvent.change(screen.getByTestId("auth-email"), {
|
|
81
|
+
target: { value: "user@example.com" },
|
|
82
|
+
});
|
|
83
|
+
fireEvent.change(screen.getByTestId("auth-password"), {
|
|
84
|
+
target: { value: "secret" },
|
|
85
|
+
});
|
|
86
|
+
fireEvent.click(screen.getByTestId("auth-submit"));
|
|
87
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
88
|
+
email: "user@example.com",
|
|
89
|
+
password: "secret",
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("blocks submission when email missing and shows error", () => {
|
|
94
|
+
const onSubmit = vi.fn();
|
|
95
|
+
render(<AuthForm testID="auth" onSubmit={onSubmit} />);
|
|
96
|
+
fireEvent.click(screen.getByTestId("auth-submit"));
|
|
97
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
98
|
+
expect(screen.getByTestId("auth-error").textContent).toMatch(/email/i);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("hides password field in magic-link mode", () => {
|
|
102
|
+
render(
|
|
103
|
+
<AuthForm
|
|
104
|
+
testID="auth"
|
|
105
|
+
mode="magic-link"
|
|
106
|
+
onSubmit={() => {}}
|
|
107
|
+
/>,
|
|
108
|
+
);
|
|
109
|
+
expect(screen.queryByTestId("auth-password")).toBeNull();
|
|
110
|
+
expect(screen.getByTestId("auth-submit").textContent).toMatch(
|
|
111
|
+
/magic link/i,
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("shows server-supplied errorMessage above submit", () => {
|
|
116
|
+
render(
|
|
117
|
+
<AuthForm
|
|
118
|
+
testID="auth"
|
|
119
|
+
onSubmit={() => {}}
|
|
120
|
+
errorMessage="Invalid credentials"
|
|
121
|
+
/>,
|
|
122
|
+
);
|
|
123
|
+
expect(screen.getByTestId("auth-error").textContent).toBe(
|
|
124
|
+
"Invalid credentials",
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("uses custom validate hook when provided", () => {
|
|
129
|
+
const validate = vi.fn(() => "Bad input");
|
|
130
|
+
render(<AuthForm testID="auth" onSubmit={() => {}} validate={validate} />);
|
|
131
|
+
fireEvent.change(screen.getByTestId("auth-email"), {
|
|
132
|
+
target: { value: "x@y.z" },
|
|
133
|
+
});
|
|
134
|
+
fireEvent.change(screen.getByTestId("auth-password"), {
|
|
135
|
+
target: { value: "p" },
|
|
136
|
+
});
|
|
137
|
+
fireEvent.click(screen.getByTestId("auth-submit"));
|
|
138
|
+
expect(validate).toHaveBeenCalled();
|
|
139
|
+
expect(screen.getByTestId("auth-error").textContent).toBe("Bad input");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("ForgotPasswordLink", () => {
|
|
144
|
+
it("calls onPress when tapped", () => {
|
|
145
|
+
const onPress = vi.fn();
|
|
146
|
+
render(<ForgotPasswordLink onPress={onPress} testID="forgot" />);
|
|
147
|
+
fireEvent.click(screen.getByTestId("forgot"));
|
|
148
|
+
expect(onPress).toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
NavBarSaveButton,
|
|
5
|
+
NavBarSearchBar,
|
|
6
|
+
NavBarTitle,
|
|
7
|
+
} from "../nav-bar";
|
|
8
|
+
|
|
9
|
+
describe("NavBarSaveButton", () => {
|
|
10
|
+
it("calls onPress when pressed and not disabled", () => {
|
|
11
|
+
const onPress = vi.fn();
|
|
12
|
+
render(<NavBarSaveButton onPress={onPress} testID="save" />);
|
|
13
|
+
fireEvent.click(screen.getByTestId("save"));
|
|
14
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("does not call onPress when disabled", () => {
|
|
18
|
+
const onPress = vi.fn();
|
|
19
|
+
render(<NavBarSaveButton onPress={onPress} disabled testID="save" />);
|
|
20
|
+
fireEvent.click(screen.getByTestId("save"));
|
|
21
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("renders busy indicator when loading", () => {
|
|
25
|
+
render(<NavBarSaveButton onPress={() => {}} loading testID="save" />);
|
|
26
|
+
expect(screen.getByTestId("save").textContent).toBe("…");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("NavBarTitle", () => {
|
|
31
|
+
it("renders title and optional subtitle", () => {
|
|
32
|
+
render(
|
|
33
|
+
<NavBarTitle testID="title" title="Inbox" subtitle="3 unread" />,
|
|
34
|
+
);
|
|
35
|
+
expect(screen.getByTestId("title-title").textContent).toBe("Inbox");
|
|
36
|
+
expect(screen.getByTestId("title-subtitle").textContent).toBe("3 unread");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("becomes pressable when onPress passed", () => {
|
|
40
|
+
const onPress = vi.fn();
|
|
41
|
+
render(<NavBarTitle testID="title" title="Tap me" onPress={onPress} />);
|
|
42
|
+
fireEvent.click(screen.getByTestId("title"));
|
|
43
|
+
expect(onPress).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("NavBarSearchBar", () => {
|
|
48
|
+
it("calls onChangeText when user types", () => {
|
|
49
|
+
const onChangeText = vi.fn();
|
|
50
|
+
render(
|
|
51
|
+
<NavBarSearchBar
|
|
52
|
+
testID="search"
|
|
53
|
+
value=""
|
|
54
|
+
onChangeText={onChangeText}
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
fireEvent.change(screen.getByTestId("search-input"), {
|
|
58
|
+
target: { value: "abc" },
|
|
59
|
+
});
|
|
60
|
+
expect(onChangeText).toHaveBeenCalledWith("abc");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("shows clear button when value present and clears on press", () => {
|
|
64
|
+
const onChangeText = vi.fn();
|
|
65
|
+
render(
|
|
66
|
+
<NavBarSearchBar
|
|
67
|
+
testID="search"
|
|
68
|
+
value="hello"
|
|
69
|
+
onChangeText={onChangeText}
|
|
70
|
+
/>,
|
|
71
|
+
);
|
|
72
|
+
fireEvent.click(screen.getByTestId("search-clear"));
|
|
73
|
+
expect(onChangeText).toHaveBeenCalledWith("");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("hides clear button when value empty", () => {
|
|
77
|
+
render(
|
|
78
|
+
<NavBarSearchBar
|
|
79
|
+
testID="search"
|
|
80
|
+
value=""
|
|
81
|
+
onChangeText={() => {}}
|
|
82
|
+
/>,
|
|
83
|
+
);
|
|
84
|
+
expect(screen.queryByTestId("search-clear")).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
NotificationsPage,
|
|
5
|
+
__test,
|
|
6
|
+
getNotificationsPageStackOptions,
|
|
7
|
+
type NotificationItem,
|
|
8
|
+
} from "../notifications-page";
|
|
9
|
+
|
|
10
|
+
const NOW = new Date("2026-05-04T10:00:00Z");
|
|
11
|
+
|
|
12
|
+
describe("NotificationsPage groupByDate", () => {
|
|
13
|
+
it("buckets items by Today / Yesterday / Earlier", () => {
|
|
14
|
+
const items: NotificationItem[] = [
|
|
15
|
+
{ id: "1", title: "Today A", timestamp: "2026-05-04T08:00:00Z" },
|
|
16
|
+
{ id: "2", title: "Yesterday A", timestamp: "2026-05-03T20:00:00Z" },
|
|
17
|
+
{ id: "3", title: "Older", timestamp: "2026-05-01T08:00:00Z" },
|
|
18
|
+
{ id: "4", title: "Today B", timestamp: "2026-05-04T09:00:00Z" },
|
|
19
|
+
];
|
|
20
|
+
const sections = __test.groupByDate(items, NOW);
|
|
21
|
+
expect(sections.map((s) => s.title)).toEqual([
|
|
22
|
+
"Today",
|
|
23
|
+
"Yesterday",
|
|
24
|
+
"Earlier",
|
|
25
|
+
]);
|
|
26
|
+
expect(sections[0].data).toHaveLength(2);
|
|
27
|
+
expect(sections[1].data).toHaveLength(1);
|
|
28
|
+
expect(sections[2].data).toHaveLength(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("omits empty buckets", () => {
|
|
32
|
+
const items: NotificationItem[] = [
|
|
33
|
+
{ id: "1", title: "Today only", timestamp: NOW.toISOString() },
|
|
34
|
+
];
|
|
35
|
+
const sections = __test.groupByDate(items, NOW);
|
|
36
|
+
expect(sections.map((s) => s.title)).toEqual(["Today"]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("NotificationsPage rendering", () => {
|
|
41
|
+
it("renders empty state when no items", () => {
|
|
42
|
+
render(<NotificationsPage testID="notifs" items={[]} />);
|
|
43
|
+
expect(screen.getByTestId("notifs-empty")).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("renders sectioned list when items present", () => {
|
|
47
|
+
render(
|
|
48
|
+
<NotificationsPage
|
|
49
|
+
testID="notifs"
|
|
50
|
+
items={[
|
|
51
|
+
{
|
|
52
|
+
id: "1",
|
|
53
|
+
title: "Welcome",
|
|
54
|
+
timestamp: NOW.toISOString(),
|
|
55
|
+
unread: true,
|
|
56
|
+
},
|
|
57
|
+
]}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
expect(screen.getByTestId("notifs-list")).toBeTruthy();
|
|
61
|
+
expect(screen.getByTestId("notifs-row-1")).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("uses custom emptyState when provided", () => {
|
|
65
|
+
render(
|
|
66
|
+
<NotificationsPage
|
|
67
|
+
testID="notifs"
|
|
68
|
+
items={[]}
|
|
69
|
+
emptyState={<span data-testid="custom-empty">Custom</span>}
|
|
70
|
+
/>,
|
|
71
|
+
);
|
|
72
|
+
expect(screen.getByTestId("custom-empty")).toBeTruthy();
|
|
73
|
+
expect(screen.queryByTestId("notifs-empty")).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("getNotificationsPageStackOptions", () => {
|
|
78
|
+
it("wires Mark all read button when onMarkAllRead provided", () => {
|
|
79
|
+
const onMarkAllRead = vi.fn();
|
|
80
|
+
const opts = getNotificationsPageStackOptions({ onMarkAllRead });
|
|
81
|
+
expect(typeof opts.headerRight).toBe("function");
|
|
82
|
+
expect(opts.headerLargeTitle).toBe(true);
|
|
83
|
+
expect(opts.title).toBe("Notifications");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("respects header right override", () => {
|
|
87
|
+
const customRight = () => null;
|
|
88
|
+
const opts = getNotificationsPageStackOptions({
|
|
89
|
+
onMarkAllRead: () => {},
|
|
90
|
+
headerRight: customRight,
|
|
91
|
+
});
|
|
92
|
+
expect(opts.headerRight).toBe(customRight);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
ScreenContainer,
|
|
5
|
+
composeHeaderOptions,
|
|
6
|
+
} from "../screen-container";
|
|
7
|
+
|
|
8
|
+
describe("ScreenContainer", () => {
|
|
9
|
+
it("renders children with default safe-area edges", () => {
|
|
10
|
+
render(
|
|
11
|
+
<ScreenContainer testID="screen">
|
|
12
|
+
<span data-testid="child">Hello</span>
|
|
13
|
+
</ScreenContainer>,
|
|
14
|
+
);
|
|
15
|
+
expect(screen.getByTestId("screen")).toBeTruthy();
|
|
16
|
+
expect(screen.getByTestId("child")).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("wraps body in a scroll container when scroll=true", () => {
|
|
20
|
+
render(
|
|
21
|
+
<ScreenContainer testID="screen" scroll>
|
|
22
|
+
<span>Hello</span>
|
|
23
|
+
</ScreenContainer>,
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByTestId("screen-scroll")).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("uses static body container when scroll=false", () => {
|
|
29
|
+
render(
|
|
30
|
+
<ScreenContainer testID="screen">
|
|
31
|
+
<span>Hello</span>
|
|
32
|
+
</ScreenContainer>,
|
|
33
|
+
);
|
|
34
|
+
expect(screen.queryByTestId("screen-scroll")).toBeNull();
|
|
35
|
+
expect(screen.getByTestId("screen-body")).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("composeHeaderOptions", () => {
|
|
40
|
+
it("returns empty object for no props", () => {
|
|
41
|
+
expect(composeHeaderOptions({})).toEqual({});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("maps headerTitle → title", () => {
|
|
45
|
+
expect(composeHeaderOptions({ headerTitle: "Settings" })).toEqual({
|
|
46
|
+
title: "Settings",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("sets headerLargeTitle when large=true", () => {
|
|
51
|
+
const opts = composeHeaderOptions({ large: true });
|
|
52
|
+
expect(opts.headerLargeTitle).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("sets headerTransparent when scrollEdgeBehavior=transparent + large", () => {
|
|
56
|
+
const opts = composeHeaderOptions({
|
|
57
|
+
large: true,
|
|
58
|
+
scrollEdgeBehavior: "transparent",
|
|
59
|
+
});
|
|
60
|
+
expect(opts.headerTransparent).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("direct headerOptions wins over named props", () => {
|
|
64
|
+
const opts = composeHeaderOptions({
|
|
65
|
+
headerTitle: "Original",
|
|
66
|
+
headerOptions: { title: "Override", custom: 42 },
|
|
67
|
+
});
|
|
68
|
+
expect(opts.title).toBe("Override");
|
|
69
|
+
expect(opts.custom).toBe(42);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("forwards headerLeft / headerRight callables", () => {
|
|
73
|
+
const left = () => null;
|
|
74
|
+
const right = () => null;
|
|
75
|
+
const opts = composeHeaderOptions({ headerLeft: left, headerRight: right });
|
|
76
|
+
expect(opts.headerLeft).toBe(left);
|
|
77
|
+
expect(opts.headerRight).toBe(right);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
SettingsPage,
|
|
5
|
+
getSettingsPageStackOptions,
|
|
6
|
+
} from "../settings-page";
|
|
7
|
+
|
|
8
|
+
describe("SettingsPage", () => {
|
|
9
|
+
it("renders sectioned rows", () => {
|
|
10
|
+
render(
|
|
11
|
+
<SettingsPage
|
|
12
|
+
testID="settings"
|
|
13
|
+
sections={[
|
|
14
|
+
{
|
|
15
|
+
id: "account",
|
|
16
|
+
title: "Account",
|
|
17
|
+
rows: [
|
|
18
|
+
{ id: "name", title: "Name", subtitle: "Mark" },
|
|
19
|
+
{ id: "email", title: "Email", subtitle: "mark@x.com" },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "prefs",
|
|
24
|
+
title: "Preferences",
|
|
25
|
+
rows: [{ id: "theme", title: "Theme", showChevron: true }],
|
|
26
|
+
},
|
|
27
|
+
]}
|
|
28
|
+
/>,
|
|
29
|
+
);
|
|
30
|
+
expect(screen.getByTestId("settings-section-account")).toBeTruthy();
|
|
31
|
+
expect(screen.getByTestId("settings-section-prefs")).toBeTruthy();
|
|
32
|
+
expect(screen.getByTestId("settings-row-name")).toBeTruthy();
|
|
33
|
+
expect(screen.getByTestId("settings-row-email")).toBeTruthy();
|
|
34
|
+
expect(screen.getByTestId("settings-row-theme")).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("invokes row onPress when pressed", () => {
|
|
38
|
+
const onPress = vi.fn();
|
|
39
|
+
render(
|
|
40
|
+
<SettingsPage
|
|
41
|
+
testID="settings"
|
|
42
|
+
sections={[
|
|
43
|
+
{
|
|
44
|
+
id: "s1",
|
|
45
|
+
rows: [{ id: "r1", title: "Logout", onPress }],
|
|
46
|
+
},
|
|
47
|
+
]}
|
|
48
|
+
/>,
|
|
49
|
+
);
|
|
50
|
+
fireEvent.click(screen.getByTestId("settings-row-r1"));
|
|
51
|
+
expect(onPress).toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("renders dangerousActions footer with destructive buttons", () => {
|
|
55
|
+
const signOut = vi.fn();
|
|
56
|
+
const deleteAcct = vi.fn();
|
|
57
|
+
render(
|
|
58
|
+
<SettingsPage
|
|
59
|
+
testID="settings"
|
|
60
|
+
sections={[
|
|
61
|
+
{ id: "s1", rows: [{ id: "r1", title: "Item" }] },
|
|
62
|
+
]}
|
|
63
|
+
dangerousActions={[
|
|
64
|
+
{ label: "Sign out", onPress: signOut },
|
|
65
|
+
{
|
|
66
|
+
label: "Delete account",
|
|
67
|
+
onPress: deleteAcct,
|
|
68
|
+
emphasized: true,
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
/>,
|
|
72
|
+
);
|
|
73
|
+
expect(screen.getByTestId("settings-dangerous-actions")).toBeTruthy();
|
|
74
|
+
fireEvent.click(screen.getByTestId("settings-danger-sign-out"));
|
|
75
|
+
expect(signOut).toHaveBeenCalled();
|
|
76
|
+
fireEvent.click(screen.getByTestId("settings-danger-delete-account"));
|
|
77
|
+
expect(deleteAcct).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("section title is omitted when not provided", () => {
|
|
81
|
+
render(
|
|
82
|
+
<SettingsPage
|
|
83
|
+
testID="settings"
|
|
84
|
+
sections={[
|
|
85
|
+
{
|
|
86
|
+
id: "untitled",
|
|
87
|
+
rows: [{ id: "r1", title: "Item" }],
|
|
88
|
+
},
|
|
89
|
+
]}
|
|
90
|
+
/>,
|
|
91
|
+
);
|
|
92
|
+
expect(screen.queryByTestId("settings-section-untitled-header")).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("getSettingsPageStackOptions", () => {
|
|
97
|
+
it("defaults to large=true and scrollEdgeBehavior=match", () => {
|
|
98
|
+
const opts = getSettingsPageStackOptions({});
|
|
99
|
+
expect(opts.headerLargeTitle).toBe(true);
|
|
100
|
+
expect(opts.title).toBe("Settings");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("overrides default title via headerTitle prop", () => {
|
|
104
|
+
const opts = getSettingsPageStackOptions({ headerTitle: "Profile" });
|
|
105
|
+
expect(opts.title).toBe("Profile");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
SettingsSubPage,
|
|
5
|
+
confirmDiscardChanges,
|
|
6
|
+
getSettingsSubPageStackOptions,
|
|
7
|
+
} from "../settings-sub-page";
|
|
8
|
+
|
|
9
|
+
describe("SettingsSubPage", () => {
|
|
10
|
+
it("renders form children inside KeyboardAvoidingView", () => {
|
|
11
|
+
render(
|
|
12
|
+
<SettingsSubPage testID="sub" onSave={() => {}}>
|
|
13
|
+
<span data-testid="field">Field</span>
|
|
14
|
+
</SettingsSubPage>,
|
|
15
|
+
);
|
|
16
|
+
expect(screen.getByTestId("sub-kav")).toBeTruthy();
|
|
17
|
+
expect(screen.getByTestId("sub-form")).toBeTruthy();
|
|
18
|
+
expect(screen.getByTestId("field")).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("getSettingsSubPageStackOptions", () => {
|
|
23
|
+
it("wires save button to headerRight when onSave provided", () => {
|
|
24
|
+
const onSave = vi.fn();
|
|
25
|
+
const opts = getSettingsSubPageStackOptions({
|
|
26
|
+
headerTitle: "Edit profile",
|
|
27
|
+
onSave,
|
|
28
|
+
dirty: true,
|
|
29
|
+
});
|
|
30
|
+
expect(opts.title).toBe("Edit profile");
|
|
31
|
+
expect(typeof opts.headerRight).toBe("function");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("does not render save button when no onSave", () => {
|
|
35
|
+
const opts = getSettingsSubPageStackOptions({ headerTitle: "Read only" });
|
|
36
|
+
expect(opts.headerRight).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("respects custom headerRight override", () => {
|
|
40
|
+
const customRight = () => null;
|
|
41
|
+
const opts = getSettingsSubPageStackOptions({
|
|
42
|
+
onSave: () => {},
|
|
43
|
+
headerRight: customRight,
|
|
44
|
+
});
|
|
45
|
+
expect(opts.headerRight).toBe(customRight);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("confirmDiscardChanges", () => {
|
|
50
|
+
it("is callable without throwing (Alert is shimmed in tests)", () => {
|
|
51
|
+
expect(() => confirmDiscardChanges(() => {})).not.toThrow();
|
|
52
|
+
});
|
|
53
|
+
});
|