import { test, expect, type Page } from "@playwright/test"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Play the cut draws the weight video's measure extras (umtool/docs/knobs.md, // Modules: Goal stack, Moving start, Promise clock, Diet badge): each module // reads the schedule's `measure` slice and declares `play`, so the full preview // returns it as a layer -- its own page, composed for preview, laid at its // region over the footage and seeked on the cut clock (`deck:seek`), posting // `:ready` once it can be. // // Fixture: e2e/fixtures/measure-extras-fixture.mjs as play-measure-fixture -- // the Play cut with a measure LEDGER pinned to its clips, so the estimate's // schedule (what Play draws) carries the measure slice; a clip's rows land at // its start (c01 0, c02 1.6, c03 4.3, c04 5.9 on the estimate's clock): // c01 keto, "lose 100" c02 ≈390, "lose 100" again, 365.7 // c03 carnivore, 291.5, the scale-video promise (23 Oct), a SYNTHETIC claim by madamsavvy (24 Oct) // c04 "lose 65" by Christmas, the check (3 Nov) // --------------------------------------------------------------------------- const PROJECT = "reports/play-measure-fixture"; // The fixture draws a measure, so the instruments are on (rev 9): the moving start is off beside the dial, and the // promise clock stands in the column's trail slot. const IDS = ["streak", "diet", "goals", "promise"] as const; const root = (page: Page) => page.locator("[data-play-cut]"); const layer = (page: Page, id: string) => page.locator(`[data-play-layer="${id}"]`); /** * What a module's page draws at the playhead: the words of the state blocks on * screen, or null while its panel is down -- read inside its own page, which is * what the render captures. */ const shown = (page: Page, id: string) => page .frameLocator(`[data-testid="play-layer-${id}-iframe"]`) .locator("#pn") .evaluate((pn) => { if (Number(getComputedStyle(pn).opacity) < 0.5 || getComputedStyle(pn).visibility === "hidden") return null; const on = [...pn.querySelectorAll(".st")].filter((e) => getComputedStyle(e).visibility !== "hidden" && Number(getComputedStyle(e).opacity) > 0.5); return on.map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim()).join(" | "); }); /** Every layer laid and its page ready (it posted `:ready`). */ async function ready(page: Page) { await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(page.locator('[data-testid="play-deck"]')).toBeVisible({ timeout: 30_000 }); for (const id of IDS) { await expect(layer(page, 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 }); } } test.beforeEach(() => { test.setTimeout(150_000); }); test("the measure extras play in Play the cut, each page seeked to the playhead's state", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); // A second into c04: every row before it has landed. await page.goto(urls.playHref(PROJECT, { clip: "c04", at: 1 })); await ready(page); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); // Laid in the build's z order: the streak (65), diet (66), goals (68), the promise clock (95, over the finale). const laid = await page.locator("[data-play-layer]").evaluateAll((els) => els.map((e) => e.getAttribute("data-play-layer"))); expect(laid.filter((id) => (IDS as readonly string[]).includes(id ?? ""))).toEqual([...IDS]); expect(laid).toContain("dial"); expect(laid).not.toContain("peak"); await expect.poll(() => shown(page, "goals"), { timeout: 10_000 }).toContain("LOSE 65"); const goals = await shown(page, "goals"); expect(goals).toContain("by Christmas · 50 days left"); expect(goals).toContain("needs 226.5"); expect(goals).toContain("×2"); expect(goals).toContain("3 goals set"); const promise = await shown(page, "promise"); expect(promise).toContain("scale video · offered 23 Oct"); expect(promise).toContain("11 days"); expect(promise).toContain("None posted"); // Her claim (SYNTHETIC in the fixture): the counterparty under the header. expect(promise).toContain("paid 24 Oct by @madamsavvy"); expect(promise).toContain("just pull up a video from three months ago"); const diet = await shown(page, "diet"); expect(diet).toContain("Carnivore"); expect(diet).toContain("Diet #2"); const streak = await shown(page, "streak"); expect(streak).toContain("Carnivore"); expect(streak).toContain("Day 63"); await page.screenshot({ path: test.info().outputPath("play-measure-c04.png") }); // Back five seconds, in the page (0.3 s into c02): the pages are seeked back. await expect(root(page)).toHaveAttribute("data-play-state", "paused"); await page.getByRole("button", { name: "−5" }).click(); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await expect.poll(() => shown(page, "goals"), { timeout: 10_000 }).toContain("2 goals set"); expect(await shown(page, "goals")).toContain("×2"); expect(await shown(page, "goals")).not.toContain("LOSE 65"); expect(await shown(page, "diet")).toContain("Keto"); expect(await shown(page, "diet")).toContain("Diet #1"); expect(await shown(page, "streak")).toContain("Keto"); expect(await shown(page, "promise")).toBeNull(); await page.screenshot({ path: test.info().outputPath("play-measure-c02.png") }); }); test("on the shelf: the footage at the frame's top, the diet's dated tags and the streak in the strip under it, seeked as before", async ({ page, request }) => { await page.setViewportSize({ width: 1366, height: 1000 }); const enc = encodeURIComponent; const read = async () => (await (await request.get(`/api/report/chrome?project=${enc(PROJECT)}`)).json()) as { chrome: Record; token: string }; const put = async (chrome: unknown) => { const { token } = await read(); const r = await request.put("/api/report/chrome", { data: { project: PROJECT, chrome, token } }); expect(r.ok(), await r.text()).toBeTruthy(); }; const before = (await read()).chrome; const deck = before.deck ?? {}; try { await put({ ...before, deck: { ...deck, shelf: { items: ["diet", "streak"] }, diet: { ...(deck.diet ?? {}), position: "shelf" }, streak: { ...(deck.streak ?? {}), position: "shelf" } }, }); await page.goto(urls.playHref(PROJECT, { clip: "c04", at: 1 })); await ready(page); // Where Play laid them, in % of the frame: the footage from 24 px down, the shelf's slots at y 750 of 1080. const top = (sel: string) => page.locator(sel).first().evaluate((el) => parseFloat((el as HTMLElement).style.top)); expect(await top("[data-play-footage]")).toBeCloseTo((24 / 1080) * 100, 1); for (const id of ["diet", "streak"]) expect(await top(`[data-testid="play-layer-${id}"]`)).toBeCloseTo((750 / 1080) * 100, 1); // The tags: the newest (carnivore, c03) and keto (c01) under it, each with the day he named it. const tags = () => page.frameLocator('[data-testid="play-layer-diet-iframe"]').locator("#pn").evaluate((pn) => [...pn.querySelectorAll(".tg")] .filter((e) => getComputedStyle(e).visibility !== "hidden" && Number(getComputedStyle(e).opacity) > 0.5) // Left to right, as they stand on the shelf (the page holds them in the order they came in). .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left) .map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim())); await expect.poll(tags, { timeout: 10_000 }).toHaveLength(2); const [newest, older] = await tags(); expect(newest).toContain("Carnivore"); expect(older).toContain("Keto"); for (const t of [newest, older]) expect(t).toMatch(/[A-Z][a-z]{2} \d{1,2}, \d{4}/); expect(await shown(page, "streak")).toContain("Carnivore"); await page.screenshot({ path: test.info().outputPath("play-measure-shelf.png") }); // Back into c02: one tag, keto. await expect(root(page)).toHaveAttribute("data-play-state", "paused"); await page.getByRole("button", { name: "−5" }).click(); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await expect.poll(tags, { timeout: 10_000 }).toHaveLength(1); expect((await tags())[0]).toContain("Keto"); } finally { await put(before); } }); test("the fan: the diet's tags overlapped with the day count on the front one, the goals' fan beside them on the shelf", async ({ page, request }) => { await page.setViewportSize({ width: 1366, height: 1000 }); const enc = encodeURIComponent; const read = async () => (await (await request.get(`/api/report/chrome?project=${enc(PROJECT)}`)).json()) as { chrome: Record; token: string }; const put = async (chrome: unknown) => { const { token } = await read(); const r = await request.put("/api/report/chrome", { data: { project: PROJECT, chrome, token } }); expect(r.ok(), await r.text()).toBeTruthy(); }; const before = (await read()).chrome; const deck = before.deck ?? {}; try { await put({ ...before, deck: { ...deck, shelf: { items: ["diet", "goals"] }, streak: false, diet: { ...(deck.diet ?? {}), position: "shelf", overlap: 0.6, days: true }, goals: { ...(deck.goals ?? {}), position: "shelf" }, }, }); await page.goto(urls.playHref(PROJECT, { clip: "c04", at: 1 })); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); for (const id of ["diet", "goals"]) { await expect(page.getByTestId(`play-layer-${id}`)).toHaveAttribute("data-feed-ready", "1", { timeout: 30_000 }); expect(await page.getByTestId(`play-layer-${id}`).evaluate((el) => parseFloat((el as HTMLElement).style.top))).toBeCloseTo((750 / 1080) * 100, 1); } await expect(page.locator('[data-play-layer="streak"]')).toHaveCount(0); const diet = page.frameLocator('[data-testid="play-layer-diet-iframe"]').locator("#pn"); // The front tag (carnivore, c03) with its running day count; keto behind it, still carnivore-free of a dim. await expect.poll(() => diet.evaluate((pn) => { const on = [...pn.querySelectorAll(".tg")].filter((e) => getComputedStyle(e).visibility !== "hidden" && Number(getComputedStyle(e).opacity) > 0.5) .sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left); return on.map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 9)); }), { timeout: 10_000 }).toEqual([expect.stringContaining("Carnivore"), expect.stringContaining("Keto")]); const days = await diet.evaluate((pn) => [...pn.querySelectorAll(".dy")].filter((e) => getComputedStyle(e).visibility !== "hidden").map((e) => (e.textContent ?? "").trim())); expect(days).toHaveLength(1); expect(days[0]).toMatch(/^\d+days?$/); const goals = page.frameLocator('[data-testid="play-layer-goals-iframe"]').locator("#pn"); await expect.poll(() => goals.evaluate((pn) => { const st = [...pn.querySelectorAll(".st")].find((e) => getComputedStyle(e).visibility !== "hidden"); return st ? (st.querySelector(".gc")?.textContent ?? "").replace(/\s+/g, " ").trim() : null; }), { timeout: 10_000 }).toBe("3goals set"); await page.screenshot({ path: test.info().outputPath("play-measure-fan.png") }); } finally { await put(before); } });