@marktiderman/genesis-ui-native 2.1.0 → 2.3.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/README.md +134 -0
- package/dist/chunk-7PCWEY6R.js +27 -0
- package/dist/chunk-7PCWEY6R.js.map +1 -0
- package/dist/chunk-D5RKSPMH.js +24 -0
- package/dist/chunk-D5RKSPMH.js.map +1 -0
- package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
- package/dist/chunk-EFXCJ5AN.js.map +1 -0
- package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
- package/dist/chunk-ERHGCWTY.js.map +1 -0
- package/dist/{chunk-3LK5ZJ4M.js → chunk-FIITITXO.js} +67 -108
- package/dist/chunk-FIITITXO.js.map +1 -0
- package/dist/chunk-FZY2IXOX.js +1559 -0
- package/dist/chunk-FZY2IXOX.js.map +1 -0
- package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
- package/dist/chunk-W7BK3ARU.js.map +1 -0
- package/dist/components/index.d.ts +143 -17
- package/dist/components/index.js +6 -4
- package/dist/data/index.d.ts +7 -1
- package/dist/data/index.js +31 -6
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/icons/lucide.d.ts +7 -0
- package/dist/icons/lucide.js +47 -0
- package/dist/icons/lucide.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/dist/layouts/index.d.ts +399 -7
- package/dist/layouts/index.js +3 -3
- package/dist/native-modules-BSVaEb3D.d.ts +206 -0
- package/package.json +34 -5
- package/src/__tests__/fake-modules.tsx +134 -0
- package/src/__tests__/native-modules-lists.test.tsx +70 -0
- package/src/__tests__/native-modules.test.tsx +631 -0
- package/src/components/__tests__/sheet.test.tsx +193 -0
- package/src/components/__tests__/toast.test.tsx +15 -0
- package/src/components/avatar.tsx +69 -16
- package/src/components/date-time-picker.tsx +128 -10
- package/src/components/drawer.tsx +158 -68
- package/src/components/dropdown-menu.tsx +7 -6
- package/src/components/glass-surface.tsx +150 -0
- package/src/components/icon.tsx +66 -0
- package/src/components/image.tsx +89 -0
- package/src/components/index.ts +33 -2
- package/src/components/list-item.tsx +29 -9
- package/src/components/popover.tsx +12 -9
- package/src/components/segmented-control.tsx +7 -1
- package/src/components/sheet.tsx +276 -133
- package/src/components/skeleton.tsx +75 -53
- package/src/components/textarea.tsx +1 -0
- package/src/components/toast.tsx +185 -87
- package/src/data/NativeResourcePage.tsx +48 -3
- package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
- package/src/hooks/use-reduced-motion.ts +24 -10
- package/src/icon-names.ts +49 -0
- package/src/icons/lucide.ts +88 -0
- package/src/layouts/__tests__/apple-sign-in.test.tsx +97 -0
- package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
- package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
- package/src/layouts/__tests__/thread-page.test.tsx +128 -0
- package/src/layouts/apple-sign-in.tsx +136 -0
- package/src/layouts/auth-screen.tsx +17 -8
- package/src/layouts/auth.tsx +29 -19
- package/src/layouts/google-sign-in.tsx +42 -0
- package/src/layouts/inbox-page.tsx +408 -0
- package/src/layouts/index.ts +45 -2
- package/src/layouts/keyboard.tsx +61 -9
- package/src/layouts/notifications-page.tsx +133 -16
- package/src/layouts/screen-container.tsx +6 -2
- package/src/layouts/settings-page.tsx +117 -14
- package/src/layouts/settings-sub-page.tsx +9 -3
- package/src/layouts/thread-page.tsx +444 -0
- package/src/native-modules.tsx +186 -0
- package/dist/chunk-3LK5ZJ4M.js.map +0 -1
- package/dist/chunk-5HRGIA6F.js.map +0 -1
- package/dist/chunk-F2TGDKOO.js +0 -43
- package/dist/chunk-F2TGDKOO.js.map +0 -1
- package/dist/chunk-TXJT55JC.js.map +0 -1
- package/dist/chunk-U2SPACTV.js +0 -876
- package/dist/chunk-U2SPACTV.js.map +0 -1
- package/dist/chunk-ULS7I6ZS.js.map +0 -1
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useReducedMotion — subscribe to the OS reduce-motion preference.
|
|
3
3
|
*
|
|
4
|
-
* Returns `true` when the user has enabled reduce-motion at the OS level
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Returns `true` when the user has enabled reduce-motion at the OS level,
|
|
5
|
+
* and follows the setting while the app runs (Reanimated's own hook reads it
|
|
6
|
+
* once at launch). Components that animate (Sheet, Drawer, Toast, Skeleton)
|
|
7
|
+
* honor it by skipping non-essential transitions and snapping into the
|
|
8
|
+
* final state.
|
|
7
9
|
*
|
|
8
10
|
* @stability Beta
|
|
9
11
|
*/
|
|
10
12
|
import { useEffect, useState } from "react";
|
|
11
13
|
import { AccessibilityInfo } from "react-native";
|
|
12
14
|
|
|
15
|
+
// The last answer anyone got: a component mounting later (a toast, an open
|
|
16
|
+
// drawer) starts from it instead of animating for a frame before it hears.
|
|
17
|
+
let lastKnown = false;
|
|
18
|
+
|
|
19
|
+
/** Tests only: forget the last answer. Not exported from the package. */
|
|
20
|
+
export function __resetReducedMotion() {
|
|
21
|
+
lastKnown = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
export function useReducedMotion(): boolean {
|
|
14
|
-
const [reduced, setReduced] = useState(
|
|
25
|
+
const [reduced, setReduced] = useState(lastKnown);
|
|
15
26
|
|
|
16
27
|
useEffect(() => {
|
|
17
28
|
let mounted = true;
|
|
18
|
-
|
|
29
|
+
const set = (v: boolean) => {
|
|
30
|
+
lastKnown = v;
|
|
19
31
|
if (mounted) setReduced(v);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
|
|
32
|
+
};
|
|
33
|
+
AccessibilityInfo.isReduceMotionEnabled()
|
|
34
|
+
.then(set)
|
|
35
|
+
// Some runtimes (web, older Android) reject when the accessibility
|
|
36
|
+
// manager isn't wired up: treat that as "no preference".
|
|
37
|
+
.catch(() => {});
|
|
38
|
+
const sub = AccessibilityInfo.addEventListener("reduceMotionChanged", set);
|
|
25
39
|
return () => {
|
|
26
40
|
mounted = false;
|
|
27
41
|
sub?.remove?.();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The semantic icon names Genesis components ask for, and the SF Symbol each
|
|
3
|
+
* one draws on iOS. Components say "settings" or "bell", never a library's
|
|
4
|
+
* own name; `lucideIcons` (`/icons/lucide`) maps the same names for Android,
|
|
5
|
+
* web and the SF Symbol fallback.
|
|
6
|
+
*
|
|
7
|
+
* @stability Beta
|
|
8
|
+
*/
|
|
9
|
+
export const SF_SYMBOLS = {
|
|
10
|
+
"arrow-left": "arrow.left",
|
|
11
|
+
bell: "bell",
|
|
12
|
+
calendar: "calendar",
|
|
13
|
+
check: "checkmark",
|
|
14
|
+
"chevron-down": "chevron.down",
|
|
15
|
+
"chevron-left": "chevron.left",
|
|
16
|
+
"chevron-right": "chevron.right",
|
|
17
|
+
"chevron-up": "chevron.up",
|
|
18
|
+
clock: "clock",
|
|
19
|
+
close: "xmark",
|
|
20
|
+
edit: "pencil",
|
|
21
|
+
error: "xmark.circle",
|
|
22
|
+
"external-link": "arrow.up.right.square",
|
|
23
|
+
filter: "line.3.horizontal.decrease",
|
|
24
|
+
heart: "heart",
|
|
25
|
+
home: "house",
|
|
26
|
+
info: "info.circle",
|
|
27
|
+
lock: "lock",
|
|
28
|
+
"log-out": "rectangle.portrait.and.arrow.right",
|
|
29
|
+
mail: "envelope",
|
|
30
|
+
menu: "line.3.horizontal",
|
|
31
|
+
minus: "minus",
|
|
32
|
+
more: "ellipsis",
|
|
33
|
+
plus: "plus",
|
|
34
|
+
refresh: "arrow.clockwise",
|
|
35
|
+
search: "magnifyingglass",
|
|
36
|
+
settings: "gearshape",
|
|
37
|
+
share: "square.and.arrow.up",
|
|
38
|
+
star: "star",
|
|
39
|
+
success: "checkmark.circle",
|
|
40
|
+
trash: "trash",
|
|
41
|
+
user: "person",
|
|
42
|
+
warning: "exclamationmark.triangle",
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
/** A semantic icon name: what the icon is for. */
|
|
46
|
+
export type NativeIconName = keyof typeof SF_SYMBOLS;
|
|
47
|
+
|
|
48
|
+
/** Every semantic icon name. */
|
|
49
|
+
export const NATIVE_ICON_NAMES = Object.keys(SF_SYMBOLS) as NativeIconName[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lucideIcons` — the lucide-react-native icon for every semantic name, the
|
|
3
|
+
* icon set `NativeIcon` draws on Android and web (and on iOS when an SF
|
|
4
|
+
* Symbol can't be drawn). Opt in by importing this subpath and passing it as
|
|
5
|
+
* `modules.icons`; the rest of the package never imports lucide.
|
|
6
|
+
*
|
|
7
|
+
* Needs lucide-react-native 0.475 or later (the names below).
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
ArrowLeft,
|
|
13
|
+
Bell,
|
|
14
|
+
Calendar,
|
|
15
|
+
Check,
|
|
16
|
+
ChevronDown,
|
|
17
|
+
ChevronLeft,
|
|
18
|
+
ChevronRight,
|
|
19
|
+
ChevronUp,
|
|
20
|
+
CircleCheck,
|
|
21
|
+
CircleX,
|
|
22
|
+
Clock,
|
|
23
|
+
Ellipsis,
|
|
24
|
+
ExternalLink,
|
|
25
|
+
Funnel,
|
|
26
|
+
Heart,
|
|
27
|
+
House,
|
|
28
|
+
Info,
|
|
29
|
+
Lock,
|
|
30
|
+
LogOut,
|
|
31
|
+
Mail,
|
|
32
|
+
Menu,
|
|
33
|
+
Minus,
|
|
34
|
+
Pencil,
|
|
35
|
+
Plus,
|
|
36
|
+
RefreshCw,
|
|
37
|
+
Search,
|
|
38
|
+
Settings,
|
|
39
|
+
Share,
|
|
40
|
+
Star,
|
|
41
|
+
Trash2,
|
|
42
|
+
TriangleAlert,
|
|
43
|
+
User,
|
|
44
|
+
X,
|
|
45
|
+
} from "lucide-react-native";
|
|
46
|
+
import type { NativeIconName } from "../icon-names";
|
|
47
|
+
import type { GenesisIconComponent } from "../native-modules";
|
|
48
|
+
|
|
49
|
+
export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
50
|
+
"arrow-left": ArrowLeft,
|
|
51
|
+
bell: Bell,
|
|
52
|
+
calendar: Calendar,
|
|
53
|
+
check: Check,
|
|
54
|
+
"chevron-down": ChevronDown,
|
|
55
|
+
"chevron-left": ChevronLeft,
|
|
56
|
+
"chevron-right": ChevronRight,
|
|
57
|
+
"chevron-up": ChevronUp,
|
|
58
|
+
clock: Clock,
|
|
59
|
+
close: X,
|
|
60
|
+
edit: Pencil,
|
|
61
|
+
error: CircleX,
|
|
62
|
+
"external-link": ExternalLink,
|
|
63
|
+
filter: Funnel,
|
|
64
|
+
heart: Heart,
|
|
65
|
+
home: House,
|
|
66
|
+
info: Info,
|
|
67
|
+
lock: Lock,
|
|
68
|
+
"log-out": LogOut,
|
|
69
|
+
mail: Mail,
|
|
70
|
+
menu: Menu,
|
|
71
|
+
minus: Minus,
|
|
72
|
+
more: Ellipsis,
|
|
73
|
+
plus: Plus,
|
|
74
|
+
refresh: RefreshCw,
|
|
75
|
+
search: Search,
|
|
76
|
+
settings: Settings,
|
|
77
|
+
share: Share,
|
|
78
|
+
star: Star,
|
|
79
|
+
success: CircleCheck,
|
|
80
|
+
trash: Trash2,
|
|
81
|
+
user: User,
|
|
82
|
+
warning: TriangleAlert,
|
|
83
|
+
// The cast widens lucide's declared `color: string` to `ColorValue`. On iOS
|
|
84
|
+
// NativeIcon passes theme roles as `PlatformColor` objects; lucide hands
|
|
85
|
+
// `color` to react-native-svg's stroke, whose extractBrush resolves
|
|
86
|
+
// PlatformColor and DynamicColorIOS objects (react-native-svg 15,
|
|
87
|
+
// src/lib/extract/extractBrush.ts).
|
|
88
|
+
} as Record<NativeIconName, GenesisIconComponent>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @feat:account
|
|
2
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Platform } from "react-native";
|
|
5
|
+
import { AuthScreen } from "../auth-screen";
|
|
6
|
+
import { appleProvider, AppleSignInButton, type AppleButtonModuleLike } from "../apple-sign-in";
|
|
7
|
+
|
|
8
|
+
function fakeApple() {
|
|
9
|
+
const seen: Array<{ buttonType: number; buttonStyle: number }> = [];
|
|
10
|
+
const apple: AppleButtonModuleLike = {
|
|
11
|
+
AppleAuthenticationButton: ({ buttonType, buttonStyle, onPress, testID, accessibilityState }) => {
|
|
12
|
+
seen.push({ buttonType, buttonStyle });
|
|
13
|
+
return (
|
|
14
|
+
<button type="button" data-testid={testID} aria-disabled={accessibilityState?.disabled ? "true" : "false"} onClick={onPress}>
|
|
15
|
+
apple-native-button
|
|
16
|
+
</button>
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
AppleAuthenticationButtonType: { SIGN_IN: 0, CONTINUE: 1, SIGN_UP: 2 },
|
|
20
|
+
AppleAuthenticationButtonStyle: { WHITE: 0, WHITE_OUTLINE: 1, BLACK: 2 },
|
|
21
|
+
};
|
|
22
|
+
return { apple, seen };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const form = { onSubmit: vi.fn() };
|
|
26
|
+
const google = { id: "google", label: "Continue with Google", onPress: () => {} };
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
Platform.OS = "ios";
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("appleProvider", () => {
|
|
33
|
+
it("adds Apple's own button to AuthScreen in one line, on iOS", () => {
|
|
34
|
+
const { apple, seen } = fakeApple();
|
|
35
|
+
const onPress = vi.fn();
|
|
36
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple, onPress }), google]} />);
|
|
37
|
+
fireEvent.click(screen.getByTestId("auth-screen-social-apple"));
|
|
38
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(screen.getByText("apple-native-button")).toBeTruthy();
|
|
40
|
+
expect(screen.getByText("Continue with Google")).toBeTruthy();
|
|
41
|
+
expect(seen[0]).toEqual({ buttonType: 1, buttonStyle: 2 });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("is null off iOS or without the module, and AuthScreen skips it", () => {
|
|
45
|
+
const { apple } = fakeApple();
|
|
46
|
+
expect(appleProvider({ apple: undefined, onPress: () => {} })).toBeNull();
|
|
47
|
+
Platform.OS = "android";
|
|
48
|
+
const provider = appleProvider({ apple, onPress: () => {} });
|
|
49
|
+
expect(provider).toBeNull();
|
|
50
|
+
render(<AuthScreen form={form} providers={[provider, google]} />);
|
|
51
|
+
expect(screen.queryByText("apple-native-button")).toBeNull();
|
|
52
|
+
expect(screen.getByText("Continue with Google")).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("keeps the dev warning when Apple is missing on iOS, and stays quiet when it's there", () => {
|
|
56
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
57
|
+
const { apple } = fakeApple();
|
|
58
|
+
const okta = { id: "okta", label: "Okta", onPress: () => {} };
|
|
59
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple, onPress: () => {} }), okta]} />);
|
|
60
|
+
expect(warn).not.toHaveBeenCalled();
|
|
61
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple: undefined, onPress: () => {} }), okta]} />);
|
|
62
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(warn.mock.calls[0]![0]).toContain("appleProvider");
|
|
64
|
+
warn.mockRestore();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("AppleSignInButton", () => {
|
|
69
|
+
it("maps Apple's wording and style, and ignores presses while disabled", () => {
|
|
70
|
+
const { apple, seen } = fakeApple();
|
|
71
|
+
const onPress = vi.fn();
|
|
72
|
+
render(<AppleSignInButton apple={apple} onPress={onPress} type="sign-up" appearance="white-outline" disabled />);
|
|
73
|
+
expect(seen[0]).toEqual({ buttonType: 2, buttonStyle: 1 });
|
|
74
|
+
fireEvent.click(screen.getByTestId("apple-sign-in"));
|
|
75
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
76
|
+
expect(screen.getByTestId("apple-sign-in").getAttribute("aria-disabled")).toBe("true");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ignores a second tap while the first sign-in is still open", async () => {
|
|
80
|
+
const { apple } = fakeApple();
|
|
81
|
+
let finish!: () => void;
|
|
82
|
+
const onPress = vi.fn(() => new Promise<void>((r) => (finish = r)));
|
|
83
|
+
render(<AppleSignInButton apple={apple} onPress={onPress} />);
|
|
84
|
+
const button = screen.getByTestId("apple-sign-in");
|
|
85
|
+
fireEvent.click(button);
|
|
86
|
+
fireEvent.click(button);
|
|
87
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
88
|
+
await act(async () => finish());
|
|
89
|
+
fireEvent.click(button);
|
|
90
|
+
expect(onPress).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("labels the provider to match Apple's wording", () => {
|
|
94
|
+
const { apple } = fakeApple();
|
|
95
|
+
expect(appleProvider({ apple, onPress: () => {}, type: "sign-in" })?.label).toBe("Sign in with Apple");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @feat:account
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { AuthScreen } from "../auth-screen";
|
|
5
|
+
import { googleProvider } from "../google-sign-in";
|
|
6
|
+
|
|
7
|
+
const form = { onSubmit: vi.fn() };
|
|
8
|
+
|
|
9
|
+
describe("googleProvider", () => {
|
|
10
|
+
it("is a provider with Google's wording that AuthScreen draws and presses", () => {
|
|
11
|
+
const onPress = vi.fn();
|
|
12
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
13
|
+
render(<AuthScreen form={form} providers={[googleProvider({ onPress, icon: <span>G</span> })]} />);
|
|
14
|
+
const button = screen.getByTestId("auth-screen-social-google");
|
|
15
|
+
expect(button.textContent).toContain("Continue with Google");
|
|
16
|
+
expect(button.textContent).toContain("G");
|
|
17
|
+
fireEvent.click(button);
|
|
18
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("is null when switched off, so the list takes it as is", () => {
|
|
23
|
+
expect(googleProvider({ onPress: () => {}, enabled: false })).toBeNull();
|
|
24
|
+
expect(googleProvider({ onPress: () => {}, label: "Sign in with Google" })?.label).toBe("Sign in with Google");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @feat:inbox-thread
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { Alert, Platform, StyleSheet } from "react-native";
|
|
6
|
+
import { InboxPage, formatInboxTime, getInboxPageStackOptions, type InboxItem } from "../inbox-page";
|
|
7
|
+
|
|
8
|
+
const NOW = new Date(2026, 9, 24, 15, 0);
|
|
9
|
+
const now = () => NOW;
|
|
10
|
+
|
|
11
|
+
function styleOf(el: Element): Record<string, unknown> {
|
|
12
|
+
return StyleSheet.flatten(JSON.parse((el as HTMLElement).dataset.style ?? "null"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const os = Platform.OS;
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
Platform.OS = os;
|
|
18
|
+
vi.mocked(Alert.alert).mockClear();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const items: InboxItem[] = [
|
|
22
|
+
{ id: "a", title: "Save button does nothing", preview: "Thanks, we're on it.", timestamp: new Date(2026, 9, 24, 9, 41), unreadCount: 2, meta: "In progress", onPress: vi.fn() },
|
|
23
|
+
{ id: "b", title: "Dark mode", preview: "You: please", timestamp: new Date(2026, 9, 23, 12, 0), unread: true },
|
|
24
|
+
{ id: "c", title: "Old one", timestamp: new Date(2026, 8, 1) },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
describe("formatInboxTime", () => {
|
|
28
|
+
it("reads as a time today, Yesterday, a weekday this week, then a date", () => {
|
|
29
|
+
expect(formatInboxTime(new Date(2026, 9, 24, 9, 41), NOW)).toMatch(/9:41/);
|
|
30
|
+
expect(formatInboxTime(new Date(2026, 9, 23, 9, 41), NOW)).toBe("Yesterday");
|
|
31
|
+
expect(formatInboxTime(new Date(2026, 9, 20, 9, 41), NOW)).toBe(new Date(2026, 9, 20).toLocaleDateString(undefined, { weekday: "long" }));
|
|
32
|
+
expect(formatInboxTime(new Date(2026, 8, 1), NOW)).not.toMatch(/2026/);
|
|
33
|
+
expect(formatInboxTime(new Date(2025, 8, 1), NOW)).toMatch(/2025/);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("InboxPage", () => {
|
|
38
|
+
it("shows the empty state, with its action, when there are no items", () => {
|
|
39
|
+
const onEmptyAction = vi.fn();
|
|
40
|
+
render(<InboxPage testID="inbox" items={[]} emptyTitle="No reports" emptyBody="Send one" emptyActionLabel="Send feedback" onEmptyAction={onEmptyAction} />);
|
|
41
|
+
expect(screen.getByTestId("inbox-empty").textContent).toContain("No reports");
|
|
42
|
+
fireEvent.click(screen.getByTestId("inbox-empty-action"));
|
|
43
|
+
expect(onEmptyAction).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("shows a spinner while the first page loads, and an error (with Try again) when the read failed", () => {
|
|
47
|
+
const onRefresh = vi.fn();
|
|
48
|
+
const { unmount } = render(<InboxPage testID="inbox" items={[]} loading emptyTitle="No reports" />);
|
|
49
|
+
expect(screen.getByTestId("inbox-loading")).toBeTruthy();
|
|
50
|
+
expect(screen.queryByTestId("inbox-empty")).toBeNull();
|
|
51
|
+
unmount();
|
|
52
|
+
render(<InboxPage testID="inbox" items={[]} error errorTitle="Couldn't load" onRefresh={onRefresh} />);
|
|
53
|
+
expect(screen.getByTestId("inbox-error").textContent).toContain("Couldn't load");
|
|
54
|
+
fireEvent.click(screen.getByTestId("inbox-error-action"));
|
|
55
|
+
expect(onRefresh).toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("lets a tap in the header (a text field's button) land while the keyboard is up", () => {
|
|
59
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
60
|
+
expect(screen.getByTestId("inbox-list").dataset.keyboardShouldPersistTaps).toBe("handled");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("renders every row with its time, preview and status, newest first as given", () => {
|
|
64
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
65
|
+
const rows = ["a", "b", "c"].map((id) => screen.getByTestId(`inbox-row-${id}`));
|
|
66
|
+
expect(rows).toHaveLength(3);
|
|
67
|
+
expect(screen.getByTestId("inbox-row-b-time").textContent).toBe("Yesterday");
|
|
68
|
+
expect(screen.getByTestId("inbox-row-a-meta").textContent).toBe("In progress");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("shows unread as a count or a dot, and says it to VoiceOver", () => {
|
|
72
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
73
|
+
expect(screen.getByTestId("inbox-row-a-count").textContent).toBe("2");
|
|
74
|
+
expect(screen.getByTestId("inbox-row-a").getAttribute("aria-label")).toMatch(/^2 unread, Save button does nothing/);
|
|
75
|
+
expect(styleOf(screen.getByTestId("inbox-row-b-unread")).borderRadius).toBe(5);
|
|
76
|
+
expect(screen.getByTestId("inbox-row-b").getAttribute("aria-label")).toMatch(/^Unread, Dark mode/);
|
|
77
|
+
expect(styleOf(screen.getByTestId("inbox-row-c-unread")).borderRadius).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("opens a row on press", () => {
|
|
81
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
82
|
+
fireEvent.click(screen.getByTestId("inbox-row-a"));
|
|
83
|
+
expect(items[0]!.onPress).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("offers swipe actions as accessibility actions and on long press, without a gesture library", () => {
|
|
87
|
+
const remove = vi.fn();
|
|
88
|
+
const markRead = vi.fn();
|
|
89
|
+
render(
|
|
90
|
+
<InboxPage
|
|
91
|
+
testID="inbox"
|
|
92
|
+
now={now}
|
|
93
|
+
items={[{ id: "x", title: "Thread", swipeActions: [{ id: "read", label: "Mark read", onPress: markRead }, { id: "delete", label: "Delete", destructive: true, onPress: remove }] }]}
|
|
94
|
+
/>,
|
|
95
|
+
);
|
|
96
|
+
const row = screen.getByTestId("inbox-row-x");
|
|
97
|
+
expect(row.getAttribute("data-a11y-actions")).toBe("read,delete");
|
|
98
|
+
row.dispatchEvent(new CustomEvent("accessibilityaction", { detail: "delete" }));
|
|
99
|
+
expect(remove).toHaveBeenCalledTimes(1);
|
|
100
|
+
fireEvent.contextMenu(row);
|
|
101
|
+
const [title, , buttons] = vi.mocked(Alert.alert).mock.calls[0]!;
|
|
102
|
+
expect(title).toBe("Thread");
|
|
103
|
+
expect(buttons?.map((b) => [b.text, b.style])).toEqual([["Mark read", "default"], ["Delete", "destructive"], ["Cancel", "cancel"]]);
|
|
104
|
+
buttons?.[0]?.onPress?.();
|
|
105
|
+
expect(markRead).toHaveBeenCalled();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("wraps rows with actions in the swipeable slot, and a null slot leaves them bare", () => {
|
|
109
|
+
function Swipe({ actions, children, testID }: { actions: { id: string }[]; children?: ReactNode; testID: string }) {
|
|
110
|
+
return (
|
|
111
|
+
<div data-testid={testID} data-actions={actions.map((a) => a.id).join(",")}>
|
|
112
|
+
{children}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const withActions = [{ id: "x", title: "T", swipeActions: [{ id: "delete", label: "Delete", onPress: () => {} }] }];
|
|
117
|
+
const { unmount } = render(<InboxPage testID="inbox" items={withActions} slots={{ swipeable: Swipe }} />);
|
|
118
|
+
expect(screen.getByTestId("inbox-row-x-swipe").getAttribute("data-actions")).toBe("delete");
|
|
119
|
+
expect(screen.getByTestId("inbox-row-x-swipe").querySelector('[data-testid="inbox-row-x"]')).toBeTruthy();
|
|
120
|
+
unmount();
|
|
121
|
+
render(<InboxPage testID="inbox" items={withActions} slots={{ swipeable: null }} />);
|
|
122
|
+
expect(screen.queryByTestId("inbox-row-x-swipe")).toBeNull();
|
|
123
|
+
expect(screen.getByTestId("inbox-row-x")).toBeTruthy();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("on iOS, draws one inset rounded group of cells, like SettingsPage", () => {
|
|
127
|
+
Platform.OS = "ios";
|
|
128
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
129
|
+
const first = styleOf(screen.getByTestId("inbox-row-a-cell"));
|
|
130
|
+
const middle = styleOf(screen.getByTestId("inbox-row-b-cell"));
|
|
131
|
+
const last = styleOf(screen.getByTestId("inbox-row-c-cell"));
|
|
132
|
+
expect(first).toMatchObject({ marginHorizontal: 16, borderTopLeftRadius: 10, borderBottomLeftRadius: 0, backgroundColor: { semantic: ["secondarySystemGroupedBackground"] } });
|
|
133
|
+
expect(middle).toMatchObject({ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 });
|
|
134
|
+
expect(last).toMatchObject({ borderTopLeftRadius: 0, borderBottomLeftRadius: 10 });
|
|
135
|
+
expect(screen.queryByTestId("inbox-row-c-separator-line")).toBeNull();
|
|
136
|
+
expect(screen.getByTestId("inbox-row-a-separator-line")).toBeTruthy();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("on Android, rows are full width", () => {
|
|
140
|
+
Platform.OS = "android";
|
|
141
|
+
render(<InboxPage testID="inbox" items={items} now={now} />);
|
|
142
|
+
expect(styleOf(screen.getByTestId("inbox-row-a-cell")).marginHorizontal).toBeUndefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("shows the paging spinner while more load, and the header and section title", () => {
|
|
146
|
+
render(<InboxPage testID="inbox" items={items} now={now} loadingMore header={<span data-testid="filter" />} sectionTitle="Your reports" />);
|
|
147
|
+
expect(screen.getByTestId("inbox-footer")).toBeTruthy();
|
|
148
|
+
expect(screen.getByTestId("filter")).toBeTruthy();
|
|
149
|
+
expect(screen.getByTestId("inbox-section-title").textContent).toBe("Your reports");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("composes a large-title header by default", () => {
|
|
153
|
+
expect(getInboxPageStackOptions({ headerTitle: "Help" })).toMatchObject({ title: "Help", headerLargeTitle: true });
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -4,7 +4,7 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
4
4
|
import { View } from "react-native";
|
|
5
5
|
import { AuthScreen } from "../auth-screen";
|
|
6
6
|
import { SettingsSubPage } from "../settings-sub-page";
|
|
7
|
-
import { KeyboardScrollProvider, type KeyboardScrollProps } from "../keyboard";
|
|
7
|
+
import { KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, useKeyboardToolbar, type KeyboardScrollProps } from "../keyboard";
|
|
8
8
|
|
|
9
9
|
const Aware = ({ children, testID }: KeyboardScrollProps) => <View testID={testID}>{children}</View>;
|
|
10
10
|
|
|
@@ -32,3 +32,44 @@ describe("KeyboardScrollProvider", () => {
|
|
|
32
32
|
expect(screen.getByTestId("sub-kav")).toBeTruthy();
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
describe("KeyboardScrollProvider toolbar", () => {
|
|
37
|
+
const Toolbar = () => <View testID="toolbar" />;
|
|
38
|
+
const Spy = vi.fn(({ children, testID, bottomOffset }: KeyboardScrollProps) => (
|
|
39
|
+
<View testID={testID} accessibilityLabel={`offset ${bottomOffset}`}>
|
|
40
|
+
{children}
|
|
41
|
+
</View>
|
|
42
|
+
));
|
|
43
|
+
|
|
44
|
+
it("adds the previous / next / done bar to AuthScreen and SettingsSubPage, and keeps the focused field clear of it", () => {
|
|
45
|
+
render(
|
|
46
|
+
<KeyboardScrollProvider component={Spy} toolbar={Toolbar}>
|
|
47
|
+
<AuthScreen form={{ onSubmit: vi.fn() }} />
|
|
48
|
+
<SettingsSubPage testID="sub">{null}</SettingsSubPage>
|
|
49
|
+
</KeyboardScrollProvider>,
|
|
50
|
+
);
|
|
51
|
+
// One bar each, beside (not inside) the scroll view.
|
|
52
|
+
expect(screen.getAllByTestId("toolbar")).toHaveLength(2);
|
|
53
|
+
expect(screen.getByTestId("auth-screen-keyboard").querySelector("[data-testid=toolbar]")).toBeNull();
|
|
54
|
+
expect(screen.getByTestId("auth-screen").querySelector("[data-testid=toolbar]")).not.toBeNull();
|
|
55
|
+
expect(screen.getByTestId("auth-screen-keyboard").getAttribute("aria-label")).toBe(`offset ${24 + KEYBOARD_TOOLBAR_HEIGHT}`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("draws no bar without one", () => {
|
|
59
|
+
render(
|
|
60
|
+
<KeyboardScrollProvider component={Spy}>
|
|
61
|
+
<AuthScreen form={{ onSubmit: vi.fn() }} />
|
|
62
|
+
</KeyboardScrollProvider>,
|
|
63
|
+
);
|
|
64
|
+
expect(screen.queryByTestId("toolbar")).toBeNull();
|
|
65
|
+
expect(screen.getByTestId("auth-screen-keyboard").getAttribute("aria-label")).toBe("offset 24");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("reports no toolbar outside a provider", () => {
|
|
69
|
+
function Probe() {
|
|
70
|
+
return <span data-testid="probe">{String(useKeyboardToolbar())}</span>;
|
|
71
|
+
}
|
|
72
|
+
render(<Probe />);
|
|
73
|
+
expect(screen.getByTestId("probe").textContent).toBe("null");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// @feat:native-layouts
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { Platform, StyleSheet, Text } from "react-native";
|
|
5
|
+
import { SettingsPage } from "../settings-page";
|
|
6
|
+
|
|
7
|
+
const sections = [
|
|
8
|
+
{
|
|
9
|
+
id: "account",
|
|
10
|
+
title: "Account",
|
|
11
|
+
footnote: "Only you see this.",
|
|
12
|
+
rows: [
|
|
13
|
+
{ id: "name", title: "Name", leading: <Text>icon</Text> },
|
|
14
|
+
{ id: "email", title: "Email" },
|
|
15
|
+
{ id: "phone", title: "Phone" },
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
function styleOf(el: Element): Record<string, unknown> {
|
|
21
|
+
return StyleSheet.flatten(JSON.parse((el as HTMLElement).dataset.style ?? "null"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const os = Platform.OS;
|
|
25
|
+
const version = Platform.Version;
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
Platform.OS = os;
|
|
28
|
+
Platform.Version = version;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("SettingsPage on iOS (inset grouped)", () => {
|
|
32
|
+
it("renders the header as an uppercase footnote in secondaryLabel, read as written, with no band or rule", () => {
|
|
33
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
34
|
+
const header = screen.getByTestId("s-section-account-header");
|
|
35
|
+
expect(header.getAttribute("role")).toBe("header");
|
|
36
|
+
expect(header.getAttribute("aria-label")).toBe("Account");
|
|
37
|
+
expect(header.textContent).toBe("Account");
|
|
38
|
+
const style = styleOf(header);
|
|
39
|
+
expect(style).toMatchObject({
|
|
40
|
+
color: { semantic: ["secondaryLabel"] },
|
|
41
|
+
fontSize: 13,
|
|
42
|
+
textTransform: "uppercase",
|
|
43
|
+
marginHorizontal: 16,
|
|
44
|
+
});
|
|
45
|
+
expect(style.backgroundColor).toBeUndefined();
|
|
46
|
+
expect(style.borderBottomWidth).toBeUndefined();
|
|
47
|
+
expect(header.className).not.toMatch(/\bbg-|\bborder/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("aligns the header with the cell text: the group's margin, then the cell's padding", () => {
|
|
51
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
52
|
+
const header = screen.getByTestId("s-section-account-header");
|
|
53
|
+
const group = screen.getByTestId("s-section-account-group");
|
|
54
|
+
expect(styleOf(header).marginHorizontal).toBe(styleOf(group).marginHorizontal);
|
|
55
|
+
expect(header.className).toContain("px-4");
|
|
56
|
+
expect(screen.getByTestId("s-row-email").className).toContain("px-4");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("puts rows in a rounded group on secondarySystemGroupedBackground", () => {
|
|
60
|
+
Platform.Version = "18.4";
|
|
61
|
+
const { unmount } = render(<SettingsPage testID="s" sections={sections} />);
|
|
62
|
+
const group = screen.getByTestId("s-section-account-group");
|
|
63
|
+
expect(group.className).toContain("overflow-hidden");
|
|
64
|
+
expect(styleOf(group)).toMatchObject({
|
|
65
|
+
backgroundColor: { semantic: ["secondarySystemGroupedBackground"] },
|
|
66
|
+
borderRadius: 10,
|
|
67
|
+
});
|
|
68
|
+
unmount();
|
|
69
|
+
Platform.Version = "26.0";
|
|
70
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
71
|
+
expect(styleOf(screen.getByTestId("s-section-account-group")).borderRadius).toBe(26);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("draws hairline separators between cells only, inset to the cell text and hidden from screen readers", () => {
|
|
75
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
76
|
+
expect(screen.queryByTestId("s-row-phone-separator")).toBeNull();
|
|
77
|
+
const separator = screen.getByTestId("s-row-email-separator");
|
|
78
|
+
expect(separator.getAttribute("aria-hidden")).toBe("true");
|
|
79
|
+
expect(styleOf(separator).height).toBe(StyleSheet.hairlineWidth);
|
|
80
|
+
// The leading spacer is the cell's `px-4`, so the line starts where the text does.
|
|
81
|
+
const [inset, line] = Array.from(separator.children);
|
|
82
|
+
expect(inset!.className).toBe("w-4");
|
|
83
|
+
expect(styleOf(screen.getByTestId("s-row-email-separator-line")).backgroundColor).toEqual({
|
|
84
|
+
semantic: ["separator"],
|
|
85
|
+
});
|
|
86
|
+
expect(line).toBe(screen.getByTestId("s-row-email-separator-line"));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("insets a separator past a leading icon by the icon and the cell's gap", () => {
|
|
90
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
91
|
+
const children = Array.from(screen.getByTestId("s-row-name-separator").children);
|
|
92
|
+
expect(children.map((c) => c.className)).toEqual(expect.arrayContaining(["w-4", "mr-3"]));
|
|
93
|
+
expect(children[1]!.className).toBe("mr-3");
|
|
94
|
+
expect(styleOf(children[1]!)).toHaveProperty("width");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("stops separators short of the trailing edge from iOS 26", () => {
|
|
98
|
+
Platform.Version = "18.4";
|
|
99
|
+
const { unmount } = render(<SettingsPage testID="s" sections={sections} />);
|
|
100
|
+
expect(screen.getByTestId("s-row-email-separator").children).toHaveLength(2);
|
|
101
|
+
unmount();
|
|
102
|
+
Platform.Version = "26.0";
|
|
103
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
104
|
+
expect(screen.getByTestId("s-row-email-separator").children).toHaveLength(3);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("puts the footnote under the group in secondaryLabel, aligned like the header", () => {
|
|
108
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
109
|
+
const footnote = screen.getByText("Only you see this.");
|
|
110
|
+
expect(styleOf(footnote)).toMatchObject({
|
|
111
|
+
color: { semantic: ["secondaryLabel"] },
|
|
112
|
+
fontSize: 13,
|
|
113
|
+
marginHorizontal: 16,
|
|
114
|
+
});
|
|
115
|
+
expect(footnote.className).toContain("px-4");
|
|
116
|
+
const group = screen.getByTestId("s-section-account-group");
|
|
117
|
+
expect(group.compareDocumentPosition(footnote) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("SettingsPage on Android (Material)", () => {
|
|
122
|
+
it("renders the header as a primary-colored subheader, not uppercase, with no band", () => {
|
|
123
|
+
Platform.OS = "android";
|
|
124
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
125
|
+
const header = screen.getByTestId("s-section-account-header");
|
|
126
|
+
expect(header.getAttribute("role")).toBe("header");
|
|
127
|
+
expect(header.className).toContain("text-primary");
|
|
128
|
+
expect(header.className).not.toMatch(/\bbg-|\bborder/);
|
|
129
|
+
const style = styleOf(header);
|
|
130
|
+
expect(style.textTransform).toBeUndefined();
|
|
131
|
+
expect(style.backgroundColor).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("keeps full-width cells and colors the footnote from the theme roles", () => {
|
|
135
|
+
Platform.OS = "android";
|
|
136
|
+
render(<SettingsPage testID="s" sections={sections} />);
|
|
137
|
+
const group = screen.getByTestId("s-section-account-group");
|
|
138
|
+
expect(styleOf(group).borderRadius).toBeUndefined();
|
|
139
|
+
expect(group.className).toContain("border-y");
|
|
140
|
+
expect(typeof styleOf(screen.getByText("Only you see this.")).color).toBe("string");
|
|
141
|
+
});
|
|
142
|
+
});
|