import { test, expect, type Page } from "@playwright/test"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE STACKED VERTICAL DECK (umtool/docs/knobs.md, "The vertical deck"; lane // L10): a 9:16 cut that has a deck keeps it -- the landscape cut's schedule and // pages laid in another geometry (report-to-video/vertical-deck.mjs). Play the // cut plays it: the deck's own page over the whole 1080x1920 frame (the rail // with its section and progress, each clip's source block and its QR), the // footage at the frame's full width, the instruments' pages in their panel. // // Fixture: e2e/fixtures/measure-extras-fixture.mjs as vertical-deck-fixture -- // play-measure-fixture's cut with the dial, the odometer and the trail on (the // extras off), a marker after c02 ("Carnivore"; "Keto" before it) and // render.format "vertical" (render.vertical.deck absent: stacked). READ-ONLY. // --------------------------------------------------------------------------- const PROJECT = "reports/vertical-deck-fixture"; const INSTRUMENTS = ["dial", "odometer", "trail"] as const; type Rect = { x: number; y: number; width: number; height: number }; type Layer = { id: string; region?: string; geometry?: Rect | null; src?: string; error?: string }; const root = (page: Page) => page.locator("[data-play-cut]"); const deck = (page: Page) => page.frameLocator('[data-testid="play-deck-iframe"]'); /** The words of the deck page's blocks that are on screen under `sel` (visible, opacity over a half). */ const shown = (page: Page, sel: string) => deck(page) .locator(sel) .evaluateAll((els) => els .filter((e) => { let n: Element | null = e; while (n && n instanceof HTMLElement) { const cs = getComputedStyle(n); if (cs.visibility === "hidden" || Number(cs.opacity) < 0.5 || cs.display === "none") return false; n = n.parentElement; } return true; }) .map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim()), ); test.beforeEach(() => { test.setTimeout(150_000); }); test("the chrome preview of a vertical cut is the stacked deck: 9:16, the picture at full width, the instruments in the panel", async ({ request }) => { const res = await request.post("/api/report/chrome/preview", { data: { project: PROJECT, estimate: true } }); expect(res.ok(), await res.text()).toBeTruthy(); const doc = (await res.json()) as { geometry: { W: number; H: number; footage: Rect; deck: Rect }; layers: Layer[]; posts: { windows: unknown[] } }; expect(doc.geometry.W).toBe(1080); expect(doc.geometry.H).toBe(1920); expect(doc.geometry.footage.width).toBe(1080); expect(doc.geometry.deck).toEqual({ x: 0, y: 0, width: 1080, height: 1920 }); expect(doc.posts.windows).toEqual([]); const by = Object.fromEntries(doc.layers.map((l) => [l.id, l])); // The safe area: the top 8 %, the bottom 20 %, the right 12 % kept clear. for (const id of INSTRUMENTS) { const g = by[id]?.geometry; expect(g, `${id} is a play layer`).toBeTruthy(); expect(by[id].src, by[id].error).toBeTruthy(); expect(g!.y).toBeGreaterThanOrEqual(1920 * 0.08); expect(g!.y + g!.height).toBeLessThanOrEqual(1920 * 0.8); expect(g!.x + g!.width).toBeLessThanOrEqual(1080 * 0.88 + 1); // Under the picture. expect(g!.y).toBeGreaterThanOrEqual(doc.geometry.footage.y + doc.geometry.footage.height); } // The dial the left column's height, the odometer and the trail down the right. expect(by.dial.geometry!.x).toBeLessThan(by.odometer.geometry!.x); expect(by.trail.geometry!.y).toBeGreaterThan(by.odometer.geometry!.y); }); test("Play the cut plays the stacked deck: the rail's section and progress, the source line and its QR, the instruments", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); await page.goto(urls.playHref(PROJECT, { clip: "c04", at: 1 })); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(page.getByTestId("play-deck")).toBeVisible({ timeout: 30_000 }); await expect(page.getByTestId("play-deck")).toHaveAttribute("data-deck-ready", "1", { timeout: 30_000 }); await expect(page.locator("[data-play-tall]")).toHaveCount(1); // The frame is tall: 9:16. const box = await page.getByTestId("play-deck").boundingBox(); expect(box).toBeTruthy(); expect(Math.abs(box!.height / box!.width - 1920 / 1080)).toBeLessThan(0.02); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); // The rail: c04 is in the second section, its name up and "2 / 2" beside it. await expect.poll(() => shown(page, ".rail .rlab"), { timeout: 10_000 }).toEqual(["Carnivore"]); expect(await shown(page, ".rail .rcount")).toEqual(["2 / 2"]); // The source block: the clip's QR beside its channel, title, date and time. const src = deck(page).locator(".src").filter({ has: deck(page).locator("img.qr") }); expect(await src.count()).toBeGreaterThan(0); const blocks = await shown(page, ".src"); expect(blocks.length).toBe(1); expect(blocks[0]).toMatch(/\d+:\d{2}/); // The tally's row (the cut counts its claims). expect((await shown(page, ".tally")).length).toBe(1); // The instruments, each its page in the panel, up and ready. for (const id of INSTRUMENTS) { await expect(page.locator(`[data-play-layer="${id}"]`)).toHaveAttribute("data-play-layer-up", "1", { timeout: 30_000 }); await expect(page.getByTestId(`play-layer-${id}`)).toHaveAttribute("data-feed-ready", "1", { timeout: 30_000 }); } await page.screenshot({ path: test.info().outputPath("vertical-deck-c04.png") }); // Back into the first section: its name on the rail. await page.goto(urls.playHref(PROJECT, { clip: "c01", at: 0.5 })); await expect(page.getByTestId("play-deck")).toHaveAttribute("data-deck-ready", "1", { timeout: 30_000 }); await expect.poll(() => shown(page, ".rail .rlab"), { timeout: 10_000 }).toEqual(["Keto"]); expect(await shown(page, ".rail .rcount")).toEqual(["1 / 2"]); await page.screenshot({ path: test.info().outputPath("vertical-deck-c01.png") }); });