Open History to see the last commit
1import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it, vi } from "vite-plus/test";
4
5const mocks = vi.hoisted(() => ({ favicon: null as string | null }));
6
7vi.mock("~/browserFaviconStore", () => ({
8 useFaviconForThreadUrl: () => mocks.favicon,
9}));
10
11import { FaviconImage, PreviewFaviconIcon, selectFaviconSource } from "./PreviewFaviconIcon";
12
13const threadRef = {
14 environmentId: EnvironmentId.make("env-1"),
15 threadId: ThreadId.make("thread-1"),
16};
17
18describe("preview favicon image", () => {
19 it("renders a captured source before later fallback sources", () => {
20 expect(
21 renderToStaticMarkup(
22 <FaviconImage
23 sources={["data:image/png;base64,AAAA", "https://public.example/icon"]}
24 fallback={<span>fallback</span>}
25 />,
26 ),
27 ).toContain('src="data:image/png;base64,AAAA"');
28 const captured = "data:image/png;base64,AAAA";
29 const google = "https://public.example/icon";
30 expect(selectFaviconSource([captured, google], new Set())).toBe(captured);
31 expect(selectFaviconSource([captured, google], new Set([captured]))).toBe(google);
32 expect(selectFaviconSource([captured, google], new Set([captured, google]))).toBeNull();
33 expect(selectFaviconSource(["data:image/png;base64,BBBB", google], new Set([captured]))).toBe(
34 "data:image/png;base64,BBBB",
35 );
36 });
37
38 it("uses a stored project icon or falls back to the browser mockup", () => {
39 mocks.favicon = null;
40 const html = renderToStaticMarkup(
41 <PreviewFaviconIcon threadRef={threadRef} url="http://localhost:3000/" />,
42 );
43 expect(html).not.toContain("<img");
44 expect(html).toContain("rounded-[5px]");
45 mocks.favicon = "data:image/png;base64,AAAA";
46 const faviconHtml = renderToStaticMarkup(
47 <PreviewFaviconIcon threadRef={threadRef} url="http://localhost:3000/" />,
48 );
49 expect(faviconHtml).toContain('src="data:image/png;base64,AAAA"');
50 });
51});