import { test, expect } from "@playwright/test"; import { existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // Release 33: the new-project form's "a phrase across channels" seed. With no // source, the seed select offers the phrase; its four fields go to the // scaffold, which scans the fixture corpus (testchan's cue files, whose lines // say "The … fixture opens/speaks/begins") and writes a chronological timeline, // phrase-scan.json beside it, and the README's checklist. const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); test("the new-project form seeds a montage from a phrase said across channels", async ({ page }) => { const slug = "phrase-seed-probe"; const dir = path.join(FIXTURE, slug); rmSync(dir, { recursive: true, force: true }); try { await page.goto(urls.projectsHref()); await page.locator("[data-new-project]").click(); const seed = page.locator("[data-new-seed]"); await expect(seed.locator("option")).toHaveText(["an empty timeline", "a phrase across channels"]); await expect(page.locator("[data-new-phrase]")).toHaveCount(0); await page.locator("[data-new-slug]").fill(slug); await seed.selectOption("phrase"); await page.locator("[data-new-phrase]").fill("fixture (opens|speaks|begins)"); await page.locator("[data-new-channels]").fill("testchan"); await page.locator("[data-new-create]").click(); await page.waitForURL(`**/projects/${slug}`); const doc = JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8")); const clips = doc.timeline as Array<{ id: string; channel: string; cutStart: number; cutEnd: number; montage: { n: number; of: number; match: string } }>; expect(clips.length).toBeGreaterThanOrEqual(3); clips.forEach((c, k) => { expect(c.id).toBe(`s${String(k + 1).padStart(2, "0")}`); expect(c.channel).toBe("testchan"); expect(c.cutEnd).toBeGreaterThan(c.cutStart); expect(c.montage.n).toBe(k + 1); expect(c.montage.of).toBe(clips.length); expect(c.montage.match).toMatch(/fixture (opens|speaks|begins)/i); }); expect(doc.render.fetchPad).toBe(0); const scan = JSON.parse(readFileSync(path.join(dir, "phrase-scan.json"), "utf8")); expect(scan.instances).toHaveLength(clips.length); expect(readFileSync(path.join(dir, "README.md"), "utf8")).toContain("Clips seeded from a phrase scan"); } finally { rmSync(dir, { recursive: true, force: true }); } expect(existsSync(dir)).toBe(false); }); test("a phrase seed with a bad expression says so in the form, and makes nothing", async ({ page }) => { const slug = "phrase-seed-bad"; const dir = path.join(FIXTURE, slug); rmSync(dir, { recursive: true, force: true }); await page.goto(urls.projectsHref()); await page.locator("[data-new-project]").click(); await page.locator("[data-new-slug]").fill(slug); await page.locator("[data-new-seed]").selectOption("phrase"); await page.locator("[data-new-phrase]").fill("slow (news"); await page.locator("[data-new-channels]").fill("testchan"); await page.locator("[data-new-create]").click(); await expect(page.locator("[data-new-error]")).toContainText("not a regular expression"); expect(existsSync(dir)).toBe(false); });