import { test, expect, type APIRequestContext, type Page } from "@playwright/test"; import * as urls from "./urls"; import { researchArchiveHref, researchHref } from "../lib/research/hrefs"; import { runsHref } from "../lib/research/runs-hrefs"; import { warm, WARM_TIMEOUT } from "./warm"; // --------------------------------------------------------------------------- // umtool ON A PHONE (the mobile-first layout, 2026-10-24): below md the shell // is the place bar (back, the trail, ⋯) fixed at the top, the title in flow, // a piece's tab strip sticky under the bar, and the dock (Inbox · Research · // Work · Tools · ≡ More) fixed at the foot. The desk is unchanged -- the last // test here holds that at the suite's own desktop viewport. // // What this proves, at 390×844 with touch (and 360×740 for the overflow): // - the pinned chrome stays within 15% of the screen after a 600 px scroll, // on a piece page and on /work; // - no top-level page scrolls sideways; // - a /work card opens its piece on a tap anywhere, and never changes its // lifecycle (the operator marked a piece done by tapping a row); // - the piece's ⋯ → Done says what it did, and Undo puts it back in Active; // - a tap on an Inbox line never parks it; Park is a named button in the // line's ⋯ sheet. // // WRITES the fixture's REPORTS_ROOT/.umtool/lifecycle.json (the report // fixture marked done and parked, then active again). // --------------------------------------------------------------------------- const PROJECT = "reports/report-fixture"; const PIECE = `p:${PROJECT}`; const ZETA = "a:articles/zeta"; const PHONE = { width: 390, height: 844 }; /** The budget: 15% of the screen, pinned while reading. */ const BUDGET = Math.round(PHONE.height * 0.15); type Piece = { id: string; lifecycle: string }; const life = async (request: APIRequestContext, id: string) => ((await (await request.get("/api/pieces")).json()) as { pieces: Piece[] }).pieces.find((p) => p.id === id)?.lifecycle; const setLife = (request: APIRequestContext, piece: string, state: string) => request.post("/api/pieces/lifecycle", { data: { piece, state } }); const hydrated = (page: Page) => expect(page.locator("[data-place-more]:not([disabled]), [data-place-home]").first()).toBeVisible(); /** How many px of the screen's height fixed or sticky things cover (their union), with nothing open. */ async function pinned(page: Page): Promise<{ px: number; what: string[] }> { return page.evaluate(() => { const spans: [number, number][] = []; const what: string[] = []; for (const el of document.querySelectorAll("body *")) { const pos = getComputedStyle(el).position; if (pos !== "fixed" && pos !== "sticky") continue; const r = el.getBoundingClientRect(); const top = Math.max(0, r.top); const bottom = Math.min(innerHeight, r.bottom); if (r.width < 4 || bottom - top < 1) continue; // A sticky thing pins only where it has stuck; in flow, it is content. if (pos === "sticky" && Math.round(r.top) !== Math.round(parseFloat(getComputedStyle(el).top) || 0)) continue; spans.push([top, bottom]); what.push(`${el.tagName.toLowerCase()}[${[...el.attributes].map((a) => a.name).filter((n) => n.startsWith("data-")).join(",")}] ${Math.round(top)}–${Math.round(bottom)}`); } spans.sort((a, b) => a[0] - b[0]); let px = 0; let end = -1; for (const [a, b] of spans) { if (b <= end) continue; px += b - Math.max(a, end); end = b; } return { px: Math.round(px), what }; }); } /** Scroll the window down 600 px the way a thumb does (wheel steps), after making sure the page is that long. */ async function read600(page: Page) { await page.evaluate(() => { // The fixture's pages are short; the chrome is what is measured, not the // content, so a page shorter than a screen and 600 px gets room to scroll. const need = innerHeight + 700 - document.documentElement.scrollHeight; if (need > 0) { const pad = document.createElement("div"); pad.style.height = `${need}px`; (document.querySelector("main") ?? document.body).append(pad); } }); for (let i = 0; i < 6; i++) { await page.mouse.wheel(0, 100); await page.waitForTimeout(60); } await expect.poll(() => page.evaluate(() => Math.round(scrollY))).toBeGreaterThanOrEqual(590); // The place bar has slid away on the way down. await expect(page.locator("html")).toHaveAttribute("data-place-hidden", ""); await page.waitForTimeout(250); } test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/", "/work", urls.projectHref(PROJECT), urls.projectHref(PROJECT, { tab: "cut" }), "/api/pieces"]); }); test.describe("on a phone (390×844)", () => { test.use({ viewport: PHONE, isMobile: true, hasTouch: true }); test("the shell: the place bar and the dock, the title in flow, no rail", async ({ page }) => { await page.goto(urls.projectHref(PROJECT, { tab: "overview" })); await hydrated(page); await expect(page.locator("[data-app-rail]")).toBeHidden(); const bar = page.locator("[data-place-bar]"); await expect(bar).toBeVisible(); expect((await bar.boundingBox())!.height).toBe(44); await expect(bar.locator("[data-place-trail]")).toContainText("Projects"); await expect(bar.locator("[data-place-back]")).toBeVisible(); // The title is in flow, under the bar, and the head's controls are not on the page. const h1 = page.getByRole("heading", { level: 1 }); await expect(h1).toHaveText("The Report Fixture"); expect(await h1.evaluate((el) => getComputedStyle(el.closest("header")!).position)).toBe("static"); await expect(page.locator("[data-page-actions]")).toBeHidden(); // Stage pips, not the stepper. await expect(page.locator("[data-stage-pips]")).toBeVisible(); await expect(page.getByRole("list", { name: "Stage" })).toBeHidden(); // The dock: the rail's places and More, the place you are in lit. const dock = page.locator("[data-phone-dock]"); await expect(dock).toBeVisible(); await expect(dock.locator("[data-dock-place]")).toHaveText([/^Inbox/, "Research", /^Work/, "Tools", /More/]); await expect(dock.locator("[data-dock-place=work]")).toHaveAttribute("aria-current", "page"); const d = (await dock.boundingBox())!; expect(Math.round(d.y + d.height)).toBe(PHONE.height); expect(d.height).toBeGreaterThanOrEqual(56); // Every place in the dock is a thumb's target. for (const b of await dock.locator("[data-dock-place]").all()) expect((await b.boundingBox())!.height).toBeGreaterThanOrEqual(44); }); test("≡ More is a sheet: Settings, + Create, Jump, the theme; it closes on the dimmed page", async ({ page }) => { await page.goto(urls.workHref()); await hydrated(page); await page.locator("[data-dock-place=more]").tap(); const sheet = page.getByRole("dialog", { name: "More" }); await expect(sheet).toBeVisible(); await expect(sheet.getByRole("link", { name: "Settings" })).toHaveAttribute("href", urls.systemHref()); await expect(sheet.getByRole("link", { name: "+ Create" })).toHaveAttribute("href", urls.createHref()); await expect(sheet.getByRole("group", { name: "Theme" })).toBeVisible(); // At most 80% of the screen, from the bottom. const b = (await sheet.boundingBox())!; expect(Math.round(b.y + b.height)).toBe(PHONE.height); expect(b.height).toBeLessThanOrEqual(PHONE.height * 0.8 + 1); await page.mouse.click(195, 40); await expect(sheet).toHaveCount(0); }); test("pinned chrome after a 600 px scroll is within 15% of the screen: a piece page and /work", async ({ page }) => { for (const url of [urls.projectHref(PROJECT, { tab: "cut" }), urls.workHref()]) { await page.goto(url); await hydrated(page); await read600(page); const { px, what } = await pinned(page); test.info().annotations.push({ type: "pinned", description: `${url}: ${px}px of ${PHONE.height} (${what.join("; ")})` }); expect(px, `${url}: ${what.join("; ")}`).toBeLessThanOrEqual(BUDGET); } // The piece's tabs are still in reach: stuck under where the bar was. await page.goto(urls.projectHref(PROJECT, { tab: "cut" })); await hydrated(page); await read600(page); const tabs = page.locator("[data-piece-tabs]"); await expect.poll(async () => Math.round((await tabs.boundingBox())!.y)).toBe(0); // A scroll back up brings the place bar back. await page.mouse.wheel(0, -120); await expect(page.locator("html")).not.toHaveAttribute("data-place-hidden", ""); await expect.poll(async () => Math.round((await tabs.boundingBox())!.y)).toBe(44); }); test("a /work card opens its piece on a tap anywhere, and never changes its lifecycle", async ({ page, request }) => { try { await page.goto(urls.workHref()); await expect(page.locator("[data-lit-list]").first()).toHaveAttribute("data-hydrated", ""); const card = page.locator(`[data-lit-line][data-piece='${PIECE}']`); // A card: the title, kind · site, the pips -- and no lifecycle control, drawn or not. await expect(card.locator("[data-piece-link]")).toBeVisible(); await expect(card.locator("[data-work-card-kind]")).toBeVisible(); await expect(card.locator("[data-work-stage]")).toBeVisible(); await expect(card.locator("[data-lifecycle-to]")).toHaveCount(0); await expect(card.locator("[data-work-lifecycle]")).toBeHidden(); // No table head on a phone. await expect(page.locator("main .micro", { hasText: /^Piece$/ })).toBeHidden(); // A tap on the stage pips -- where Park and Mark done once sat -- opens the piece. const stage = (await card.locator("[data-work-stage]").boundingBox())!; const box = (await card.boundingBox())!; await card.tap({ position: { x: stage.x - box.x + stage.width / 2, y: stage.y - box.y + stage.height / 2 } }); await expect(page).toHaveURL(new RegExp(`/projects/${PROJECT}`)); expect(await life(request, PIECE)).toBe("active"); // And a tap at the card's far edge does the same. await page.goBack(); await expect(card).toBeVisible(); await card.tap({ position: { x: box.width - 6, y: box.height - 6 } }); await expect(page).toHaveURL(new RegExp(`/projects/${PROJECT}`)); expect(await life(request, PIECE)).toBe("active"); } finally { await setLife(request, PIECE, "active"); } }); test("Work's filters fold into one line that opens them in a sheet; a chip filters under it", async ({ page }) => { await page.goto(urls.workHref()); await hydrated(page); await expect(page.locator("[data-facet=kind]")).toBeHidden(); const summary = page.locator("[data-filter-summary]"); await expect(summary).toContainText(/^Active · any stage · any kind — \d+/); await summary.tap(); const sheet = page.getByRole("dialog", { name: "Filters" }); await expect(sheet).toBeVisible(); await sheet.locator("[data-facet=kind]").getByRole("link", { name: /^Article \d+$/ }).tap(); await expect(page).toHaveURL(/kind=article/); await expect(summary).toContainText("Active · any stage · Article"); await sheet.getByRole("button", { name: /^Show \d+$/ }).tap(); await expect(sheet).toHaveCount(0); for (const id of await page.locator("[data-lit-line][data-piece]").evaluateAll((els) => els.map((e) => e.getAttribute("data-piece")))) expect(id).toMatch(/^a:/); }); test("the piece's ⋯ → Done says what it did; Undo puts it back in Active", async ({ page, request }) => { try { await page.goto(urls.projectHref(PROJECT, { tab: "overview" })); await hydrated(page); await page.locator("[data-place-more]").tap(); const sheet = page.getByRole("dialog", { name: "Page actions" }); await expect(sheet).toBeVisible(); // Three labelled buttons, the current one marked and not a button. const choice = sheet.locator("[data-lifecycle-choice]"); await expect(choice).toHaveAttribute("data-lifecycle-choice", "active"); await expect(choice.locator("[data-lifecycle-current=active]")).toHaveText(/Active/); await expect(choice.getByRole("button")).toHaveText(["Parked", "Done"]); // The ⋯ items and the status line are in the sheet too. await expect(sheet.locator("[data-piece-more]")).toBeVisible(); await expect(sheet.locator(".micro").last()).toHaveText(/4 clips/i); await choice.locator("[data-lifecycle-to=done]").tap(); const bar = page.locator(`[data-undo='${PIECE}']`); await expect(bar).toContainText("Marked done — hidden from Active."); await expect(sheet).toBeHidden(); expect(await life(request, PIECE)).toBe("done"); // The bar sits above the dock, on the screen. const b = (await bar.boundingBox())!; const dock = (await page.locator("[data-phone-dock]").boundingBox())!; expect(b.y + b.height).toBeLessThanOrEqual(dock.y); expect(b.x).toBeGreaterThanOrEqual(0); expect(b.x + b.width).toBeLessThanOrEqual(PHONE.width); await bar.getByRole("button", { name: "Undo" }).tap(); await expect(bar).toHaveCount(0); await expect.poll(() => life(request, PIECE)).toBe("active"); await page.locator("[data-place-more]").tap(); await expect(page.locator("[data-lifecycle-choice]")).toHaveAttribute("data-lifecycle-choice", "active"); } finally { await setLife(request, PIECE, "active"); } }); test("a tap on an Inbox line never parks it; Park is a named button in the line's ⋯ sheet", async ({ page, request }) => { try { await page.goto(urls.homeHref()); await expect(page.locator("[data-lit-list]").first()).toHaveAttribute("data-hydrated", ""); const line = page.locator(`[data-lit-line][data-piece='${ZETA}'][data-card='iteration-ready']`); await expect(line).toBeVisible(); await line.scrollIntoViewIfNeeded(); // The desk's Park / Mute are not drawn on a phone; ⋯ is, always. await expect(line.locator("[data-lit-act]")).toBeHidden(); const more = line.locator(`[data-inbox-more] > button`); await expect(more).toBeVisible(); // Taps across the line -- its title, and the gap between its one action // and ⋯, where Park and Mute sit on the desk -- light it and nothing else. const box = (await line.boundingBox())!; for (const x of [8, box.width * 0.5, box.width - 8]) await line.tap({ position: { x, y: 10 } }); // Lit now, its action is drawn filled (and a little wider): measured as it is. // The taps keep 24 px from the action and ⋯: a phone's touch adjustment // gives a tap that close to a control to the control, as it should. await expect(line).toHaveAttribute("data-lit", ""); const m = (await more.boundingBox())!; const go = (await line.locator(".lit-go").boundingBox())!; const row = m.y - box.y + m.height / 2; for (const x of [go.x - box.x + go.width + 24, (go.x + go.width + m.x) / 2 - box.x, m.x - box.x - 24]) await line.tap({ position: { x, y: row } }); await expect(page.locator("[data-undo]")).toHaveCount(0); expect(await life(request, ZETA)).toBe("active"); await expect(line).toBeVisible(); await more.tap(); const sheet = page.getByRole("dialog"); await expect(sheet.getByRole("button", { name: /^Park/ })).toBeVisible(); await expect(sheet.getByRole("button", { name: /^Mute/ })).toBeVisible(); await sheet.getByRole("button", { name: "Close" }).tap(); await expect(sheet).toHaveCount(0); expect(await life(request, ZETA)).toBe("active"); } finally { await setLife(request, ZETA, "active"); } }); }); // ── no sideways scroll at 360×740 ─────────────────────────────────────────── const PAGES = [ urls.homeHref(), researchHref(), researchArchiveHref(), runsHref(), urls.workHref(), urls.projectsHref(), urls.siteHref("priv"), urls.createHref(), urls.toolsHref(), urls.findHref(), urls.phraseFinderHref(), urls.mixHref(), urls.facesHref(), urls.sourcesHref(), urls.benchHref(), urls.songToolsHref(), urls.systemHref(), urls.generationPolicyHref(), ...["overview", "article", "iterations", "cut", "media", "build", "deliver", "sources", "history"].map((tab) => urls.articleHref({ site: "articles", id: "zeta" }, { tab })), ...["overview", "cut", "sources"].map((tab) => urls.projectHref(PROJECT, { tab })), ]; test.describe("at 360×740", () => { test.use({ viewport: { width: 360, height: 740 }, isMobile: true, hasTouch: true }); test.describe.configure({ timeout: 90_000 }); for (const url of PAGES) { test(`${url} does not scroll sideways`, async ({ page }) => { const res = await page.goto(url); expect(res?.status(), url).toBeLessThan(400); await page.waitForLoadState("networkidle", { timeout: 5_000 }).catch(() => {}); const over = await page.evaluate(() => { const W = document.documentElement.clientWidth; const out: string[] = []; for (const el of document.querySelectorAll("body *")) { const r = el.getBoundingClientRect(); if (r.right > W + 1 && r.width > 0 && getComputedStyle(el).position !== "fixed") out.push(`${el.tagName.toLowerCase()}.${String(el.className).slice(0, 60)}`); } return { scroll: document.documentElement.scrollWidth - W, out: out.slice(0, 5) }; }); expect(over.scroll, `${url} is ${over.scroll}px too wide: ${over.out.join(", ")}`).toBeLessThanOrEqual(0); }); } }); // ── the desk is unchanged ─────────────────────────────────────────────────── test("on the desk the head is as it was: the rail, the trail, the actions inline, the stepper; no phone chrome", async ({ page }) => { await page.goto(urls.projectHref(PROJECT, { tab: "overview" })); await expect(page.locator("[data-app-rail]")).toBeVisible(); await expect(page.locator("[data-place-bar]")).toBeHidden(); await expect(page.locator("[data-phone-dock]")).toBeHidden(); const head = page.locator("header[data-app-header=page]"); // The trail above the title, in the Breadcrumb. await expect(head.getByRole("navigation", { name: "Breadcrumb" }).getByRole("link", { name: "Projects" })).toBeVisible(); // The actions sit in the head's row, right of the title, inline -- not a sheet. const actions = head.locator("[data-page-actions]"); await expect(actions).toBeVisible(); expect(await actions.evaluate((el) => getComputedStyle(el).position)).toBe("static"); await expect(head.locator("[data-lifecycle-chip]")).toBeVisible(); await expect(head.locator("[data-lifecycle-choice]")).toHaveCount(0); const t = (await head.locator("h1").boundingBox())!; const a = (await actions.boundingBox())!; expect(a.x).toBeGreaterThan(t.x + t.width); // The stepper, not the pips; the tabs wrap and do not stick. await expect(page.getByRole("list", { name: "Stage" })).toBeVisible(); await expect(page.locator("[data-stage-pips]")).toBeHidden(); expect(await page.locator("[data-piece-tabs]").evaluate((el) => getComputedStyle(el).position)).toBe("static"); // The page's column is still the scroller: the head never leaves the screen. await page.mouse.wheel(0, 600); await page.waitForTimeout(200); expect(await page.evaluate(() => scrollY)).toBe(0); });