import { test, expect, type Page } from "@playwright/test"; import * as urls from "./urls"; import { SONG_SECTION_TAB } from "../lib/pieces/song-tabs.mjs"; // --------------------------------------------------------------------------- // The song piece (plans/umtool-redesign.md, P4a-3): a song's page is the P4a // frame -- the head, the Spec → Cuts → Done stepper, the lifecycle chip, the // Next card -- around ONE of five tabs, Overview · Cuts · Spec · Cover · Notes, // and a cut's page is a view of the Cuts tab. Against make-fixture.mjs's songs: // // alpha all four cuts (the derived `shipped`: Done, and it looks done) // beta wide and wide-short only (at Cuts) // // browse.spec runs first and promotes, notes and re-specs alpha; nothing here // depends on which file ships, only on the set being whole. // --------------------------------------------------------------------------- const ALPHA = "reports/videos/alpha"; const BETA = "reports/videos/beta"; const PIECE = `p:${ALPHA}`; const tab = (page: Page, id: string) => page.getByTestId(`piece-tab-${id}`); const keysReady = (page: Page) => expect(page.locator("[data-piece-keys=ready]")).toBeAttached(); const steps = (page: Page) => page.getByRole("list", { name: "Stage" }).locator("li"); test("the frame: title, trail, the Spec → Cuts → Done stepper, five tabs, the Overview alone", async ({ page }) => { const res = await page.goto(urls.projectHref("alpha")); expect(res?.status()).toBe(200); const crumbs = page.getByRole("navigation", { name: "Breadcrumb" }); await expect(crumbs.locator("h1")).toHaveText(/Alpha/); await expect(crumbs).toContainText(ALPHA); await expect(page.locator("header .micro").last()).toHaveText(/4\/4 cuts · \d+ variants/i); // Every cut built: at Done (a suggestion -- the lifecycle is still Active). const frame = page.locator(`[data-piece-frame="${PIECE}"]`); await expect(frame).toHaveAttribute("data-piece-stage", "done"); await expect(frame).toHaveAttribute("data-piece-lifecycle", "active"); await expect(steps(page)).toHaveText([/^Spec/, /^Cuts/, /^Done/]); await expect(steps(page).nth(2)).toHaveAttribute("aria-current", "step"); await expect(steps(page).nth(1)).toHaveAttribute("data-step", "done"); const tabs = page.getByRole("navigation", { name: "Piece" }).getByRole("link"); await expect(tabs).toHaveText([/^Overview/, /^Cuts/, /^Spec/, /^Cover/, /^Notes/]); await expect(tab(page, "overview")).toHaveAttribute("aria-current", "page"); await expect(tab(page, "cuts")).toHaveText("Cuts4"); await expect(tab(page, "cuts")).toHaveAttribute("href", urls.projectHref(ALPHA, { tab: "cuts" })); // The Overview: the Next card, the decisions, the cut set at a glance, the // looks-done suggestion, the song tools -- and none of the other tabs' sections. await expect(page.locator("[data-next]:visible")).toBeVisible(); await expect(page.locator("[data-song-slot]")).toHaveCount(4); await expect(page.locator("[data-song-slot][data-present='0']")).toHaveCount(0); await expect(page.locator("[data-song-looks-done]")).toContainText("every cut shipped"); await expect(page.locator("[data-song-pile=sort]")).toHaveAttribute("href", urls.pileHref("sort")); await expect(page.locator("[data-song-copy]")).toBeVisible(); await expect(page.locator("[data-cut]")).toHaveCount(0); await expect(page.locator("[data-op]")).toHaveCount(0); await expect(page.locator("[data-note-for=song]")).toHaveCount(0); // An open decision is a state: its chip is the neutral state tag, never the doubt colour (P6). const openChip = page.locator("[data-decision][data-severity=open]").first().locator("span").first(); await expect(openChip).toHaveText(/open/i); await expect(openChip).toHaveClass(/border-dashed/); await expect(openChip).not.toHaveClass(/doubt/); }); test("a song with a hole is at Cuts, and Work files it where its stepper says", async ({ page }) => { await page.goto(urls.projectHref(BETA)); await expect(page.locator(`[data-piece-frame="p:${BETA}"]`)).toHaveAttribute("data-piece-stage", "cuts"); await expect(steps(page).nth(1)).toHaveAttribute("aria-current", "step"); await expect(steps(page).nth(2)).toHaveAttribute("data-step", "todo"); await expect(page.locator("[data-song-slot=vertical]")).toHaveAttribute("data-present", "0"); await expect(page.locator("[data-song-looks-done]")).toHaveCount(0); // Work: the song's own three steps on its bar; its bucket is the one the step stands in for. await page.goto(urls.workHref({ life: "all" })); const beta = page.locator(`[data-lit-line][data-piece='p:${BETA}']`); await expect(beta).toHaveAttribute("data-stage", "video"); await expect(beta).toContainText("cuts"); const alpha = page.locator(`[data-lit-line][data-piece='${PIECE}']`); await expect(alpha).toHaveAttribute("data-stage", "deliver"); await expect(alpha).toContainText("done"); await expect(alpha).toContainText("looks done"); }); test("the Next card is the song's top Inbox call, and its one action goes where the Inbox's does", async ({ page, request }) => { const inbox = (await (await request.get("/api/browse/decisions")).json()) as { groups: { id: string; cards: { piece: string | null; kind: string; action: { label: string; href: string } }[] }[]; }; const top = inbox.groups.filter((g) => g.id !== "quiet").flatMap((g) => g.cards).find((c) => c.piece === PIECE); expect(top, "the fixture's alpha has a call waiting").toBeTruthy(); await page.goto(urls.projectHref(ALPHA)); const next = page.locator("[data-next]:visible"); await expect(next.locator("[data-next-kind]")).toHaveAttribute("data-next-kind", top!.kind); const action = next.locator("[data-next-action] > :is(a, button):visible"); await expect(action).toHaveText(top!.action.label); }); test("a song's calls land on their tab: the spec's on Spec, a cover's on Cover, a cut's on its page -- at the full path", async ({ request }) => { const items = ((await (await request.get("/api/browse/decisions?project=alpha")).json()) as { items: { kind: string; href: string }[] }).items; const WHERE: Record = { "spec-problem": "spec", "no-plan": "spec", unattributed: "cuts", "thumb-unaccepted": "cover" }; const songWide = items.filter((d) => WHERE[d.kind]); expect(songWide.length, "alpha names no plan, so at least that call").toBeGreaterThan(0); // The song's canonical address is its full path (P6); the basename stays the // decision's project, the notes' target. for (const d of songWide) expect(d.href, d.kind).toBe(urls.projectHref(ALPHA, { tab: WHERE[d.kind] })); const cutCalls = items.filter((x) => x.kind === "unjudged-variant" || x.kind === "stale-recipe"); expect(cutCalls.length).toBeGreaterThan(0); for (const d of cutCalls) { expect(d.href, d.kind).toMatch(new RegExp(`^/projects/${ALPHA}/(wide|wide-short|vertical|vertical-short)(\\?|$)`)); } }); test("the tab is the URL: ?tab=, a note's target, a bad tab the Overview, and the old addresses land", async ({ page }) => { // Every section a spec names is on the tab the table says. expect(SONG_SECTION_TAB.cuts).toBe("cuts"); await page.goto(urls.songSection("alpha", "cuts")); await expect(tab(page, "cuts")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-cut]")).toHaveCount(4); await expect(page.locator("[data-song-slot]")).toHaveCount(0); // A cut card links the cut at the song's full path (P6), as the Overview's // slots and the picker do; the basename still resolves (below, and the 1366 test). await expect(page.locator("[data-cut=wide]").getByRole("link", { name: "wide", exact: true })).toHaveAttribute("href", urls.cutHref(ALPHA, "wide")); await page.goto(urls.songSection("alpha", "spec")); await expect(page.locator("[data-op=trim-hooks]")).toBeVisible(); await expect(page.locator("[data-song-plans]")).toBeVisible(); await page.goto(urls.songSection("alpha", "cover")); await expect(page.locator("[data-judge-faces]").first()).toBeVisible(); await page.goto(urls.songSection("alpha", "notes")); await expect(page.locator("[data-note-for=song]").first()).toBeVisible(); await expect(page.locator("[data-song-notes]")).toBeVisible(); await page.goto(urls.projectHref(ALPHA, { tab: "nonsense" })); await expect(tab(page, "overview")).toHaveAttribute("aria-current", "page"); // A song's notes are keyed by target: `?note=` opens the tab it is written on. await page.goto(urls.projectHref("alpha", { note: "song" })); await expect(tab(page, "notes")).toHaveAttribute("aria-current", "page"); await page.goto(urls.projectHref("alpha", { note: "plan:alpha.plan.json" })); await expect(tab(page, "spec")).toHaveAttribute("aria-current", "page"); await page.goto(urls.projectHref("alpha", { note: "cut:vertical" })); await expect(tab(page, "cuts")).toHaveAttribute("aria-current", "page"); // The old address rides P3's redirect to the Overview. await page.goto("/browse/alpha"); await expect(page).toHaveURL(/\/projects\/alpha$/); await expect(tab(page, "overview")).toHaveAttribute("aria-current", "page"); }); test("a cut's page is a view of the Cuts tab: the frame, the four cuts beside the title, the bench under it", async ({ page }) => { const res = await page.goto("/browse/alpha/wide"); expect(res?.status()).toBe(200); await expect(page).toHaveURL(/\/projects\/alpha\/wide$/); await expect(tab(page, "cuts")).toHaveAttribute("aria-current", "page"); await expect(page.locator(`[data-piece-frame="${PIECE}"]`)).toBeVisible(); const picker = page.locator("[data-song-cut-picker=wide]"); await expect(picker.locator("[aria-current=page]")).toHaveText("wide"); await expect(page.locator("[data-loudness='wide.mp4']")).toBeVisible(); // The bench's controls are outlines; Signal is only focus and the lit line (P6). await expect(page.locator("main button[class*='color-sel'], main a[class*='border-[var(--color-sel)]']")).toHaveCount(0); // The trail's project id is the way back to the song. await expect(page.getByRole("navigation", { name: "Breadcrumb" }).getByRole("link", { name: ALPHA })).toHaveAttribute( "href", urls.projectHref(ALPHA), ); await picker.getByRole("link", { name: "wide-short" }).click(); await expect(page).toHaveURL(new RegExp(`/projects/${ALPHA}/wide-short$`)); await expect(page.locator("[data-song-cut-picker=wide-short]")).toBeVisible(); }); test("keys: 1–5 open the tabs, n runs the Next card's action", async ({ page }) => { await page.goto(urls.projectHref(ALPHA)); await keysReady(page); await page.keyboard.press("2"); await expect(page).toHaveURL(/\?tab=cuts$/); await keysReady(page); await page.keyboard.press("5"); await expect(page).toHaveURL(/\?tab=notes$/); await expect(tab(page, "notes")).toHaveAttribute("aria-current", "page"); await keysReady(page); await page.keyboard.press("1"); await expect(tab(page, "overview")).toHaveAttribute("aria-current", "page"); await keysReady(page); const action = page.locator("[data-next-action] > a:visible"); if ((await action.count()) > 0) { const href = await action.getAttribute("href"); await page.keyboard.press("n"); await expect(page).toHaveURL(new RegExp(`${href!.replace(/[?]/g, "\\?")}$`)); } }); test("marked done, every stage is done; the lifecycle chip says so", async ({ page, request }) => { try { expect((await request.post("/api/pieces/lifecycle", { data: { piece: PIECE, state: "done" } })).ok()).toBe(true); await page.goto(urls.projectHref(ALPHA)); await expect(page.locator("[data-lifecycle-chip]")).toHaveAttribute("data-lifecycle-chip", "done"); for (let i = 0; i < 3; i += 1) await expect(steps(page).nth(i)).toHaveAttribute("data-step", "done"); // The suggestion is spent once the piece is marked done. await expect(page.locator("[data-song-looks-done]")).toHaveCount(0); await expect(page.locator("[data-next-kind=lifecycle]")).toContainText("Marked done"); } finally { await request.post("/api/pieces/lifecycle", { data: { piece: PIECE, state: "active" } }); } }); test("fits 1366×768: the head, the five tabs and the Next card's action without a horizontal scroll", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); for (const href of [urls.projectHref(ALPHA), urls.projectHref(ALPHA, { tab: "cuts" }), urls.projectHref(ALPHA, { tab: "spec" }), "/projects/alpha/wide"]) { await page.goto(href); await expect(tab(page, "notes")).toBeInViewport(); const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); expect(overflow, href).toBeLessThanOrEqual(0); } await page.goto(urls.projectHref(ALPHA)); await expect(page.locator("[data-next-action] > :is(a, button):visible")).toBeInViewport(); });