Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions apps/web/src/components/preview/PreviewView.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ const mocks = vi.hoisted(() => ({
idleDesktopTab: false,
idleDesktopOverlay: false,
loading: false,
loadFailed: false,
nativeServerTab: false,
streamedServerTab: false,
serverEpoch: null as string | null,
servers: [] as PreviewableServer[],
recordingTabIds: new Set<string>(),
recordingRuntimeTabId: null as string | null,
stopBrowserRecording: vi.fn(async (_runtimeTabId: string) => null),
recordVisitForThread: vi.fn(),
}));

Expand All @@ -51,6 +53,13 @@ const STUB_BROWSER_DEFAULTS = {
profiles: BUILT_IN_BROWSER_PROFILES,
profileId: DEFAULT_BROWSER_PROFILE_ID,
};
const LOAD_FAILED = {
_tag: "LoadFailed",
url: "http://example.com/",
title: "",
code: -102,
description: "ERR_CONNECTION_REFUSED",
} as const;

// The desktop bridge only exists inside Electron; the view reads it once at import.
vi.mock(import("./previewBridge"), async (original) => ({
Expand Down Expand Up @@ -105,9 +114,11 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
desktopByTabId: {
"tab-1": {
hasWebContents: true,
navStatus: mocks.idleDesktopOverlay
? { _tag: "Idle" }
: { _tag: "Success", url: "http://example.com/", title: "Example" },
navStatus: mocks.loadFailed
? LOAD_FAILED
: mocks.idleDesktopOverlay
? { _tag: "Idle" }
: { _tag: "Success", url: "http://example.com/", title: "Example" },
canGoBack: false,
canGoForward: false,
loading: mocks.loading,
Expand Down Expand Up @@ -139,7 +150,9 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
threadId: "thread-1",
tabId: "tab-1",
runtime: mocks.nativeServerTab || mocks.streamedServerTab ? "server" : "desktop",
navStatus: { _tag: "Success", url: "http://example.com/", title: "Example" },
navStatus: mocks.loadFailed
? LOAD_FAILED
: { _tag: "Success", url: "http://example.com/", title: "Example" },
canGoBack: false,
canGoForward: false,
updatedAt: "2026-07-13T00:00:00.000Z",
Expand All @@ -157,6 +170,7 @@ vi.mock(import("~/browser/browserRecording"), async (original) => ({
...(await original()),
findActiveBrowserRecordingRuntimeTabId: () => mocks.recordingRuntimeTabId,
useActiveBrowserRecordingTabIds: () => mocks.recordingTabIds,
stopBrowserRecording: mocks.stopBrowserRecording,
}));
vi.mock(import("./useDiscoveredLocalServers"), async (original) => ({
...(await original()),
Expand Down Expand Up @@ -236,6 +250,7 @@ function setup() {
mocks.idleDesktopTab = false;
mocks.idleDesktopOverlay = false;
mocks.loading = false;
mocks.loadFailed = false;
mocks.nativeServerTab = false;
mocks.streamedServerTab = false;
mocks.serverEpoch = null;
Expand Down Expand Up @@ -451,6 +466,19 @@ describe("PreviewView", () => {
expect(listeners.size).toBe(0);
});

it("stops an active recording after the page fails to load", async () => {
setup();
mocks.loadFailed = true;
mocks.recordingTabIds = new Set([TEST_RUNTIME_TAB_ID]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
await using _screen = await render(view());

const stop = page.getByRole("button", { name: "Stop recording" });
await expect.element(stop).toBeEnabled();
await userEvent.click(stop);

expect(mocks.stopBrowserRecording).toHaveBeenCalledWith(TEST_RUNTIME_TAB_ID);
});

it("focuses the address bar each time the focus-url shortcut fires", async () => {
setup();
await using _screen = await render(view());
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/preview/PreviewView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ export function PreviewView({
onSubmit={(next) => void handleSubmitUrl(next)}
onOpenInBrowser={tabId ? handleOpenInBrowser : undefined}
onCapture={previewBridge && tabId && !isServerTab ? handleCapture : undefined}
captureDisabled={!desktopOverlay || isUnreachable}
captureDisabled={recordingRuntimeTabId === null && (!desktopOverlay || isUnreachable)}
recording={recordingRuntimeTabId !== null}
onPictureInPicture={
tabId && (isServerTab || previewBridge) ? handlePictureInPicture : undefined
Expand Down
Loading