79 lines · 2.5 KB · TypeScript
RawDownload
import type { PreviewAutomationOpenInput, PreviewSessionSnapshot } from "@t3tools/contracts";import { describe, expect, it } from "vite-plus/test"; import {  DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,  previewAutomationDefaultViewport,  previewAutomationOpenNeedsOverlay,  shouldOpenPreviewMiniPlayer,} from "./previewAutomationOpenReadiness"; const snapshot = (navStatus: PreviewSessionSnapshot["navStatus"]): PreviewSessionSnapshot => ({  threadId: "thread-1",  tabId: "tab-1",  navStatus,  canGoBack: false,  canGoForward: false,  updatedAt: "2026-06-26T00:00:00.000Z",}); describe("preview automation open readiness", () => {  it("opens the inline preview by default", () => {    expect(shouldOpenPreviewMiniPlayer({} as PreviewAutomationOpenInput)).toBe(true);  });   it("supports explicit opt-out and the legacy show alias", () => {    expect(shouldOpenPreviewMiniPlayer({ open: false } as PreviewAutomationOpenInput)).toBe(false);    expect(shouldOpenPreviewMiniPlayer({ show: false } as PreviewAutomationOpenInput)).toBe(false);    expect(      shouldOpenPreviewMiniPlayer({ open: true, show: false } as PreviewAutomationOpenInput),    ).toBe(true);  });   it("does not wait for a desktop overlay when opening an empty tab", () => {    expect(      previewAutomationOpenNeedsOverlay(        {} as PreviewAutomationOpenInput,        snapshot({ _tag: "Idle" }),      ),    ).toBe(false);  });   it("waits when an empty tab is immediately given a URL", () => {    expect(      previewAutomationOpenNeedsOverlay(        { url: "https://example.com" } as PreviewAutomationOpenInput,        snapshot({ _tag: "Idle" }),      ),    ).toBe(true);  });   it("waits for existing tabs that already have rendered content", () => {    expect(      previewAutomationOpenNeedsOverlay(        {} as PreviewAutomationOpenInput,        snapshot({          _tag: "Success",          url: "https://example.com/",          title: "Example",        }),      ),    ).toBe(true);  });   it("gives newly-created automation tabs a stable desktop viewport", () => {    expect(previewAutomationDefaultViewport(false, snapshot({ _tag: "Idle" }))).toEqual(      DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,    );  });   it("preserves reused and already-fixed browser viewports", () => {    expect(previewAutomationDefaultViewport(true, snapshot({ _tag: "Idle" }))).toBeNull();    expect(      previewAutomationDefaultViewport(false, {        ...snapshot({ _tag: "Idle" }),        viewport: { _tag: "freeform", width: 900, height: 600 },      }),    ).toBeNull();  });});