Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProjectFavicon.test.tsx

51 lines1.8 KB

1import type { ReactNode } from "react";
2import { act, Profiler } from "react";
3import { createRoot } from "react-dom/client";
4import { expect, it, vi } from "vite-plus/test";
5​
6const harness = vi.hoisted(() => ({
7 Passthrough: ({ children }: { children?: unknown }) => children,
8}));
9​
10vi.mock("react-native", () => ({ View: harness.Passthrough }));
11vi.mock("expo-image", () => ({ Image: () => <img alt="" /> }));
12vi.mock("./ui/AppSymbol", () => ({ SymbolView: () => null }));
13vi.mock("./ui/AppText", () => ({
14 AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
15}));
16vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => ({
17 useAppearancePreferences: () => ({ themeAppearance: "light" }),
18}));
19vi.mock("../state/assets", async () => {
20 const { Atom } = await import("effect/reactivity");
21 const url = Atom.make<string | null>("https://example.test/favicon.png");
22 return { projectFaviconUrlAtom: () => url };
23});
24​
25import { EnvironmentId } from "@t3tools/contracts";
26​
27import { ProjectFavicon } from "./ProjectFavicon";
28​
29it("mounts the favicon image in the first commit", async () => {
30 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
31 const container = document.createElement("div");
32 const root = createRoot(container);
33 const commits: string[] = [];
34 try {
35 await act(async () =>
36 root.render(
37 <Profiler id="favicon" onRender={(_id, phase) => commits.push(phase)}>
38 <ProjectFavicon
39 environmentId={EnvironmentId.make("env-1")}
40 projectTitle="Project"
41 workspaceRoot="/repo"
42 />
43 </Profiler>,
44 ),
45 );
46 expect(container.querySelector("img")).not.toBeNull();
47 expect(commits).toEqual(["mount"]);
48 } finally {
49 await act(async () => root.unmount());
50 }
51});