import { test, expect, type Page } from "@playwright/test"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // A TEXT CARD in Play the cut (lane leaflit-labels; operator, 6 Nov: "play the // cut needs to handle x posts"): a `teaser` entry -- an X post quoted on a card // -- plays as the build draws it, its own page (chrome-teaser.mjs, composed for // preview by POST /api/report/chrome/teasers) laid full frame and seeked on the // cut clock, not a placeholder. A card that carries a mark keeps the deck up // over it (deck.mjs teaserCounts) and the count steps at the mark. // // Fixture: e2e/fixtures/make-fixture.mjs, play-teaser-fixture -- the Play cut // with its card k01 replaced by t01 (4 s, three lines), marked CORROBORATED at // 1.0 s into the card; c02's mark (k1) lands before it, so the count is 1 on // the card's first second and 2 after its mark. // --------------------------------------------------------------------------- const PROJECT = "reports/play-teaser-fixture"; const root = (page: Page) => page.locator("[data-play-cut]"); const card = (page: Page) => page.locator('[data-play-teaser="t01"]'); const frame = (page: Page) => page.frameLocator('[data-testid="play-teaser-iframe"]'); /** A line's visibility inside the card's own page (the build's pixels, seeked by the parent). */ const lineOpacity = (page: Page, i: number) => frame(page).locator(`[data-k="l${i}.o"]`).evaluate((el) => Number(getComputedStyle(el).opacity)); const tally = (page: Page) => page.locator("[data-play-tally]"); test.beforeEach(() => { test.setTimeout(120_000); }); test("a teaser card that carries a mark plays as the build draws it: its lines, the deck over it, the count stepping at its mark", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); // Into the card, before its mark (1.0 s): seeked there from the URL. await page.goto(urls.playHref(PROJECT, { clip: "t01", at: 0.6 })); await expect(root(page)).toHaveAttribute("data-play-item", "t01", { timeout: 30_000 }); await expect(page.locator('[data-testid="play-deck"]')).toBeVisible({ timeout: 30_000 }); // The card's own page, not a placeholder. await expect(card(page)).toHaveAttribute("data-play-teaser-ready", "1", { timeout: 30_000 }); await expect(page.locator("[data-play-placeholder]")).toHaveCount(0); await expect(frame(page).locator('[data-k="l1.t"]')).toHaveText("“I want to understand your perspective"); await expect(frame(page).locator('[data-k="l2.t"]')).toHaveText("behind them as a moderate.”"); // Before the mark: c02's k1 has counted, the card's has not. await expect(tally(page)).toHaveAttribute("data-play-tally", "CORROBORATED:1"); await page.screenshot({ path: test.info().outputPath("play-teaser-before-mark.png") }); // Seek through the card past its mark (→ is 5 s on, past the card: back with ← lands before it, so step by the URL). await page.goto(urls.playHref(PROJECT, { clip: "t01", at: 2.6 })); await expect(root(page)).toHaveAttribute("data-play-item", "t01", { timeout: 30_000 }); await expect(card(page)).toHaveAttribute("data-play-teaser-ready", "1", { timeout: 30_000 }); await expect(page.locator('[data-testid="play-deck"]')).toHaveAttribute("data-deck-ready", "1", { timeout: 30_000 }); // Every line is in by now: the card's last line too. await expect.poll(() => lineOpacity(page, 2), { timeout: 10_000 }).toBeGreaterThan(0.9); await expect.poll(() => lineOpacity(page, 1), { timeout: 10_000 }).toBeGreaterThan(0.9); // After the mark: the count stepped on the card. await expect(tally(page)).toHaveAttribute("data-play-tally", "CORROBORATED:2"); await page.screenshot({ path: test.info().outputPath("play-teaser-after-mark.png") }); // Playing across the mark from the card's start: the count steps while the card is on screen. await page.goto(urls.playHref(PROJECT, { clip: "t01", at: 0.2 })); await expect(card(page)).toHaveAttribute("data-play-teaser-ready", "1", { timeout: 30_000 }); await expect(tally(page)).toHaveAttribute("data-play-tally", "CORROBORATED:1"); await page.locator("[data-play-toggle]").click(); await expect(tally(page)).toHaveAttribute("data-play-tally", "CORROBORATED:2", { timeout: 15_000 }); await page.keyboard.press("k"); await expect(root(page)).toHaveAttribute("data-play-state", "paused"); // Out of it (c01): no card on screen. await page.locator('[data-play-row="c01"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); await expect(card(page)).toHaveCount(0); }); // AN ANALYSIS ITEM (lane analysis-ending): its own page (chrome-analysis.mjs) composed for preview by the same route // and laid full frame, seeked on the cut clock -- the build's figures from the fixture's ledger, a bound said over/under. test("an analysis item plays as the build draws it: its page full frame, its pace rows computed from the ledger", async ({ page }) => { const P = "reports/play-analysis-fixture"; const item = page.locator('[data-play-teaser="a01"]'); const f = page.frameLocator('[data-testid="play-teaser-iframe"]'); await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P, { clip: "a01", at: 5.5 })); await expect(root(page)).toHaveAttribute("data-play-item", "a01", { timeout: 30_000 }); await expect(item).toHaveAttribute("data-play-teaser-ready", "1", { timeout: 30_000 }); await expect(page.locator("[data-play-placeholder]")).toHaveCount(0); await expect(f.locator(".ttl")).toHaveText("What his own numbers say"); // A bound in words, unsigned: ending on w5's "< 300" more than 10.5 lb lost, starting on it at most 8.5 lb lost. await expect(f.locator('[data-k="r0"] .v')).toHaveText("MORE THAN10.5 lblost"); await expect(f.locator('[data-k="r1"] .v')).toHaveText("AT MOST8.5 lblost"); await expect(f.locator('[data-k="r0"] .ls')).toHaveText("21 days · to < 300"); // Landed by now (the rows land after the line): seeked, not a still of its first frame. await expect.poll(() => f.locator('[data-k="rd"]').evaluate((el) => Number(getComputedStyle(el).opacity)), { timeout: 10_000 }).toBeGreaterThan(0.9); // Shown, not only loaded: the page's frame is visible on the stage. await expect(item).toHaveAttribute("data-play-teaser-ready", "1"); await expect(page.locator('[data-play-teaser="a01"] iframe')).toBeVisible(); await page.screenshot({ path: test.info().outputPath("play-analysis.png") }); // Out of it (c01): no page on screen. await page.locator('[data-play-row="c01"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); await expect(item).toHaveCount(0); });