The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { RegistryContext } from "@effect/atom-react"; |
| 2 | import { EnvironmentId } from "@t3tools/contracts"; |
| 3 | import { Atom, AtomRegistry } from "effect/reactivity"; |
| 4 | import { expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | import { render } from "../../test/render"; |
| 7 | import { ProjectFavicon, type ProjectFaviconProject } from "./ProjectFavicon"; |
| 8 | |
| 9 | const state = vi.hoisted(() => ({ favicon: undefined as Atom.Atom<string | null> | undefined })); |
| 10 | vi.mock(import("../state/assets"), () => ({ |
| 11 | projectFaviconUrlAtom: () => { |
| 12 | if (!state.favicon) throw new Error("Favicon resource not configured"); |
| 13 | return state.favicon; |
| 14 | }, |
| 15 | })); |
| 16 | |
| 17 | function setup() { |
| 18 | const activeResources = new Set<string>(); |
| 19 | state.favicon = Atom.make((get) => { |
| 20 | activeResources.add("favicon"); |
| 21 | get.addFinalizer(() => activeResources.delete("favicon")); |
| 22 | return null; |
| 23 | }); |
| 24 | return { activeResources }; |
| 25 | } |
| 26 | |
| 27 | it("only activates the favicon resource after removing a custom icon", async () => { |
| 28 | const { activeResources } = setup(); |
| 29 | const registry = AtomRegistry.make(); |
| 30 | const project: ProjectFaviconProject = { |
| 31 | environmentId: EnvironmentId.make("test"), |
| 32 | workspaceRoot: "/project", |
| 33 | title: "Project", |
| 34 | faviconPath: "icon.png", |
| 35 | projectIcon: { kind: "monogram", text: "PR", color: "blue" }, |
| 36 | }; |
| 37 | const view = (projectIcon: ProjectFaviconProject["projectIcon"]) => ( |
| 38 | <RegistryContext value={registry}> |
| 39 | <ProjectFavicon project={{ ...project, projectIcon }} /> |
| 40 | </RegistryContext> |
| 41 | ); |
| 42 | try { |
| 43 | await using screen = await render(view(project.projectIcon)); |
| 44 | expect(activeResources.size).toBe(0); |
| 45 | await screen.rerender(view({ kind: "emoji", emoji: "🌱" })); |
| 46 | expect(activeResources.size).toBe(0); |
| 47 | await screen.rerender(view({ kind: "lucide", name: "leaf", color: "green" })); |
| 48 | expect(activeResources.size).toBe(0); |
| 49 | await screen.rerender(view(null)); |
| 50 | expect(activeResources.size).toBe(1); |
| 51 | await screen.rerender(view(project.projectIcon)); |
| 52 | await screen.rerender(view(null)); |
| 53 | expect(activeResources.size).toBe(1); |
| 54 | } finally { |
| 55 | registry.dispose(); |
| 56 | } |
| 57 | }); |