import { test, expect, type Page } from "@playwright/test"; import { execFileSync } from "node:child_process"; import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE COMBO COUNTER (report-to-video/post-combo.mjs; knobs.md, "The combo // counter"): one reaction GIF answering three people. Fixture: // e2e/fixtures/post-combo-fixture.mjs -- p-c1 (its first use), p-txt (words), // p-c2 (the same bytes re-uploaded: ×2), p-c3 (again, its capture in the // corpus only: ×3), p-oth (another GIF). Each item is its 3 s read, its GIF // beside the card from the first frame: the badge pops at the item's 0 s. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const DIR = path.join(FIXTURE, "reports", "post-combo-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const PROJECT = "reports/post-combo-fixture"; const SHOTS = process.env.POST_COMBO_SHOTS ?? null; type Entry = { id: string; type: string; combo?: unknown }; const timeline = () => (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Entry[] }).timeline; const umtool = (args: string[]) => execFileSync("node", ["bin/umtool.mjs", ...args], { cwd: path.join(HERE, ".."), encoding: "utf8", env: { ...process.env, REPORTS_DIR: FIXTURE, CHANNELS_DIR: path.join(FIXTURE, "channels"), UMTOOL_CACHE_DIR: path.join(FIXTURE, "cache"), UMTOOL_PRINTS_CACHE: path.join(FIXTURE, "cache", "media-prints"), UMTOOL_MEDIA_DIR: "" }, }); test.beforeAll(() => { if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`); }); test.beforeEach(() => { test.setTimeout(120_000); copyFileSync(`${MANIFEST}.pristine`, MANIFEST); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); }); const root = (page: Page) => page.locator("[data-play-cut]"); test("Play shows the combo: none on the first use, ×2 then ×3 as the repeated GIF starts", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-c1" })); await expect(root(page)).toHaveAttribute("data-play-item", "p-c1"); await expect(page.locator('[data-post-play="p-c1"]')).toBeVisible(); // The first use counts, and draws nothing. await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo", "1"); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-show", "0"); await expect(page.locator("[data-combo-badge]")).toHaveCount(0); // The second use: the badge is up from the attachment's start (the item's 0 s: beside the card, the GIF plays from the first frame). await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-c2" })); await expect(root(page)).toHaveAttribute("data-play-item", "p-c2"); const badge = page.locator("[data-post-combo]"); await expect(badge).toHaveAttribute("data-post-combo", "2"); await expect(badge).toHaveAttribute("data-post-combo-show", "1"); await expect(badge).toHaveAttribute("data-post-combo-at", "0"); await expect(badge).toHaveAttribute("data-post-combo-up", "1"); await page.locator("[data-play-toggle]").click(); // Popped: scaled up and opaque. await expect.poll(async () => Number(await page.locator('[data-combo-badge="2"]').evaluate((el) => getComputedStyle(el.parentElement as HTMLElement).opacity)), { timeout: 10_000 }).toBeGreaterThan(0.9); await expect(page.locator('[data-combo-badge="2"]')).toContainText("COMBO"); await expect(page.locator('[data-combo-badge="2"]')).toContainText("×2"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-combo-play-x2.png") }); // Played on into the third use: ×3, from its start. await expect(root(page)).toHaveAttribute("data-play-item", "p-c3", { timeout: 15_000 }); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo", "3"); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-up", "1"); await expect(page.locator('[data-combo-badge="3"]')).toContainText("×3"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-combo-play-x3.png") }); // p-oth repeats nothing. await expect(root(page)).toHaveAttribute("data-play-item", "p-oth", { timeout: 15_000 }); await expect(page.locator("[data-post-combo]")).toHaveCount(0); await page.locator("[data-play-toggle]").click(); }); test("the post bench lists the repeat group and turns the badge off for one item (it still counts); posts repeats agrees", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.postBenchHref(PROJECT, "p-c3")); const panel = page.locator('[data-post-bench-combo="3"]'); await expect(panel).toBeVisible(); expect(await panel.locator("[data-post-bench-combo-member]").evaluateAll((els) => els.map((e) => e.getAttribute("data-post-bench-combo-member")))).toEqual(["p-c1", "p-c2", "p-c3"]); await expect(panel.locator('[data-post-bench-combo-member="p-c2"]')).toContainText("the same file"); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-show", "1"); // On the item's clock: up from the GIF's start for its 2.6 s, gone before the item's 3 s end. const scrub = page.locator("[data-post-bench-scrub]"); await scrub.fill("1"); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-up", "1"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-combo-bench.png") }); await scrub.fill("2.8"); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-up", "0"); await expect(page.locator("[data-combo-badge]")).toHaveCount(0); await panel.locator("[data-post-bench-combo-toggle]").uncheck(); await expect(panel.locator("[data-post-bench-combo-note]")).toContainText("still counts"); await expect.poll(() => timeline().find((e) => e.id === "p-c3")?.combo).toBe(false); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-show", "0"); await expect(page.locator("[data-combo-badge]")).toHaveCount(0); const rep = JSON.parse(umtool(["posts", "repeats", PROJECT, "--json"])) as { groups: { members: { id: string; badge: number | null; show: boolean; tier: string | null }[] }[] }; expect(rep.groups).toHaveLength(1); expect(rep.groups[0].members.map((m) => `${m.id}:${m.badge}:${m.show ? "shown" : "-"}:${m.tier ?? "first"}`)).toEqual(["p-c1:1:-:first", "p-c2:2:shown:sha256", "p-c3:3:-:sha256"]); // On again: the item takes the cut's badge. await panel.locator("[data-post-bench-combo-toggle]").check(); await expect.poll(() => "combo" in (timeline().find((e) => e.id === "p-c3") ?? {})).toBe(false); await expect(page.locator("[data-post-combo]")).toHaveAttribute("data-post-combo-show", "1"); });