Open History to see the last commit
1import type { DesktopPreviewFavicon, PreviewSessionSnapshot } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import { RightPanelTabs } from "./RightPanelTabs";
6
7const previewSurface = {
8 id: "browser:tab-1" as const,
9 kind: "preview" as const,
10 resourceId: "tab-1",
11};
12const secondSurface = {
13 id: "browser:tab-2" as const,
14 kind: "preview" as const,
15 resourceId: "tab-2",
16};
17const sessions: Readonly<Record<string, PreviewSessionSnapshot>> = {
18 "tab-1": {
19 threadId: "thread-1",
20 tabId: "tab-1",
21 navStatus: { _tag: "Success", url: "http://24x.xf.local/", title: "Local site" },
22 canGoBack: false,
23 canGoForward: false,
24 updatedAt: "2026-08-09T00:00:00.000Z",
25 },
26 "tab-2": {
27 threadId: "thread-1",
28 tabId: "tab-2",
29 navStatus: { _tag: "Success", url: "http://24x.xf.local/admin", title: "Admin" },
30 canGoBack: false,
31 canGoForward: false,
32 updatedAt: "2026-08-09T00:00:00.000Z",
33 },
34};
35
36const favicon = (dataUrl: string, pageUrl: string): DesktopPreviewFavicon => ({
37 dataUrl,
38 pageUrl,
39 capturedAt: 1,
40});
41
42function overlay(icon: DesktopPreviewFavicon | null) {
43 return {
44 hasWebContents: true,
45 canGoBack: false,
46 canGoForward: false,
47 loading: false,
48 zoomFactor: 1,
49 pictureInPicture: false,
50 colorScheme: "system" as const,
51 controller: "none" as const,
52 favicon: icon,
53 };
54}
55
56function renderTabs(first: DesktopPreviewFavicon | null, second?: DesktopPreviewFavicon) {
57 return renderToStaticMarkup(
58 <RightPanelTabs
59 mode="inline"
60 surfaces={second ? [previewSurface, secondSurface] : [previewSurface]}
61 activeSurfaceId={previewSurface.id}
62 pendingSurfaceIds={new Set()}
63 previewSessions={sessions}
64 desktopByTabId={{
65 "tab-1": overlay(first),
66 ...(second ? { "tab-2": overlay(second) } : {}),
67 }}
68 terminalLabelsById={new Map()}
69 onActivate={() => undefined}
70 onCloseSurface={() => undefined}
71 onCloseOtherSurfaces={() => undefined}
72 onCloseSurfacesToRight={() => undefined}
73 onCloseAllSurfaces={() => undefined}
74 onCopyFilePath={() => undefined}
75 onAddBrowser={() => undefined}
76 onAddTerminal={() => undefined}
77 onAddPullRequest={() => undefined}
78 onAddDiff={() => undefined}
79 onAddFiles={() => undefined}
80 onAddAgents={() => undefined}
81 liveAgentCount={0}
82 browserAvailable
83 terminalAvailable={false}
84 diffAvailable={false}
85 filesAvailable={false}
86 pullRequestAvailable={false}
87 agentsAvailable={false}
88 >
89 <div>content</div>
90 </RightPanelTabs>,
91 );
92}
93
94describe("RightPanelTabs preview favicon", () => {
95 it("prefers a live capture and never asks Google about a private hostname", () => {
96 const captured = renderTabs(favicon("data:image/png;base64,AAAA", "http://24x.xf.local/"));
97 expect(captured).toContain("data:image/png;base64,AAAA");
98 expect(captured).not.toContain("s2/favicons");
99 expect(renderTabs(null)).not.toContain("s2/favicons");
100 });
101
102 it("keeps route-specific captures isolated between live tabs on one origin", () => {
103 const html = renderTabs(
104 favicon("data:image/png;base64,AAAA", "http://24x.xf.local/"),
105 favicon("data:image/png;base64,BBBB", "http://24x.xf.local/admin"),
106 );
107 expect(html).toContain("data:image/png;base64,AAAA");
108 expect(html).toContain("data:image/png;base64,BBBB");
109 });
110
111 it("hides a capture while the server session still describes another origin", () => {
112 const html = renderTabs(favicon("data:image/png;base64,AAAA", "https://example.com/"));
113 expect(html).not.toContain("data:image/png;base64,AAAA");
114 });
115});