import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // A clip's picture blurred (report-to-video clip-blur.mjs) and new clips from a // span of a recording: // - the clip editor's Blur box: Blur picture, the caption (prefilled with the // default), the strength, From playhead, Whole clip, off again // - New clip (from the span after the clip, its edges typed): inserted after // the clip through the timeline route, its quote read from the words, Blur // picture on it; the editor opens the new clip // - the project page's timeline: Add clip, its quote from the recording's // cues, after a chosen entry, Blur picture // Fixture: e2e/fixtures/clip-editor-fixture.mjs, as clip-blur-fixture // (r001 1.0-3.0, r002 4.0-6.0, r003 6.5-8.5 on vid1; vid1's cues 0-21 s). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const PROJECT = "reports/clip-blur-fixture"; const DIR = path.join(HERE, "..", ".e2e-song", "reports", "clip-blur-fixture"); type Entry = Record & { id: string; type: string }; const timeline = (): Entry[] => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).timeline; const entry = (id: string) => timeline().find((e) => e.id === id) ?? null; const DEFAULT_CAPTION = "Original footage uncensored, blurred here for TOS"; test("the Blur box: on, a caption, a strength, from the playhead, the whole clip, off", async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: "r003", mode: "edit" })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r003"); await expect(page.locator("[data-editor-player]")).not.toHaveAttribute("data-editor-player", "looking", { timeout: 15_000 }); const box = page.locator('[data-blur-box="r003"]'); await box.locator("[data-blur-on]").check(); // The box shows the click at once, and the write lands: the saved key, and the view's box after it. await expect.poll(() => entry("r003")?.blur).toEqual({ on: true }); await expect(box).toHaveAttribute("data-blur", JSON.stringify({ on: true })); await expect(box.locator("[data-blur-on]")).toBeChecked(); await expect(page.locator("[data-editor-blurred]")).toHaveAttribute("data-editor-blurred", "on"); await expect(box.locator("[data-blur-caption]")).toHaveValue(DEFAULT_CAPTION); await box.locator("[data-blur-caption]").fill("Blurred here for TOS"); await box.locator("[data-blur-caption]").press("Enter"); await expect.poll(() => entry("r003")?.blur).toEqual({ on: true, caption: "Blurred here for TOS" }); await box.locator('[data-knob="blur-strength"]').fill("8"); await box.locator('[data-knob="blur-strength"]').press("Enter"); await expect.poll(() => (entry("r003")?.blur as { strength?: number } | undefined)?.strength).toBe(8); // A word puts the playhead there; From playhead blurs from that second on. await page.locator('[data-word-t="7.2"]').click(); await box.locator("[data-blur-from-playhead]").click(); await expect.poll(() => (entry("r003")?.blur as { from?: number } | undefined)?.from).toBe(7.2); await expect(box.locator("[data-blur-span]")).toHaveAttribute("data-blur-span", "7.2-"); await box.locator("[data-blur-whole]").click(); await expect.poll(() => entry("r003")?.blur).toEqual({ on: true, caption: "Blurred here for TOS", strength: 8 }); // The default caption again is no caption key. await box.locator("[data-blur-caption-default]").click(); await expect.poll(() => entry("r003")?.blur).toEqual({ on: true, strength: 8 }); await box.locator("[data-blur-on]").uncheck(); await expect.poll(() => entry("r003") && "blur" in entry("r003")!).toBe(false); await expect(box).toHaveAttribute("data-blur", "null"); await expect(box.locator("[data-blur-on]")).not.toBeChecked(); await expect(page.locator("[data-editor-blurred]")).toHaveCount(0); }); test("New clip: the span after the clip, its quote from the words, Blur picture, inserted after it", async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: "r003", mode: "edit" })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r003"); await expect(page.locator("[data-editor-words]")).toBeVisible(); await page.locator('[data-action="new-clip"]').click(); const form = page.locator('[data-new-clip="r003"]'); // With no selection: the span just after the clip, as long as it (at least 5 s). await expect(form.locator("[data-new-clip-from]")).toHaveValue("8.5"); await expect(form.locator("[data-new-clip-to]")).toHaveValue("13.5"); await expect(form.locator("[data-new-clip-id]")).toHaveValue("r003-2"); await form.locator("[data-new-clip-from]").fill("9.2"); await form.locator("[data-new-clip-to]").fill("11.8"); await expect(form.locator("[data-new-clip-quote]")).toHaveValue("Another whole sentence entirely."); await form.locator("[data-new-clip-blur]").check(); await form.locator("[data-new-clip-insert]").click(); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r003-2"); const ids = timeline().map((e) => e.id); expect(ids.indexOf("r003-2")).toBe(ids.indexOf("r003") + 1); expect(entry("r003-2")).toMatchObject({ type: "clip", video: "vid1", start: 9.2, end: 11.8, cite: 9, quote: "Another whole sentence entirely.", blur: { on: true } }); await expect(page.locator('[data-blur-box="r003-2"] [data-blur-on]')).toBeChecked(); }); test("the timeline's Add clip: a spec, its quote from the cues, after a chosen entry, Blur picture", async ({ page }) => { test.setTimeout(90_000); await page.goto(urls.section(PROJECT, "timeline")); await expect(page.getByTestId("timeline-undo")).toBeEnabled(); await page.getByTestId("timeline-add-clip").click(); await page.getByTestId("timeline-add-spec").fill("testchan/vid1@12-15"); await expect(page.getByTestId("timeline-add-quote")).toHaveValue("A fourth one, done."); await page.getByTestId("timeline-add-after").selectOption("r001"); await page.getByTestId("timeline-add-blur").check(); await page.getByTestId("timeline-add-submit").click(); await expect.poll(() => timeline().map((e) => e.id).indexOf("vid1-12")).toBe(timeline().map((e) => e.id).indexOf("r001") + 1); expect(entry("vid1-12")).toEqual({ type: "clip", id: "vid1-12", channel: "testchan", video: "vid1", start: 12, end: 15, cite: 12, quote: "A fourth one, done.", blur: { on: true } }); await expect(page.getByTestId("timeline-add-form")).toHaveCount(0); });