import { test, expect, type Page } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE INTRO AS A REAL, PLAYABLE BLOCK (lane intro-play; operator, 8 Nov 2026: "more first-class intro support (view // in play the cut)"; umtool/docs/knobs.md, "The intro, played and edited"): the cut's render.intro plays as the build // draws it -- its own page (report-to-video intro.mjs introPageHtml, composed by POST /api/report/chrome/intro) and // its sound -- in Play, as Present's first slide, first on the walk's stops; and the Cut tab's intro row opens an editor whose // live preview follows the unsaved knobs and whose Save writes the manifest. // // Fixture: e2e/fixtures/intro-play-fixture.mjs -- the Play cut opening on a title-card intro (the project's title, // "29 October 2026"), its sound intro.wav, and a whole-cut version v1. WRITES (the title, v1's patch): its own. // // INTRO_SHOTS (a directory): the surfaces' screenshots at 1366×768 go there too. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const PROJECT = "reports/intro-play-fixture"; const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "intro-play-fixture"); const SHOTS = process.env.INTRO_SHOTS ?? null; const manifest = () => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")) as { render: { intro?: unknown } }; const takeDoc = (id: string) => JSON.parse(readFileSync(path.join(DIR, "takes", id, "take.json"), "utf8")) as { patch: { render?: { intro?: unknown } } | null }; 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("Play opens on the intro as the build draws it -- its page, its words, its sound -- not a placeholder", async ({ page }) => { await page.goto(urls.playHref(PROJECT, { clip: "brand-intro", at: 3.4 })); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-item", "brand-intro", { timeout: 30_000 }); const intro = page.locator('[data-play-intro="brand-intro"]'); await expect(intro).toHaveAttribute("data-play-intro-ready", "1", { timeout: 30_000 }); await expect(intro).toHaveAttribute("data-play-intro-style", "title-card"); await expect(page.locator("[data-play-placeholder]")).toHaveCount(0); const frame = page.frameLocator('[data-testid="play-intro-iframe"]'); await expect(frame.locator('[data-k="tt"]')).toHaveText("The Intro Play Fixture"); await expect(frame.locator('[data-k="tl0"]')).toHaveText("29 October 2026"); // Its sound: the project's own file, through the intro route. await expect(intro.locator("[data-play-intro-audio]")).toHaveAttribute("src", /\/api\/report\/chrome\/intro\?.*sound=1.*path=intro\.wav/); const sound = await page.request.get(String(await intro.locator("[data-play-intro-audio]").getAttribute("src"))); expect(sound.status()).toBe(200); expect(sound.headers()["content-type"]).toBe("audio/wav"); await shot(page, "intro-play.png"); // Playing from the top: the sound runs with the clock, then the first clip takes over. await page.goto(urls.playHref(PROJECT, { clip: "brand-intro", at: 0.2 })); await expect(intro).toHaveAttribute("data-play-intro-ready", "1", { timeout: 30_000 }); await page.locator("[data-play-toggle]").click(); await expect(intro).toHaveAttribute("data-play-intro-sound", "playing", { timeout: 15_000 }); await expect(root).toHaveAttribute("data-play-item", "c01", { timeout: 20_000 }); await expect(intro).toHaveCount(0); }); test("Present opens the deck on the intro slide, playing the build's page", async ({ page }) => { await page.goto(urls.presentHref(PROJECT)); const root = page.locator("[data-present]"); await expect(root).toHaveAttribute("data-present-slide", "brand-intro", { timeout: 30_000 }); await expect(root).toHaveAttribute("data-present-kind", "intro"); await expect(page.locator('[data-present-cell]').first()).toHaveAttribute("data-present-cell", "brand-intro"); const intro = page.locator('[data-testid="present-intro"]'); await expect(intro).toHaveAttribute("data-play-intro-ready", "1", { timeout: 30_000 }); await expect(page.frameLocator('[data-testid="present-intro-iframe"]').locator('[data-k="tt"]')).toHaveText("The Intro Play Fixture"); await shot(page, "intro-present.png"); await page.keyboard.press("ArrowRight"); await expect(root).not.toHaveAttribute("data-present-slide", "brand-intro"); }); test("the walk lists the intro first: the walk's stops (a version's old walk address is its review pass, L7b)", async ({ page, request }) => { // A version's take walk is its review pass now (a 308): watched block by block, read-only. await page.goto(urls.takeWalkHref(PROJECT, "v1")); await expect(page).toHaveURL(new RegExp(`${urls.versionReviewHref(PROJECT, "v1").replace(/[?]/g, "\\?")}$`)); await expect(page.locator("[data-review-pass]")).toHaveAttribute("data-review-pass", "v1", { timeout: 30_000 }); const w = (await (await request.get(`/api/report/walk?project=${encodeURIComponent(PROJECT)}`)).json()) as { stops: string[]; intro: { style: string } | null; first: string | null }; expect(w.stops[0]).toBe("brand-intro"); expect(w.intro?.style).toBe("title-card"); expect(w.first).not.toBe("brand-intro"); }); test("the Cut tab's intro row: Edit opens the knobs and a live preview; a new title changes the preview, Save writes it; a version goes without", async ({ page }) => { await page.goto(urls.projectHref(PROJECT, { tab: "cut" })); const row = page.locator("[data-intro-row]"); await expect(row).toHaveAttribute("data-intro-row", "on"); await expect(row.locator("[data-intro-summary]")).toContainText("title-card", { timeout: 20_000 }); await row.locator("[data-intro-edit]").click(); const editor = page.locator("[data-intro-editor]"); await expect(editor).toBeVisible(); const preview = page.frameLocator('[data-testid="intro-editor-preview-iframe"]'); await expect(page.locator('[data-testid="intro-editor-preview"]')).toHaveAttribute("data-play-intro-ready", "1", { timeout: 30_000 }); await expect(preview.locator('[data-k="tt"]')).toHaveText("The Intro Play Fixture"); await expect(editor.locator('[data-intro-field="style"]')).toHaveValue("title-card"); // A new title, unsaved: the preview follows it; the manifest does not. await editor.locator('[data-intro-field="title"]').fill("A title of its own"); await expect(preview.locator('[data-k="tt"]')).toHaveText("A title of its own", { timeout: 20_000 }); expect((manifest().render.intro as { title?: string }).title).toBeUndefined(); // A length the build refuses is said, and Save waits. await editor.locator('[data-intro-field="seconds"]').fill("9"); await expect(editor.locator("[data-intro-problems]")).toContainText("render.intro.seconds must be a number from 3.5 to 8", { timeout: 20_000 }); await expect(editor.locator("[data-intro-save]")).toBeDisabled(); await editor.locator('[data-intro-field="seconds"]').fill("5"); await expect(editor.locator("[data-intro-problems]")).toHaveCount(0, { timeout: 20_000 }); await editor.locator("[data-intro-save]").click(); await expect(editor.locator('[data-intro-said="ok"]')).toBeVisible(); expect(manifest().render.intro).toEqual({ style: "title-card", sound: "intro.wav", title: "A title of its own", seconds: 5 }); await expect(row.locator("[data-intro-summary]")).toContainText("A title of its own"); await expect(page.locator('[data-testid="intro-editor-preview"]')).toHaveAttribute("data-play-intro-ready", "1", { timeout: 30_000 }); await row.evaluate((el) => el.scrollIntoView({ block: "start" })); await shot(page, "intro-editor.png"); // A version without the intro: its patch's render.intro is null; the project's manifest keeps it. const v1 = editor.locator('[data-intro-version="v1"]'); await expect(v1).toBeChecked(); await v1.uncheck(); await expect.poll(() => takeDoc("v1").patch?.render?.intro, { timeout: 10_000 }).toBeNull(); await expect(v1).not.toBeChecked(); expect((manifest().render.intro as { title?: string }).title).toBe("A title of its own"); await expect(row.locator("[data-intro-versions-off]")).toContainText("v1"); // Play on that version opens on c01: no intro. await page.goto(urls.playHref(PROJECT, { take: "v1" })); await expect(page.locator("[data-play-cut]")).toHaveAttribute("data-play-item", "c01", { timeout: 30_000 }); await expect(page.locator("[data-play-intro]")).toHaveCount(0); // Back on: the key comes OFF its patch (no stale copy of the cut's intro) -- it opens on the intro again. await page.goto(urls.projectHref(PROJECT, { tab: "cut" })); await page.locator("[data-intro-edit]").click(); await page.locator('[data-intro-version="v1"]').check(); await expect.poll(() => JSON.stringify(takeDoc("v1").patch?.render?.intro ?? "absent"), { timeout: 10_000 }).toBe(JSON.stringify("absent")); await expect(page.locator('[data-intro-version="v1"]')).toBeChecked(); await expect(page.locator("[data-intro-versions-off]")).toHaveCount(0); await page.goto(urls.playHref(PROJECT, { take: "v1" })); await expect(page.locator("[data-play-intro]")).toHaveCount(1, { timeout: 30_000 }); });