115 lines · 3.7 KB · TypeScript
RawDownload
import type { DesktopPreviewFavicon, PreviewSessionSnapshot } from "@t3tools/contracts";import { renderToStaticMarkup } from "react-dom/server";import { describe, expect, it } from "vite-plus/test"; import { RightPanelTabs } from "./RightPanelTabs"; const previewSurface = {  id: "browser:tab-1" as const,  kind: "preview" as const,  resourceId: "tab-1",};const secondSurface = {  id: "browser:tab-2" as const,  kind: "preview" as const,  resourceId: "tab-2",};const sessions: Readonly<Record<string, PreviewSessionSnapshot>> = {  "tab-1": {    threadId: "thread-1",    tabId: "tab-1",    navStatus: { _tag: "Success", url: "http://24x.xf.local/", title: "Local site" },    canGoBack: false,    canGoForward: false,    updatedAt: "2026-08-09T00:00:00.000Z",  },  "tab-2": {    threadId: "thread-1",    tabId: "tab-2",    navStatus: { _tag: "Success", url: "http://24x.xf.local/admin", title: "Admin" },    canGoBack: false,    canGoForward: false,    updatedAt: "2026-08-09T00:00:00.000Z",  },}; const favicon = (dataUrl: string, pageUrl: string): DesktopPreviewFavicon => ({  dataUrl,  pageUrl,  capturedAt: 1,}); function overlay(icon: DesktopPreviewFavicon | null) {  return {    hasWebContents: true,    canGoBack: false,    canGoForward: false,    loading: false,    zoomFactor: 1,    pictureInPicture: false,    colorScheme: "system" as const,    controller: "none" as const,    favicon: icon,  };} function renderTabs(first: DesktopPreviewFavicon | null, second?: DesktopPreviewFavicon) {  return renderToStaticMarkup(    <RightPanelTabs      mode="inline"      surfaces={second ? [previewSurface, secondSurface] : [previewSurface]}      activeSurfaceId={previewSurface.id}      pendingSurfaceIds={new Set()}      previewSessions={sessions}      desktopByTabId={{        "tab-1": overlay(first),        ...(second ? { "tab-2": overlay(second) } : {}),      }}      terminalLabelsById={new Map()}      onActivate={() => undefined}      onCloseSurface={() => undefined}      onCloseOtherSurfaces={() => undefined}      onCloseSurfacesToRight={() => undefined}      onCloseAllSurfaces={() => undefined}      onCopyFilePath={() => undefined}      onAddBrowser={() => undefined}      onAddTerminal={() => undefined}      onAddPullRequest={() => undefined}      onAddDiff={() => undefined}      onAddFiles={() => undefined}      onAddAgents={() => undefined}      liveAgentCount={0}      browserAvailable      terminalAvailable={false}      diffAvailable={false}      filesAvailable={false}      pullRequestAvailable={false}      agentsAvailable={false}    >      <div>content</div>    </RightPanelTabs>,  );} describe("RightPanelTabs preview favicon", () => {  it("prefers a live capture and never asks Google about a private hostname", () => {    const captured = renderTabs(favicon("data:image/png;base64,AAAA", "http://24x.xf.local/"));    expect(captured).toContain("data:image/png;base64,AAAA");    expect(captured).not.toContain("s2/favicons");    expect(renderTabs(null)).not.toContain("s2/favicons");  });   it("keeps route-specific captures isolated between live tabs on one origin", () => {    const html = renderTabs(      favicon("data:image/png;base64,AAAA", "http://24x.xf.local/"),      favicon("data:image/png;base64,BBBB", "http://24x.xf.local/admin"),    );    expect(html).toContain("data:image/png;base64,AAAA");    expect(html).toContain("data:image/png;base64,BBBB");  });   it("hides a capture while the server session still describes another origin", () => {    const html = renderTabs(favicon("data:image/png;base64,AAAA", "https://example.com/"));    expect(html).not.toContain("data:image/png;base64,AAAA");  });});