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

previewNavigationReadiness.test.ts

56 lines1.6 KB

1import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3​
4const mocks = vi.hoisted(() => ({
5 readThreadPreviewState: vi.fn(),
6}));
7​
8vi.mock("~/previewStateStore", () => ({
9 applyPreviewServerSnapshot: vi.fn(),
10 readThreadPreviewState: mocks.readThreadPreviewState,
11 reconcilePreviewServerSessions: vi.fn(),
12 updatePreviewServerSnapshot: vi.fn(),
13}));
14​
15vi.mock("./previewBridge", () => ({
16 previewBridge: {
17 automation: {
18 evaluate: vi.fn(),
19 status: vi.fn(),
20 },
21 },
22}));
23​
24import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
25​
26import { PreviewAutomationTargetUnavailableError } from "./previewAutomationErrors";
27import { waitForNavigationReadiness } from "./previewNavigationReadiness";
28​
29describe("waitForNavigationReadiness", () => {
30 it("rejects a replaced runtime target even when readiness polling is disabled", async () => {
31 const threadRef = {
32 environmentId: EnvironmentId.make("environment-2"),
33 threadId: ThreadId.make("thread-1"),
34 };
35 const tabId = "tab_1";
36 const staleRuntimeTabId = previewRuntimeTabId(threadRef, "epoch-1", tabId);
37 mocks.readThreadPreviewState.mockReturnValue({
38 serverEpoch: "epoch-2",
39 sessions: {
40 [tabId]: { tabId },
41 },
42 });
43​
44 await expect(
45 waitForNavigationReadiness(
46 threadRef,
47 "request-1",
48 tabId,
49 staleRuntimeTabId,
50 "navigate",
51 "none",
52 100,
53 ),
54 ).rejects.toBeInstanceOf(PreviewAutomationTargetUnavailableError);
55 });
56});