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", () => ({
12 Image: (props: { source: { uri: string } }) => <img alt="" src={props.source.uri} />,
13}));
14vi.mock("./ui/AppSymbol", () => ({ SymbolView: () => null }));
15vi.mock("./ui/AppText", () => ({
16 AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
17}));
18vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => ({
19 useAppearancePreferences: () => ({ themeAppearance: "light" }),
20}));
21vi.mock("../state/assets", async () => {
22 const { Atom } = await import("effect/reactivity");
23 const url = Atom.make<string | null>("https://example.test/favicon.png");
24 const missing = Atom.make<string | null>(null);
25 return {
26 projectFaviconUrlAtom: (target: { readonly cwd: string }) =>
27 target.cwd === "/repo-without-icon" ? missing : url,
28 };
29});
30
31import { EnvironmentId } from "@t3tools/contracts";
32
33import { ProjectFavicon } from "./ProjectFavicon";
34
35it("mounts the favicon image in the first commit", async () => {
36 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
37 const container = document.createElement("div");
38 const root = createRoot(container);
39 const commits: string[] = [];
40 try {
41 await act(async () =>
42 root.render(
43 <Profiler id="favicon" onRender={(_id, phase) => commits.push(phase)}>
44 <ProjectFavicon
45 environmentId={EnvironmentId.make("env-1")}
46 projectTitle="Project"
47 workspaceRoot="/repo"
48 />
49 </Profiler>,
50 ),
51 );
52 expect(container.querySelector("img")).not.toBeNull();
53 expect(commits).toEqual(["mount"]);
54 } finally {
55 await act(async () => root.unmount());
56 }
57});
58
59it("shows the next project's icon when a group's own project has none", async () => {
60 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
61 const container = document.createElement("div");
62 const root = createRoot(container);
63 const environmentId = EnvironmentId.make("env-1");
64 try {
65 await act(async () =>
66 root.render(
67 <ProjectFavicon
68 environmentId={environmentId}
69 projectTitle="Project"
70 workspaceRoot="/repo-without-icon"
71 fallbackProjects={[
72 {
73 environmentId,
74 workspaceRoot: "/repo/apps/web",
75 faviconPath: null,
76 projectIcon: null,
77 },
78 ]}
79 />,
80 ),
81 );
82 expect(container.querySelector("img")?.getAttribute("src")).toBe(
83 "https://example.test/favicon.png",
84 );
85 } finally {
86 await act(async () => root.unmount());
87 }
88});