import { test, expect, type APIRequestContext } from "@playwright/test"; import * as urls from "./urls"; import { warm, WARM_TIMEOUT } from "./warm"; // --------------------------------------------------------------------------- // WORK (plans/umtool-redesign.md, P3): every piece in one lit list, faceted by // stage, kind, site and lifecycle (active by default), with a search -- and // the old /browse, /articles and /sites keys still filtering. // // WRITES the fixture's REPORTS_ROOT/.umtool/lifecycle.json (a project parked, // marked done, then active again). // // A row's Park / Mark done are behind its own ⋯ menu (data-work-lifecycle), // never on the line: on a phone the line's buttons were drawn over the stage // pips and a tap on the row marked a piece done. On a phone a row is a card // with no lifecycle control at all -- phone.spec.ts holds that, at 390×844 // with touch (a tap anywhere opens the piece; Done and its Undo are the // piece's ⋯ sheet). // --------------------------------------------------------------------------- type Piece = { id: string; kind: string; lifecycle: string; title: string }; const pieces = async (request: APIRequestContext): Promise => ((await (await request.get("/api/pieces")).json()) as { pieces: Piece[] }).pieces; const rows = "[data-lit-list] [data-lit-line][data-piece]"; const ids = async (page: import("@playwright/test").Page) => page.locator(rows).evaluateAll((els) => els.map((e) => e.getAttribute("data-piece"))); const REPORT = "p:reports/report-fixture"; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/work", "/work?life=all", "/api/pieces"]); }); test("every active piece, one lit line each, and the rail's count agrees", async ({ page, request }) => { const active = (await pieces(request)).filter((p) => p.lifecycle === "active"); await page.goto(urls.workHref()); await expect(page.locator("[data-app-rail] [data-place=work]")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-work-count]")).toHaveAttribute("data-work-count", String(active.length)); expect((await ids(page)).sort()).toEqual(active.map((p) => p.id).sort()); await expect(page.locator("[data-rail-count=work]")).toHaveText(String(active.length)); // Articles and projects alike, each with its stage on the bar. await expect(page.locator(`${rows}[data-piece^='a:']`).first()).toBeVisible(); await expect(page.locator(`${rows}[data-piece^='p:']`).first()).toBeVisible(); const stage = await page.locator(rows).first().getAttribute("data-stage"); expect(["research", "article", "video", "deliver"]).toContain(stage); }); test("the facets filter, compose, and count what they would show", async ({ page }) => { await page.goto(urls.workHref()); const kind = page.locator("[data-facet=kind]").getByRole("link", { name: /^Article \d+$/ }); const n = Number((await kind.textContent())?.replace(/\D+/g, "")); await kind.click(); await expect(page).toHaveURL(/kind=article/); expect((await ids(page)).every((id) => id?.startsWith("a:"))).toBe(true); await expect(page.locator(rows)).toHaveCount(n); // A stage within it. await page.locator("[data-facet=stage]").getByRole("link", { name: /^Research \d+$/ }).click(); await expect(page).toHaveURL(/stage=research/); await expect(page).toHaveURL(/kind=article/); for (const s of await page.locator(rows).evaluateAll((els) => els.map((e) => e.getAttribute("data-stage")))) expect(s).toBe("research"); // The search, under the facets it was typed with; `/` puts the cursor there. await page.goto(urls.workHref()); await expect(page.locator("[data-lit-list]").first()).toHaveAttribute("data-hydrated", ""); await page.locator("body").press("/"); await expect(page.locator("[data-work-search]")).toBeFocused(); await page.keyboard.type("report-fixture"); await page.keyboard.press("Enter"); await expect(page).toHaveURL(/q=report-fixture/); await expect(page.locator(`${rows}[data-piece='${REPORT}']`)).toBeVisible(); }); test("the old lists' keys land on the same set", async ({ page }) => { // /browse?kind= → Work, and the kind is a facet chip. await page.goto("/browse?kind=report-video"); await expect(page).toHaveURL(/\/work\?kind=report-video$/); await expect(page.locator("[data-facet=kind] [aria-current=true]")).toHaveText(/^report video\s*\d+$/); await expect(page.locator(`${rows}[data-piece='${REPORT}']`)).toBeVisible(); // ...and /browse's state, a key with no chip group, is a chip you can take off. await page.goto("/browse?state=draft"); await expect(page.locator("[data-extra=state]")).toHaveText(/state: draft/); for (const id of await ids(page)) expect(id).toMatch(/^[ap]:/); await page.locator("[data-extra=state]").click(); await expect(page).not.toHaveURL(/state=/); // /sites?site=priv → Work by site, the site's page a link from the facet. await page.goto("/sites?site=priv"); await expect(page).toHaveURL(/by=site/); await expect(page.locator("[data-site=priv]")).toBeVisible(); await expect(page.locator("[data-site-page=priv]")).toHaveAttribute("href", urls.siteHref("priv")); }); test("Park takes a piece out of the active list, Parked lists it, Reactivate brings it back", async ({ page, request }) => { try { await page.goto(urls.workHref()); const line = page.locator(`${rows}[data-piece='${REPORT}']`); await expect(page.locator("[data-lit-list]").first()).toHaveAttribute("data-hydrated", ""); await line.click(); await line.getByRole("button", { name: "Lifecycle: Active" }).click(); await line.locator("[data-lifecycle-to=parked]").click(); await expect(page.locator(`[data-undo='${REPORT}']`)).toContainText("Parked — hidden from Active."); await expect(line).toHaveCount(0); await page.locator("[data-facet=life]").getByRole("link", { name: /^Parked \d+$/ }).click(); await expect(page).toHaveURL(/life=parked/); const parked = page.locator(`${rows}[data-piece='${REPORT}']`); await expect(parked).toHaveAttribute("data-lifecycle", "parked"); await parked.click(); await parked.getByRole("button", { name: "Lifecycle: Parked" }).click(); await parked.locator("[data-lifecycle-to=active]").click(); await expect(parked).toHaveCount(0); expect((await pieces(request)).find((p) => p.id === REPORT)?.lifecycle).toBe("active"); } finally { await request.post("/api/pieces/lifecycle", { data: { piece: REPORT, state: "active" } }); } });