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

previewAutomationOpenReadiness.test.ts

141 lines4.7 KB

1import type { PreviewAutomationOpenInput, PreviewSessionSnapshot } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,
6 explicitlySuppressesPreviewMiniPlayer,
7 previewAutomationDefaultViewport,
8 previewAutomationOpenNeedsOverlay,
9 shouldAutoShowPreviewForAutomationUse,
10 shouldOpenPreviewMiniPlayer,
11} from "./previewAutomationOpenReadiness";
12​
13const snapshot = (navStatus: PreviewSessionSnapshot["navStatus"]): PreviewSessionSnapshot => ({
14 threadId: "thread-1",
15 tabId: "tab-1",
16 navStatus,
17 canGoBack: false,
18 canGoForward: false,
19 updatedAt: "2026-06-26T00:00:00.000Z",
20});
21​
22describe("preview automation open readiness", () => {
23 it("opens the inline preview by default", () => {
24 expect(shouldOpenPreviewMiniPlayer({} as PreviewAutomationOpenInput)).toBe(true);
25 });
26​
27 it("supports explicit opt-out and the legacy show alias", () => {
28 expect(shouldOpenPreviewMiniPlayer({ open: false } as PreviewAutomationOpenInput)).toBe(false);
29 expect(shouldOpenPreviewMiniPlayer({ show: false } as PreviewAutomationOpenInput)).toBe(false);
30 expect(
31 shouldOpenPreviewMiniPlayer({ open: true, show: false } as PreviewAutomationOpenInput),
32 ).toBe(true);
33 });
34​
35 it("does not wait for a desktop overlay when opening an empty tab", () => {
36 expect(
37 previewAutomationOpenNeedsOverlay(
38 {} as PreviewAutomationOpenInput,
39 snapshot({ _tag: "Idle" }),
40 ),
41 ).toBe(false);
42 });
43​
44 it("waits when an empty tab is immediately given a URL", () => {
45 expect(
46 previewAutomationOpenNeedsOverlay(
47 { url: "https://example.com" } as PreviewAutomationOpenInput,
48 snapshot({ _tag: "Idle" }),
49 ),
50 ).toBe(true);
51 });
52​
53 it("waits for existing tabs that already have rendered content", () => {
54 expect(
55 previewAutomationOpenNeedsOverlay(
56 {} as PreviewAutomationOpenInput,
57 snapshot({
58 _tag: "Success",
59 url: "https://example.com/",
60 title: "Example",
61 }),
62 ),
63 ).toBe(true);
64 });
65​
66 it("gives newly-created automation tabs a stable desktop viewport", () => {
67 expect(previewAutomationDefaultViewport(false, snapshot({ _tag: "Idle" }))).toEqual(
68 DEFAULT_PREVIEW_AUTOMATION_VIEWPORT,
69 );
70 });
71​
72 it("preserves reused and already-fixed browser viewports", () => {
73 expect(previewAutomationDefaultViewport(true, snapshot({ _tag: "Idle" }))).toBeNull();
74 expect(
75 previewAutomationDefaultViewport(false, {
76 ...snapshot({ _tag: "Idle" }),
77 viewport: { _tag: "freeform", width: 900, height: 600 },
78 }),
79 ).toBeNull();
80 });
81});
82​
83describe("shouldOpenPreviewMiniPlayer with the floating-preview preference", () => {
84 it("honours the preference when the agent said nothing either way", () => {
85 // `preview_open` no longer arrives with `open` pre-filled, so an agent
86 // that omitted it leaves the decision to the user's setting.
87 expect(shouldOpenPreviewMiniPlayer({}, false)).toBe(false);
88 expect(shouldOpenPreviewMiniPlayer({}, true)).toBe(true);
89 });
90​
91 it("lets an explicit request outrank the preference in both directions", () => {
92 expect(shouldOpenPreviewMiniPlayer({ open: true }, false)).toBe(true);
93 expect(shouldOpenPreviewMiniPlayer({ open: false }, true)).toBe(false);
94 expect(shouldOpenPreviewMiniPlayer({ show: true }, false)).toBe(true);
95 });
96​
97 it("distinguishes an explicit background request from a disabled preference", () => {
98 expect(explicitlySuppressesPreviewMiniPlayer({ open: false })).toBe(true);
99 expect(explicitlySuppressesPreviewMiniPlayer({ show: false })).toBe(true);
100 expect(explicitlySuppressesPreviewMiniPlayer({})).toBe(false);
101 });
102});
103​
104describe("auto-show for existing automation tabs", () => {
105 it("records floating-preview intent whenever an agent uses the tab", () => {
106 expect(
107 shouldAutoShowPreviewForAutomationUse({
108 operation: "navigate",
109 autoShowFloatingPreview: true,
110 presentationSuppressed: false,
111 }),
112 ).toBe(true);
113 });
114​
115 it("leaves explicit opens and background-only tabs alone", () => {
116 expect(
117 shouldAutoShowPreviewForAutomationUse({
118 operation: "open",
119 autoShowFloatingPreview: true,
120 presentationSuppressed: false,
121 }),
122 ).toBe(false);
123 expect(
124 shouldAutoShowPreviewForAutomationUse({
125 operation: "click",
126 autoShowFloatingPreview: true,
127 presentationSuppressed: true,
128 }),
129 ).toBe(false);
130 });
131​
132 it("honours the auto-show preference for reused tabs", () => {
133 expect(
134 shouldAutoShowPreviewForAutomationUse({
135 operation: "snapshot",
136 autoShowFloatingPreview: false,
137 presentationSuppressed: false,
138 }),
139 ).toBe(false);
140 });
141});