|
| 1 | +import type { ReactNode } from "react"; |
| 2 | +import { act, Profiler } from "react"; |
| 3 | +import { createRoot } from "react-dom/client"; |
| 4 | +import { expect, it, vi } from "vite-plus/test"; |
| 5 | + |
| 6 | +const harness = vi.hoisted(() => ({ |
| 7 | + Passthrough: ({ children }: { children?: unknown }) => children, |
| 8 | +})); |
| 9 | + |
| 10 | +vi.mock("react-native", () => ({ View: harness.Passthrough })); |
| 11 | +vi.mock("expo-image", () => ({ Image: () => <img alt="" /> })); |
| 12 | +vi.mock("./ui/AppSymbol", () => ({ SymbolView: () => null })); |
| 13 | +vi.mock("./ui/AppText", () => ({ |
| 14 | + AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>, |
| 15 | +})); |
| 16 | +vi.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 | + |
| 22 | +import { EnvironmentId } from "@t3tools/contracts"; |
| 23 | + |
| 24 | +import { ProjectFavicon } from "./ProjectFavicon"; |
| 25 | + |
| 26 | +it("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 | +}); |
0 commit comments