import { test, expect, type Page } from "@playwright/test"; import path from "node:path"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // PRESENT MODE (lib/report/present.mjs, components/projects/present/; knobs.md, "Present mode"): the cut as slides, // one at a time, navigated like a deck. Fixture: e2e/fixtures/present-fixture.mjs -- section-0 (the opening), c01 // (a clip), section-1 ("The posts"), presentchan-x/1 (a narrated reply to a private account, a redacted name, a // censored picture), presentchan-x/2 (words only), t01 (a teaser). // // PRESENT_SHOTS (a directory): the three slides' screenshots at 1366×768 go there too. // --------------------------------------------------------------------------- const PROJECT = "reports/present-fixture"; const SHOTS = process.env.PRESENT_SHOTS ?? null; const ORDER = ["section-0", "c01", "section-1", "presentchan-x/1", "presentchan-x/2", "t01"]; const root = (page: Page) => page.locator("[data-present]"); const card = (page: Page) => page.frameLocator('[data-post-card-frame="read"]'); const shot = async (page: Page, name: string) => { await page.screenshot({ path: test.info().outputPath(name) }); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, name) }); }; test.beforeEach(async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); }); test("arrow keys step the slides in cut order and the address follows; Back returns; a deep link opens its slide; the outline jumps", async ({ page }) => { await page.goto(urls.presentHref(PROJECT)); await expect(root(page)).toHaveAttribute("data-present-slide", "section-0", { timeout: 30_000 }); await expect(page).toHaveURL(/#section-0$/); // An app: the whole of it in the window, no page scroll. expect(await page.evaluate(() => document.documentElement.scrollHeight <= window.innerHeight)).toBe(true); await expect(page.locator("[data-present-progress]")).toHaveText("1 / 6"); await expect(page.locator("[data-present-section-label]")).toHaveText("The Present Fixture"); await expect(page.locator("[data-present-cell]")).toHaveCount(6); expect(await page.locator("[data-present-cell]").evaluateAll((els) => els.map((e) => e.getAttribute("data-present-cell")))).toEqual(ORDER); for (const [i, id] of ORDER.slice(1).entries()) { await page.keyboard.press(i % 2 ? "PageDown" : "ArrowRight"); await expect(root(page)).toHaveAttribute("data-present-slide", id); await expect(page).toHaveURL(new RegExp(`#${id.replace("/", "\\/")}$`)); await expect(page.locator(`[data-present-cell="${id}"]`)).toHaveAttribute("aria-current", "true"); if (id === "c01") { await expect(page.locator("[data-present-clip-title]")).toHaveText("24 Oct 2020"); await expect(page.locator("[data-present-clip-video]")).toHaveCount(1); } if (id === "section-1") await expect(page.locator("[data-present-section-label]")).toHaveText("The posts"); } await expect(page.locator("[data-present-progress]")).toHaveText("6 / 6"); // Past the end: nothing moves. await page.keyboard.press("ArrowRight"); await expect(root(page)).toHaveAttribute("data-present-slide", "t01"); await expect(page.locator("[data-present-teaser]")).toContainText("Next Season"); // ← and Shift+Space back; Home and End. await page.keyboard.press("ArrowLeft"); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/2"); await expect(page.locator("[data-present-progress]")).toHaveText("5 / 6 · Oct 31"); await page.keyboard.press("Shift+Space"); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1"); await page.keyboard.press("Home"); await expect(root(page)).toHaveAttribute("data-present-slide", "section-0"); await page.keyboard.press("End"); await expect(root(page)).toHaveAttribute("data-present-slide", "t01"); // The browser's Back: the slide before, from the history. await page.goBack(); await expect(root(page)).toHaveAttribute("data-present-slide", "section-0"); await page.goBack(); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1"); // A click on the stage's right third: on; its left third: back. await page.locator('[data-present-zone="next"]').click(); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/2"); await page.locator('[data-present-zone="prev"]').click(); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1"); // A deep link opens on its slide. await page.goto(urls.presentHref(PROJECT, { slide: "presentchan-x/2" })); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/2", { timeout: 30_000 }); await expect(page.locator("[data-present-progress]")).toHaveText("5 / 6 · Oct 31"); // The outline: a click on a cell jumps there; a section's label to its first slide. await page.locator('[data-present-cell="c01"]').click(); await expect(root(page)).toHaveAttribute("data-present-slide", "c01"); await expect(page).toHaveURL(/#c01$/); await page.locator('[data-present-group-label="section-1"]').click(); await expect(root(page)).toHaveAttribute("data-present-slide", "section-1"); }); test("the screenshots: a post with its thread and attachment, a clip, a section divider", async ({ page }) => { await page.goto(urls.presentHref(PROJECT, { slide: "presentchan-x/1" })); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1", { timeout: 30_000 }); // The card as the build draws it: the private parent blurred, the picture censored in its slot. await expect(card(page).locator('[data-post-parent="0"][data-redacted]')).toHaveCount(1, { timeout: 30_000 }); await expect(page.locator('[data-post-media="0"]')).toHaveAttribute("data-post-blurred", "band", { timeout: 15_000 }); await page.keyboard.press("p"); await expect(root(page)).toHaveAttribute("data-present-state", "paused"); await page.waitForTimeout(500); await shot(page, "present-post.png"); await page.goto(urls.presentHref(PROJECT, { slide: "c01" })); await expect(root(page)).toHaveAttribute("data-present-slide", "c01", { timeout: 30_000 }); await expect.poll(() => page.locator("[data-present-clip-video]").evaluate((v: HTMLVideoElement) => v.readyState), { timeout: 15_000 }).toBeGreaterThanOrEqual(2); await page.keyboard.press("p"); await shot(page, "present-clip.png"); await page.goto(urls.presentHref(PROJECT, { slide: "section-1" })); await expect(page.locator("[data-present-section-label]")).toHaveText("The posts", { timeout: 30_000 }); await shot(page, "present-section.png"); }); test("the settings persist across a reload; narration off silences the take; a censor toggle changes the card", async ({ page }) => { await page.goto(urls.presentHref(PROJECT, { slide: "presentchan-x/1" })); await expect(root(page)).toHaveAttribute("data-present-settings-loaded", "1", { timeout: 30_000 }); await page.evaluate(() => window.localStorage.removeItem("umtool.present.settings.v1")); await page.reload(); await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1", { timeout: 30_000 }); await expect(root(page)).toHaveAttribute("data-present-settings-loaded", "1"); // As the build draws it, by default: the made-up name a bar, its letters nowhere in the card. await expect(card(page).locator("[data-post-blanked]")).toHaveCount(2, { timeout: 30_000 }); await expect(card(page).locator("[data-post-words]")).not.toContainText("Quentin"); // The narration: its take, heard. const voice = page.locator("audio[data-post-narration-audio]"); await expect(voice).toHaveCount(1); expect(await voice.evaluate((a: HTMLAudioElement) => a.muted)).toBe(false); await page.keyboard.press("s"); const drawer = page.locator("[data-present-settings]"); await expect(drawer).toBeVisible(); // The kinds this slide carries, counted. await expect(drawer.locator('[data-present-censor-count="names"]')).toHaveText("1 here"); await expect(drawer.locator('[data-present-censor-count="authors"]')).toHaveText("1 here"); await expect(drawer.locator('[data-present-censor-count="pictures"]')).toHaveText("1 here"); // Narration off: the take is silent. await drawer.locator('[data-present-toggle="narration"]').uncheck(); await expect.poll(() => voice.evaluate((a: HTMLAudioElement) => a.muted)).toBe(true); // A censor toggle: the redacted name shown, the card drawn again. await drawer.locator('[data-present-toggle="names"]').uncheck(); await expect(card(page).locator("[data-post-words]")).toContainText("Quentin Example", { timeout: 30_000 }); await expect(card(page).locator("[data-post-blanked]")).toHaveCount(0); // The pictures: as captured. await drawer.locator('[data-present-toggle="pictures"]').uncheck(); await expect(page.locator('[data-post-media="0"]')).not.toHaveAttribute("data-post-blurred", /.+/); await drawer.locator('[data-present-toggle="autoAdvance"]').check(); await drawer.locator("[data-present-linger]").fill("3"); // Reloaded: every setting as left. await page.reload(); await expect(root(page)).toHaveAttribute("data-present-settings-loaded", "1", { timeout: 30_000 }); await page.keyboard.press("s"); await expect(drawer.locator('[data-present-toggle="narration"]')).not.toBeChecked(); await expect(drawer.locator('[data-present-toggle="names"]')).not.toBeChecked(); await expect(drawer.locator('[data-present-toggle="pictures"]')).not.toBeChecked(); await expect(drawer.locator('[data-present-toggle="slurs"]')).toBeChecked(); await expect(drawer.locator('[data-present-toggle="autoAdvance"]')).toBeChecked(); await expect(drawer.locator("[data-present-linger]")).toHaveValue("3"); await expect(card(page).locator("[data-post-words]")).toContainText("Quentin Example", { timeout: 30_000 }); expect(await voice.evaluate((a: HTMLAudioElement) => a.muted)).toBe(true); // Names back on: the bar again. await drawer.locator('[data-present-toggle="names"]').check(); await expect(card(page).locator("[data-post-blanked]")).toHaveCount(2, { timeout: 30_000 }); // Escape closes the drawer; settings back to the defaults for the next run. await page.keyboard.press("Escape"); await expect(drawer).toHaveCount(0); await page.evaluate(() => window.localStorage.removeItem("umtool.present.settings.v1")); }); test("auto-advance moves on once a slide is read and its linger is over", async ({ page }) => { await page.goto(urls.presentHref(PROJECT, { slide: "section-1" })); await expect(root(page)).toHaveAttribute("data-present-settings-loaded", "1", { timeout: 30_000 }); await page.evaluate(() => window.localStorage.setItem("umtool.present.settings.v1", JSON.stringify({ autoAdvance: true, linger: 0.2 }))); await page.reload(); await expect(root(page)).toHaveAttribute("data-present-slide", "section-1", { timeout: 30_000 }); // A section divider reads for 2.5 s: then the post after it. await expect(root(page)).toHaveAttribute("data-present-slide", "presentchan-x/1", { timeout: 10_000 }); await page.evaluate(() => window.localStorage.removeItem("umtool.present.settings.v1")); }); test("the project head links to present mode", async ({ page }) => { await page.goto(urls.projectHref(PROJECT, { tab: "cut" })); await expect(page.locator('[data-present-link="header"]')).toHaveAttribute("href", urls.presentHref(PROJECT)); }); // THE WORKSPACE'S PRESENT MODE (umtool redesign L7b): the same deck, over the workspace, at `?mode=present`. test("in the workspace: Present ⛶ is the deck full screen, the arrows move it, Esc is back to Edit; the old /present 308s here", async ({ page }) => { await page.goto(urls.workspaceHref(PROJECT)); await expect(page.locator("[data-ws-mode-present]")).toHaveAttribute("href", urls.presentHref(PROJECT)); await page.locator("[data-ws-mode-present]").click(); await expect(page).toHaveURL(/[?&]mode=present/); await expect(root(page)).toHaveAttribute("data-present-slide", "section-0", { timeout: 30_000 }); // Full screen: the deck covers the window, nothing of the workspace shows around it. const box = await root(page).boundingBox(); expect(box).toMatchObject({ x: 0, y: 0, width: 1366, height: 768 }); await page.keyboard.press("ArrowRight"); await expect(root(page)).toHaveAttribute("data-present-slide", "c01"); await expect(page).toHaveURL(/mode=present#c01$/); await shot(page, "ws-present.png"); // ⌘K over the deck: its Esc closes the palette, never present mode under it; the arrows are the palette's. await page.keyboard.press("Control+k"); const jump = page.locator("dialog[open]"); await expect(jump).toBeVisible(); await page.keyboard.press("ArrowRight"); await expect(root(page)).toHaveAttribute("data-present-slide", "c01"); await page.keyboard.press("Escape"); await expect(jump).toHaveCount(0); await expect(root(page)).toHaveCount(1); // Esc: the settings first, when open; then back to Edit. await page.keyboard.press("s"); await expect(page.locator("[data-present-settings]")).toBeVisible(); await page.keyboard.press("Escape"); await expect(page.locator("[data-present-settings]")).toHaveCount(0); await expect(root(page)).toHaveCount(1); await page.keyboard.press("Escape"); await expect(root(page)).toHaveCount(0); await expect(page).not.toHaveURL(/mode=/); await expect(page.locator("[data-ws-mode-edit]")).toHaveAttribute("aria-current", "page"); // The browser's Back: presenting again, on the slide it left. await page.goBack(); await expect(root(page)).toHaveAttribute("data-present-slide", "c01", { timeout: 30_000 }); // The old address: a 308 to the mode, its take kept. for (const [old, now] of [ [urls.legacyPresentHref(PROJECT), urls.presentHref(PROJECT)], [urls.legacyPresentHref(PROJECT, { take: "v1" }), urls.presentHref(PROJECT, { take: "v1" })], ]) { const res = await page.request.get(old, { maxRedirects: 0 }); expect(res.status(), old).toBe(308); expect(res.headers()["location"], old).toBe(now); } }); test("a 9:16 cut presents tall (the stacked vertical deck); on a phone the deck fits the width", async ({ page }) => { const V = "reports/vertical-deck-fixture"; await page.goto(urls.presentHref(V)); await expect(root(page)).toHaveAttribute("data-present-slide", /.+/, { timeout: 30_000 }); const stage = await page.locator("[data-present-stage]").boundingBox(); expect(stage).not.toBeNull(); expect(stage!.height).toBeGreaterThan(stage!.width * 1.6); await shot(page, "ws-present-tall.png"); await page.setViewportSize({ width: 390, height: 844 }); await page.goto(urls.presentHref(PROJECT)); await expect(root(page)).toHaveAttribute("data-present-slide", "section-0", { timeout: 30_000 }); expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true); await expect(page.locator("[data-present-exit]")).toBeInViewport(); await page.locator('[data-present-zone="next"]').click(); await expect(root(page)).toHaveAttribute("data-present-slide", "c01"); await page.locator("[data-present-exit]").click(); await expect(root(page)).toHaveCount(0); });