From 576ff9a44439aedb7ab85cafb6b7eaaa2d7fef5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 11 Oct 2026 13:15:02 +0200 Subject: [PATCH] test(documents): pin that Open in new tab hands over the preview's bytes --- e2e/documents.spec.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/e2e/documents.spec.ts b/e2e/documents.spec.ts index 8e5a8f76d..a186b6996 100644 --- a/e2e/documents.spec.ts +++ b/e2e/documents.spec.ts @@ -232,6 +232,45 @@ test.describe("document vault", () => { await expect(sheet.locator("iframe")).toBeVisible({ timeout: 5_000 }); }); + test("a PDF opens in a new browser tab from the fetched bytes", async ({ + page, + }) => { + // Headless Chromium has no PDF viewer and turns a PDF tab into a + // download, so the tab itself is not observable here. Record what the + // control hands to `window.open` instead, and read the bytes behind it. + await page.addInitScript(() => { + const calls: unknown[][] = []; + (window as unknown as { __opened: unknown[][] }).__opened = calls; + window.open = (...args: unknown[]) => { + calls.push(args); + return null; + }; + }); + await page.goto(`/documents?episode=${KNIE_EPISODE_ID}&view=compact&q=MRT`); + await openButton(page, "MRT Knie").click(); + const sheet = page.getByRole("dialog", { name: "MRT Knie" }); + await expect(sheet.locator("iframe")).toBeVisible({ timeout: 5_000 }); + const open = sheet.locator('[data-slot="document-open-in-tab"]'); + // Enabled once the preview's bytes are in hand. + await expect(open).toBeEnabled(); + if (process.env.E2E_SHOT_DIR) { + await page.screenshot({ + path: `${process.env.E2E_SHOT_DIR}/open-in-tab-${test.info().project.name}.png`, + }); + } + await open.click(); + const opened = await page.evaluate( + () => (window as unknown as { __opened: string[][] }).__opened, + ); + // The object URL the preview already shows, not the serve route: a bare + // navigation would carry no record-session assertion. + const previewSrc = await sheet.locator("iframe").getAttribute("src"); + expect(previewSrc).toMatch(/^blob:/); + expect(opened).toEqual([[previewSrc, "_blank", "noopener"]]); + // The sheet stays where it was. + await expect(sheet).toBeVisible(); + }); + test("doctor flow B: the condition filter reaches the MRT report", async ({ page, }) => {