diff --git a/apps/web/src/browser/desktopTabLifetime.test.ts b/apps/web/src/browser/desktopTabLifetime.test.ts index feb015c91a..1efe1b90ac 100644 --- a/apps/web/src/browser/desktopTabLifetime.test.ts +++ b/apps/web/src/browser/desktopTabLifetime.test.ts @@ -1,4 +1,9 @@ -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { + DEFAULT_PREVIEW_APPEARANCE, + DEFAULT_PREVIEW_ZOOM_FACTOR, + EnvironmentId, + ThreadId, +} from "@t3tools/contracts"; import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; const { closeTab, createTab, stopBrowserRecording } = vi.hoisted(() => ({ @@ -16,6 +21,12 @@ vi.mock("./browserRecording", () => ({ })); import { acquireDesktopTab } from "./desktopTabLifetime"; + +/** Client settings are unset in tests, so creation carries the schema defaults. */ +const DEFAULT_TAB_STATE = { + zoomFactor: DEFAULT_PREVIEW_ZOOM_FACTOR, + colorScheme: DEFAULT_PREVIEW_APPEARANCE, +}; import { previewRuntimeTabId } from "./previewRuntimeTabId"; describe("desktopTabLifetime", () => { @@ -81,8 +92,8 @@ describe("desktopTabLifetime", () => { const second = acquireDesktopTab(tabB); await Promise.all([first.ready, second.ready]); - expect(createTab).toHaveBeenCalledWith(tabA); - expect(createTab).toHaveBeenCalledWith(tabB); + expect(createTab).toHaveBeenCalledWith(tabA, DEFAULT_TAB_STATE); + expect(createTab).toHaveBeenCalledWith(tabB, DEFAULT_TAB_STATE); expect(createTab).toHaveBeenCalledTimes(2); first.release(); diff --git a/apps/web/src/components/preview/PreviewView.test.tsx b/apps/web/src/components/preview/PreviewView.test.tsx index d9671e2f2d..c3fe5337d0 100644 --- a/apps/web/src/components/preview/PreviewView.test.tsx +++ b/apps/web/src/components/preview/PreviewView.test.tsx @@ -1,4 +1,10 @@ -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { + DEFAULT_PREVIEW_APPEARANCE, + DEFAULT_PREVIEW_ZOOM_FACTOR, + EnvironmentId, + FILL_PREVIEW_VIEWPORT, + ThreadId, +} from "@t3tools/contracts"; import { renderToStaticMarkup } from "react-dom/server"; import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -41,6 +47,34 @@ vi.mock("~/state/session", () => ({ readPreparedConnection: mocks.readPreparedConnection, })); +// Stubbed at the direct dependency rather than letting the real module pull in +// `useSettings` -> `state/server`, which would drag the whole settings and +// connection graph into a test that only cares about the browser chrome. +vi.mock("~/browser/browserDefaults", () => ({ + useBrowserDefaults: () => ({ + viewport: FILL_PREVIEW_VIEWPORT, + zoomFactor: DEFAULT_PREVIEW_ZOOM_FACTOR, + appearance: DEFAULT_PREVIEW_APPEARANCE, + autoShowFloatingPreview: true, + }), + getBrowserDefaults: () => ({ + viewport: FILL_PREVIEW_VIEWPORT, + zoomFactor: DEFAULT_PREVIEW_ZOOM_FACTOR, + appearance: DEFAULT_PREVIEW_APPEARANCE, + autoShowFloatingPreview: true, + }), + browserDefaultOpenViewport: () => FILL_PREVIEW_VIEWPORT, + browserDefaultTabState: () => ({ + zoomFactor: DEFAULT_PREVIEW_ZOOM_FACTOR, + colorScheme: DEFAULT_PREVIEW_APPEARANCE, + }), + browserResponsiveViewportForToggle: () => ({ + _tag: "freeform" as const, + width: 1024, + height: 768, + }), +})); + vi.mock("~/composerDraftStore", () => ({ useComposerDraftStore: ( select: (store: { addPreviewAnnotation: () => void; addImage: () => void }) => unknown, diff --git a/apps/web/src/components/preview/addBrowserSurface.test.ts b/apps/web/src/components/preview/addBrowserSurface.test.ts index 5dfc1a42e9..4299374b32 100644 --- a/apps/web/src/components/preview/addBrowserSurface.test.ts +++ b/apps/web/src/components/preview/addBrowserSurface.test.ts @@ -1,4 +1,9 @@ -import type { PreviewOpenInput, PreviewSessionSnapshot, ScopedThreadRef } from "@t3tools/contracts"; +import { + FILL_PREVIEW_VIEWPORT, + type PreviewOpenInput, + type PreviewSessionSnapshot, + type ScopedThreadRef, +} from "@t3tools/contracts"; import { AsyncResult } from "effect/unstable/reactivity"; import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -40,7 +45,10 @@ describe("addBrowserSurface", () => { await addBrowserSurface({ threadRef, openPreview: ({ input }) => openPreview(input) }); - expect(openPreview).toHaveBeenCalledWith({ threadId: "thread-1" }); + expect(openPreview).toHaveBeenCalledWith({ + threadId: "thread-1", + viewport: FILL_PREVIEW_VIEWPORT, + }); expect(Object.keys(readThreadPreviewState(threadRef).sessions)).toEqual(["tab-1", "tab-2"]); expect( selectThreadRightPanelState( diff --git a/apps/web/src/components/preview/openPreviewSession.test.ts b/apps/web/src/components/preview/openPreviewSession.test.ts index 2e84fec5e6..138c3dd368 100644 --- a/apps/web/src/components/preview/openPreviewSession.test.ts +++ b/apps/web/src/components/preview/openPreviewSession.test.ts @@ -1,4 +1,9 @@ -import type { PreviewOpenInput, PreviewSessionSnapshot, ScopedThreadRef } from "@t3tools/contracts"; +import { + FILL_PREVIEW_VIEWPORT, + type PreviewOpenInput, + type PreviewSessionSnapshot, + type ScopedThreadRef, +} from "@t3tools/contracts"; import * as Cause from "effect/Cause"; import { AsyncResult } from "effect/unstable/reactivity"; import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -41,7 +46,10 @@ describe("openPreviewSession", () => { threadRef, }); - expect(open).toHaveBeenCalledWith({ threadId: "thread-1" }); + expect(open).toHaveBeenCalledWith({ + threadId: "thread-1", + viewport: FILL_PREVIEW_VIEWPORT, + }); expect(readThreadPreviewState(threadRef).snapshot).toEqual(idleSnapshot); expect(readThreadPreviewState(threadRef).recentlySeenUrls).toEqual([]); }); @@ -55,7 +63,11 @@ describe("openPreviewSession", () => { url: "t3.chat", }); - expect(open).toHaveBeenCalledWith({ threadId: "thread-1", url: "t3.chat" }); + expect(open).toHaveBeenCalledWith({ + threadId: "thread-1", + url: "t3.chat", + viewport: FILL_PREVIEW_VIEWPORT, + }); expect(readThreadPreviewState(threadRef).snapshot).toEqual(snapshot); expect(readThreadPreviewState(threadRef).recentlySeenUrls).toEqual(["https://t3.chat/"]); });