Open History to see the last commit
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("../state/assets", async () => {
17 const { Atom } = await import("effect/reactivity");
18 const url = Atom.make<string | null>("https://example.test/favicon.png");
19 return { projectFaviconUrlAtom: () => url };
20});
21
22import { EnvironmentId } from "@t3tools/contracts";
23
24import { ProjectFavicon } from "./ProjectFavicon";
25
26it("mounts the favicon image in the first commit", async () => {
27 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
28 const container = document.createElement("div");
29 const root = createRoot(container);
30 const commits: string[] = [];
31 try {
32 await act(async () =>
33 root.render(
34 <Profiler id="favicon" onRender={(_id, phase) => commits.push(phase)}>
35 <ProjectFavicon
36 environmentId={EnvironmentId.make("env-1")}
37 projectTitle="Project"
38 workspaceRoot="/repo"
39 />
40 </Profiler>,
41 ),
42 );
43 expect(container.querySelector("img")).not.toBeNull();
44 expect(commits).toEqual(["mount"]);
45 } finally {
46 await act(async () => root.unmount());
47 }
48});