1import type { DesktopPreviewTabState } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { projectDesktopState } from "./usePreviewBridge";
5
6const favicon = {
7 dataUrl: "data:image/png;base64,AAAA",
8 pageUrl: "http://localhost:3000/app",
9 capturedAt: 1,
10};
11
12function state(navStatus: DesktopPreviewTabState["navStatus"]): DesktopPreviewTabState {
13 return {
14 tabId: "tab-1",
15 webContentsId: 1,
16 navStatus,
17 canGoBack: false,
18 canGoForward: false,
19 zoomFactor: 1,
20 pictureInPicture: false,
21 colorScheme: "system",
22 audioMuted: false,
23 audible: false,
24 controller: "none",
25 favicon,
26 updatedAt: "2026-08-09T00:00:00.000Z",
27 };
28}
29
30describe("projectDesktopState", () => {
31 it("shows a retained icon only while the current document has the captured origin", () => {
32 expect(
33 projectDesktopState(
34 state({ kind: "Loading", url: "http://localhost:3000/reload", title: "" }),
35 ).favicon,
36 ).toEqual(favicon);
37 expect(
38 projectDesktopState(
39 state({
40 kind: "LoadFailed",
41 url: "https://example.com/",
42 title: "",
43 code: -105,
44 description: "failed",
45 }),
46 ).favicon,
47 ).toBeNull();
48 expect(projectDesktopState(state({ kind: "Idle" })).favicon).toBeNull();
49 });
50});