Open History to see the last commit
1import { act, type ReactNode } from "react";
2import { createRoot, type Root } from "react-dom/client";
3import { afterEach, expect, it, vi } from "vite-plus/test";
4
5vi.mock("react-native", () => ({
6 View: (props: { readonly children?: ReactNode }) => <div>{props.children}</div>,
7 Keyboard: { dismiss: () => {} },
8 BackHandler: { addEventListener: () => ({ remove: () => {} }) },
9}));
10const useIsFocusedMock = vi.fn<() => boolean>(() => {
11 throw new Error("Couldn't find a navigation object.");
12});
13// React Navigation throws this outside a navigator, as for the Arrange threads sheet.
14vi.mock("@react-navigation/native", () => ({
15 useIsFocused: () => useIsFocusedMock(),
16}));
17vi.mock("./AndroidScreenHeader.android", () => ({
18 AndroidScreenHeader: (props: { readonly title: string }) => <h1>{props.title}</h1>,
19}));
20vi.mock("./WorkspaceAppBar.android", () => ({
21 useHasWorkspaceAppBar: () => false,
22 WorkspaceAppBar: () => null,
23}));
24vi.mock("./AndroidAnchoredMenu.android", () => ({
25 AndroidAnchoredMenu: (props: {
26 readonly children?: ReactNode | ((open: () => void) => ReactNode);
27 }) => (typeof props.children === "function" ? props.children(() => {}) : props.children),
28}));
29vi.mock("./ScreenHeaderButton.android", () => ({ ScreenHeaderButton: () => null }));
30vi.mock("./SearchField", () => ({ SearchField: () => null }));
31vi.mock("./Button", () => ({ Button: () => null }));
32vi.mock("../../features/layout/adaptive-workspace-context", () => ({
33 useAdaptiveWorkspaceLayout: () => ({ layout: { usesSplitView: false } }),
34}));
35vi.mock("./useToolbarLayout", () => ({
36 useToolbarLayout: () => ({ height: 48, paddingTop: 0, paddingBottom: 0 }),
37}));
38vi.mock("../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null }));
39vi.mock("../../features/layout/useSidebarToggle", () => ({ useSidebarToggle: () => null }));
40vi.mock("../../features/settings/appearance/AppearancePreferencesProvider", () => ({
41 useAppearancePreferences: () => ({ themeVariables: {} }),
42}));
43
44import { AppBar } from "./AppBar.android";
45
46const roots: Root[] = [];
47
48afterEach(() => {
49 for (const root of roots.splice(0)) act(() => root.unmount());
50 document.body.innerHTML = "";
51});
52
53it("renders a sheet bar without search outside a navigation container", () => {
54 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
55 const container = document.createElement("div");
56 document.body.append(container);
57 const root = createRoot(container);
58 roots.push(root);
59
60 act(() => root.render(<AppBar sheet title="Arrange threads" />));
61
62 expect(container.textContent).toBe("Arrange threads");
63});
64
65it("does not mount the hidden screen header while inline search is active", () => {
66 useIsFocusedMock.mockReturnValueOnce(true);
67 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
68 const container = document.createElement("div");
69 document.body.append(container);
70 const root = createRoot(container);
71 roots.push(root);
72
73 act(() =>
74 root.render(
75 <AppBar
76 title="Archived threads"
77 search={{
78 mode: "inline",
79 value: "",
80 placeholder: "Search",
81 onChangeText: () => {},
82 }}
83 />,
84 ),
85 );
86
87 expect(container.querySelector("h1")).toBeNull();
88});