test(web): update preview tests for the new open and createTab shapes

`preview.open` now carries the configured default viewport and `createTab`
carries the zoom/appearance defaults, so the call-shape assertions had to move
with them.

PreviewView's test stubs `browserDefaults` directly rather than deepening the
`state/session` mock: the component now reaches `useSettings`, which pulls in
`state/server`, and a test about browser chrome shouldn't drag the settings and
connection graph along with it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5 committed 2026-08-15 16:26:16 +02:00
1 parent b4777dad6d
commit cca9dc8330
4 files changed
+74 -9

No files matched your search

@@ -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();
@@ -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,
@@ -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(
@@ -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/"]);
});