import { test, expect, type Page } from "@playwright/test"; import * as urls from "./urls"; import { researchArchiveHref, researchHref } from "../lib/research/hrefs"; // --------------------------------------------------------------------------- // The shell (plans/umtool-redesign.md, P1, P3): the rail on every page -- // Inbox · Research · Work · Tools · Settings -- with the place you are in lit, // a bench without it, the ⌘K palette, the theme choice surviving a reload in // both directions, and the lit line's keys and motion. // --------------------------------------------------------------------------- const rail = (page: Page) => page.locator("[data-app-rail]"); const place = (page: Page, id: string) => rail(page).locator(`nav[aria-label=Main] > a[data-place=${id}]`); // Every place, a page under each, and what the rail says: "page" on the // place's own page, "true" on a page under it. const PLACES: { url: string; lit: string; current: "page" | "true" }[] = [ { url: urls.homeHref(), lit: "inbox", current: "page" }, // Research (R1): both its pages are the place's own. { url: researchHref(), lit: "research", current: "page" }, { url: researchArchiveHref(), lit: "research", current: "page" }, { url: urls.workHref(), lit: "work", current: "page" }, { url: urls.projectsHref(), lit: "work", current: "true" }, { url: urls.articleHref({ site: "articles", id: "delta" }), lit: "work", current: "true" }, { url: urls.siteHref("priv"), lit: "work", current: "true" }, { url: urls.toolsHref(), lit: "tools", current: "page" }, { url: urls.mixHref(), lit: "tools", current: "true" }, { url: urls.findHref(), lit: "tools", current: "true" }, // Every tool page lights Tools (P6: faces and a trim set lit Work before). { url: urls.facesHref(), lit: "tools", current: "true" }, { url: urls.trimHref("mk-hooks"), lit: "tools", current: "true" }, { url: urls.sourcesHref(), lit: "tools", current: "true" }, { url: urls.benchHref(), lit: "tools", current: "true" }, { url: urls.systemHref(), lit: "settings", current: "page" }, { url: urls.generationPolicyHref(), lit: "settings", current: "page" }, ]; for (const { url, lit, current } of PLACES) { test(`${url} has the rail, with ${lit} lit`, async ({ page }) => { const res = await page.goto(url); expect(res?.status()).toBe(200); await expect(rail(page)).toBeVisible(); await expect(place(page, lit)).toHaveAttribute("aria-current", current); // Exactly one place is lit. await expect(rail(page).locator("nav[aria-label=Main] > a[aria-current]")).toHaveCount(1); // The page head: one Breadcrumb nav, the page's name its h1. await expect(page.getByRole("navigation", { name: "Breadcrumb" }).locator("h1")).toHaveCount(1); }); } test("the rail's places, in order, with Research beside them and counts in Meter", async ({ page }) => { await page.goto(urls.homeHref()); const places = rail(page).locator("nav[aria-label=Main] > a[data-place]"); await expect(places).toHaveText([/^Inbox/, "Research", /^Work/, "Tools", "Settings"]); await expect(place(page, "research")).toHaveAttribute("href", researchHref()); await expect(place(page, "settings")).toHaveAttribute("href", urls.systemHref()); await expect(rail(page).locator("[data-rail-count=inbox]")).toHaveText(/^\d+$/); await expect(rail(page).locator("[data-rail-count=work]")).toHaveText(/^\d+$/); // Tools opens into its tools only while you are in one. await expect(rail(page).locator("[data-rail-sub=tools]")).toHaveCount(0); }); test("a song pile lights Tools and the song group, and its menu opens in the rail", async ({ page }) => { await page.goto(urls.pileHref("sort")); await expect(place(page, "tools")).toHaveAttribute("aria-current", "true"); const group = rail(page).locator("[data-nav-group=song]"); await expect(group.getByRole("button")).toHaveAttribute("aria-current", "page"); await group.getByRole("button").click(); await expect(group.getByRole("menuitem", { name: "sort", exact: true })).toHaveAttribute("aria-current", "page"); }); // ── ⌘K ───────────────────────────────────────────────────────────────────── const palette = (page: Page) => page.locator("dialog[data-jump]"); /** The chord is listened for once the palette has mounted. */ const ready = (page: Page) => expect(page.locator("dialog[data-jump][data-ready]")).toBeAttached(); test("⌘K opens the palette on a bench too; typing narrows it, Enter goes", async ({ page }) => { await page.goto(urls.clipBenchHref("reports/report-fixture", "c01")); await expect(rail(page)).toHaveCount(0); await ready(page); await page.keyboard.press("Control+k"); await expect(palette(page)).toBeVisible(); await expect(palette(page).locator("[data-jump-input]")).toBeFocused(); await page.keyboard.type("find"); await expect(palette(page).locator("[role=option][aria-selected=true]")).toHaveAttribute("data-jump-item", "find"); await page.keyboard.press("Enter"); await expect(page).toHaveURL(/\/tools\/find$/); await expect(palette(page)).toBeHidden(); }); test("the palette jumps to a piece, moves with the arrows, closes on Escape, and fits 1366×768", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); await page.goto(urls.homeHref()); await ready(page); await rail(page).locator("[data-rail-section=jump]").click(); await expect(palette(page)).toBeVisible(); const box = await palette(page).boundingBox(); expect(box!.y + box!.height).toBeLessThanOrEqual(768); // Places, tools and create actions first; the pieces arrive from the server. await expect(palette(page).locator("[data-jump-item=inbox]")).toBeVisible(); await expect(palette(page).locator("[data-jump-item=new-article]")).toBeVisible(); await page.keyboard.press("ArrowDown"); await expect(palette(page).locator("[role=option]").nth(1)).toHaveAttribute("aria-selected", "true"); await page.keyboard.press("Escape"); await expect(palette(page)).toBeHidden(); await page.keyboard.press("Control+k"); await page.keyboard.type("zeta"); const zeta = palette(page).locator("[data-jump-item='a:articles/zeta']"); await expect(zeta).toBeVisible(); await expect(zeta).toHaveAttribute("aria-selected", "true"); await page.keyboard.press("Enter"); await expect(page).toHaveURL(/\/articles\/zeta$/); }); test("a create action from the palette opens its line of /create (P5)", async ({ page }) => { await page.goto(urls.workHref()); await ready(page); await page.keyboard.press("Control+k"); await page.keyboard.type("video from a recording"); await expect(palette(page).locator("[role=option][aria-selected=true]")).toHaveAttribute("data-jump-item", "new-video-recording"); await page.keyboard.press("Enter"); await expect(page).toHaveURL(/\/create\?make=video-recording$/); await expect(page.locator("[data-make-form=video-recording] [data-new-project-form]")).toBeVisible(); }); test("a bench collapses the rail; its head still links home", async ({ page }) => { await page.goto(urls.clipBenchHref("reports/report-fixture", "c01")); await expect(page.locator("[data-app-header=bench]")).toBeVisible(); await expect(rail(page)).toHaveCount(0); await expect(page.locator("[data-app-header=bench]").getByRole("link", { name: "umtool home" })).toHaveAttribute("href", "/"); }); test("the theme choice is a cookie the server stamps on , both ways", async ({ page, context }) => { const themeCookie = async () => (await context.cookies()).find((c) => c.name === "umtool-theme")?.value ?? null; const control = (page: Page) => rail(page).getByRole("group", { name: "Theme" }); await page.goto(urls.homeHref()); await expect(page.locator("html")).not.toHaveAttribute("data-theme", /.+/); await expect(control(page).getByRole("button", { name: "Auto" })).toHaveAttribute("aria-pressed", "true"); // Light: stamped at once, and served stamped after a reload. await control(page).getByRole("button", { name: "Light" }).click(); await expect(page.locator("html")).toHaveAttribute("data-theme", "light"); expect(await themeCookie()).toBe("light"); let html = await (await page.request.get(urls.workHref())).text(); expect(html).toMatch(/]*data-theme="light"/); await page.reload(); await expect(page.locator("html")).toHaveAttribute("data-theme", "light"); await expect(control(page).getByRole("button", { name: "Light" })).toHaveAttribute("aria-pressed", "true"); // Dark wins over a light system too: the explicit choice goes both ways. await page.emulateMedia({ colorScheme: "light" }); await control(page).getByRole("button", { name: "Dark" }).click(); await expect(page.locator("html")).toHaveAttribute("data-theme", "dark"); expect(await themeCookie()).toBe("dark"); await page.reload(); await expect(page.locator("html")).toHaveAttribute("data-theme", "dark"); const ground = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--ground").trim()); expect(ground).toBe("#0c0a08"); // Auto: the cookie goes, the attribute goes, and the system decides again. await control(page).getByRole("button", { name: "Auto" }).click(); await expect(page.locator("html")).not.toHaveAttribute("data-theme", /.+/); expect(await themeCookie()).toBeNull(); await page.reload(); await expect(page.locator("html")).not.toHaveAttribute("data-theme", /.+/); const lightGround = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--ground").trim()); expect(lightGround).toBe("#f1efec"); html = await (await page.request.get(urls.workHref())).text(); expect(html).not.toMatch(/]*data-theme=/); }); test("j and k move the lit line, and focus goes with it", async ({ page }) => { await page.goto(urls.homeHref()); const list = page.locator("[data-lit-list]").first(); await expect(list).toHaveAttribute("data-hydrated", ""); const lines = list.locator("[data-lit-line]"); expect(await lines.count()).toBeGreaterThan(2); await expect(lines.nth(0)).toHaveAttribute("data-lit", ""); // From anywhere on the page: the Inbox is the page's one list. await page.locator("body").press("j"); await expect(lines.nth(1)).toHaveAttribute("data-lit", ""); await expect(lines.nth(0)).not.toHaveAttribute("data-lit", ""); await expect(lines.nth(1)).toBeFocused(); await page.keyboard.press("j"); await expect(lines.nth(2)).toHaveAttribute("data-lit", ""); await page.keyboard.press("k"); await expect(lines.nth(1)).toHaveAttribute("data-lit", ""); // Exactly one line is lit, and it is the one Tab stop into the list. await expect(list.locator("[data-lit-line][data-lit]")).toHaveCount(1); await expect(lines.nth(1)).toHaveAttribute("tabindex", "0"); await expect(lines.nth(0)).toHaveAttribute("tabindex", "-1"); // The lit line is its own focus mark: a quiet dashed outline, never the // 2px Signal ring every other control wears. const outline = await lines.nth(1).evaluate((el) => { const cs = getComputedStyle(el); return `${cs.outlineStyle} ${cs.outlineWidth}`; }); expect(outline).toBe("dashed 1px"); await page.keyboard.press("Tab"); const ring = await page.evaluate(() => { const cs = getComputedStyle(document.activeElement!); return `${cs.outlineStyle} ${cs.outlineWidth}`; }); expect(ring).toBe("solid 2px"); await page.keyboard.press("Shift+Tab"); await expect(lines.nth(1)).toBeFocused(); // The head sits on the lit line. const line = await lines.nth(1).boundingBox(); await expect.poll(async () => Math.round((await list.locator(".lit-head").boundingBox())?.y ?? -1)).toBe(Math.round(line!.y)); }); test("a control's focus ring is Signal at once: it does not fade in (the lit line's glide is the one motion)", async ({ page }) => { await page.goto(researchHref()); const search = page.getByRole("button", { name: /^Search/ }); await expect(search).toBeEnabled(); await page.getByRole("textbox", { name: "Ask" }).focus(); await page.keyboard.press("Tab"); // Read in the same task as the Tab lands: no wait, no poll. const seen = await page.evaluate(() => { const el = document.activeElement as HTMLElement; const probe = document.createElement("i"); probe.style.color = "var(--signal)"; document.body.append(probe); const signal = getComputedStyle(probe).color; probe.remove(); const cs = getComputedStyle(el); return { label: el.textContent?.trim().slice(0, 6), outline: `${cs.outlineStyle} ${cs.outlineWidth} ${cs.outlineColor}`, signal, props: cs.transitionProperty }; }); expect(seen.label).toBe("Search"); expect(seen.outline).toBe(`solid 2px ${seen.signal}`); expect(seen.props).not.toMatch(/outline|all/); }); test("the head glides, and does not under reduced motion", async ({ page }) => { const duration = () => page.locator("[data-lit-list] .lit-head").first().evaluate((el) => getComputedStyle(el).transitionDuration); await page.goto(urls.homeHref()); await expect(page.locator("[data-lit-list] .lit-head[data-placed]").first()).toBeAttached(); expect(await duration()).toMatch(/^0\.12s/); await page.emulateMedia({ reducedMotion: "reduce" }); await page.reload(); await expect(page.locator("[data-lit-list] .lit-head[data-placed]").first()).toBeAttached(); expect(await duration()).toMatch(/^0s/); }); test("every page links the umtool icon -- the parent mark lit in Signal -- and it is served", async ({ page, request }) => { await page.goto(urls.homeHref()); const href = await page.locator("head link[rel=icon][type='image/svg+xml']").first().getAttribute("href"); expect(href).toMatch(/^\/icon\.svg/); const res = await request.get(href!); expect(res.status()).toBe(200); expect(res.headers()["content-type"]).toContain("image/svg+xml"); // Signal's on-dark value is the lit line (common/lib/brand.ts ACCENTS.signal.onDark). expect(await res.text()).toContain('fill="#5fa8a0"'); });