deck
"], sha: "c".repeat(40), }); - const user = userEvent.setup(); - render(deck
"); - expect(screen.queryByTestId("html-frame")).toBeNull(); - await user.click(screen.getByTestId("lane-file-preview")); - const frame = await screen.findByTestId("html-frame"); - expect(frame.getAttribute("srcdoc")).toContain("deck
"); - expect(screen.getByRole("button", { name: "Preview", pressed: true })).toBeInTheDocument(); - await user.click(screen.getByRole("button", { name: "Whole file", pressed: false })); - expect(await screen.findByTestId("lane-file-editor")).toHaveValue("deck
"); - expect(screen.queryByTestId("html-frame")).toBeNull(); + const fetchSpy = vi + .spyOn(globalThis, "fetch") + .mockResolvedValue(new Response("deck
", { status: 200 })); + try { + const user = userEvent.setup(); + render(deck
"); + expect(screen.queryByTestId("html-frame")).toBeNull(); + await user.click(screen.getByTestId("lane-file-preview")); + const modal = await screen.findByTestId("html-viewer"); + const frame = await within(modal).findByTestId("html-frame"); + expect(frame.getAttribute("srcdoc")).toContain("deck
"); + expect(frame.getAttribute("sandbox")).not.toContain("allow-same-origin"); + await user.keyboard("{Escape}"); + await waitFor(() => expect(screen.queryByTestId("html-viewer")).toBeNull()); + // The source stayed where it was, under the modal. + expect(screen.getByTestId("lane-file-editor")).toHaveValue("deck
"); + } finally { + fetchSpy.mockRestore(); + } }); - it("opens a changed HTML file on its Changes, the page only after Preview", async () => { + it("offers Preview on a changed HTML file's Changes, opening the page in a modal", async () => { vi.mocked(api.lanes.changes).mockResolvedValue( changes({ files: [ @@ -583,28 +592,21 @@ describe("LaneChangesPanel", () => { ], }) ); - vi.mocked(api.lanes.gitFile).mockResolvedValue({ - available: true, - path: "deck.html", - rev: "work", - binary: false, - truncated: false, - lines: ["deck
"], - sha: "c".repeat(40), - }); - const user = userEvent.setup(); - render(deck
"); - expect(frame.getAttribute("sandbox")).not.toContain("allow-same-origin"); - // Back to Changes: the diff again, not the page. - await user.click(screen.getByRole("button", { name: "Changes", pressed: false })); - await screen.findByRole("button", { name: "Changes", pressed: true }); - await waitFor(() => expect(screen.queryByTestId("html-frame")).toBeNull()); + const fetchSpy = vi + .spyOn(globalThis, "fetch") + .mockResolvedValue(new Response("deck
", { status: 200 })); + try { + const user = userEvent.setup(); + render(two
"]); const tool = (id: string, input: Record