Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

previewAutomationOpenReadiness.test.ts

94 lines3.3 KB

1import type { PreviewAutomationOpenInput, PreviewSessionSnapshot } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,
6 previewAutomationDefaultViewport,
7 previewAutomationOpenNeedsOverlay,
8 shouldOpenPreviewMiniPlayer,
9} from "./previewAutomationOpenReadiness";
10​
11const snapshot = (navStatus: PreviewSessionSnapshot["navStatus"]): PreviewSessionSnapshot => ({
12 threadId: "thread-1",
13 tabId: "tab-1",
14 navStatus,
15 canGoBack: false,
16 canGoForward: false,
17 updatedAt: "2026-06-26T00:00:00.000Z",
18});
19​
20describe("preview automation open readiness", () => {
21 it("opens the inline preview by default", () => {
22 expect(shouldOpenPreviewMiniPlayer({} as PreviewAutomationOpenInput)).toBe(true);
23 });
24​
25 it("supports explicit opt-out and the legacy show alias", () => {
26 expect(shouldOpenPreviewMiniPlayer({ open: false } as PreviewAutomationOpenInput)).toBe(false);
27 expect(shouldOpenPreviewMiniPlayer({ show: false } as PreviewAutomationOpenInput)).toBe(false);
28 expect(
29 shouldOpenPreviewMiniPlayer({ open: true, show: false } as PreviewAutomationOpenInput),
30 ).toBe(true);
31 });
32​
33 it("does not wait for a desktop overlay when opening an empty tab", () => {
34 expect(
35 previewAutomationOpenNeedsOverlay(
36 {} as PreviewAutomationOpenInput,
37 snapshot({ _tag: "Idle" }),
38 ),
39 ).toBe(false);
40 });
41​
42 it("waits when an empty tab is immediately given a URL", () => {
43 expect(
44 previewAutomationOpenNeedsOverlay(
45 { url: "https://example.com" } as PreviewAutomationOpenInput,
46 snapshot({ _tag: "Idle" }),
47 ),
48 ).toBe(true);
49 });
50​
51 it("waits for existing tabs that already have rendered content", () => {
52 expect(
53 previewAutomationOpenNeedsOverlay(
54 {} as PreviewAutomationOpenInput,
55 snapshot({
56 _tag: "Success",
57 url: "https://example.com/",
58 title: "Example",
59 }),
60 ),
61 ).toBe(true);
62 });
63​
64 it("gives newly-created automation tabs a stable desktop viewport", () => {
65 expect(previewAutomationDefaultViewport(false, snapshot({ _tag: "Idle" }))).toEqual(
66 DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,
67 );
68 });
69​
70 it("preserves reused and already-fixed browser viewports", () => {
71 expect(previewAutomationDefaultViewport(true, snapshot({ _tag: "Idle" }))).toBeNull();
72 expect(
73 previewAutomationDefaultViewport(false, {
74 ...snapshot({ _tag: "Idle" }),
75 viewport: { _tag: "freeform", width: 900, height: 600 },
76 }),
77 ).toBeNull();
78 });
79});
80​
81describe("shouldOpenPreviewMiniPlayer with the floating-preview preference", () => {
82 it("honours the preference when the agent said nothing either way", () => {
83 // `preview_open` no longer arrives with `open` pre-filled, so an agent
84 // that omitted it leaves the decision to the user's setting.
85 expect(shouldOpenPreviewMiniPlayer({}, false)).toBe(false);
86 expect(shouldOpenPreviewMiniPlayer({}, true)).toBe(true);
87 });
88​
89 it("lets an explicit request outrank the preference in both directions", () => {
90 expect(shouldOpenPreviewMiniPlayer({ open: true }, false)).toBe(true);
91 expect(shouldOpenPreviewMiniPlayer({ open: false }, true)).toBe(false);
92 expect(shouldOpenPreviewMiniPlayer({ show: true }, false)).toBe(true);
93 });
94});