| 1 | import type { PreviewSessionSnapshot, ProjectScript } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { getConfiguredPreviewUrls, shouldShowPreviewEmptyState } from "./previewEmptyStateLogic"; |
| 5 | |
| 6 | const snapshot = (navStatus: PreviewSessionSnapshot["navStatus"]): PreviewSessionSnapshot => ({ |
| 7 | threadId: "thread-1", |
| 8 | tabId: "tab-1", |
| 9 | navStatus, |
| 10 | canGoBack: false, |
| 11 | canGoForward: false, |
| 12 | updatedAt: "2026-06-12T20:00:00.000Z", |
| 13 | }); |
| 14 | |
| 15 | describe("shouldShowPreviewEmptyState", () => { |
| 16 | it("shows quick-open options for a new idle browser tab", () => { |
| 17 | expect(shouldShowPreviewEmptyState(snapshot({ _tag: "Idle" }))).toBe(true); |
| 18 | }); |
| 19 | |
| 20 | it("shows browser content once navigation starts", () => { |
| 21 | expect( |
| 22 | shouldShowPreviewEmptyState( |
| 23 | snapshot({ _tag: "Loading", url: "http://localhost:5173", title: "" }), |
| 24 | ), |
| 25 | ).toBe(false); |
| 26 | }); |
| 27 | }); |
| 28 | |
| 29 | describe("getConfiguredPreviewUrls", () => { |
| 30 | it("collects configured preview URLs from project scripts", () => { |
| 31 | const scripts = [ |
| 32 | { previewUrl: "http://localhost:5173" }, |
| 33 | {}, |
| 34 | { previewUrl: "http://localhost:3000" }, |
| 35 | ] as ProjectScript[]; |
| 36 | |
| 37 | expect(getConfiguredPreviewUrls(scripts)).toEqual([ |
| 38 | "http://localhost:5173", |
| 39 | "http://localhost:3000", |
| 40 | ]); |
| 41 | }); |
| 42 | }); |