Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/next-web.spec.ts9 * Description : SP Note Next Generation, web workstream — editor safety10 * (unknown content, content-error read-only), every new11 * block (insert → reload → still there and rendered),12 * sandboxed code, drawing, PDF annotations, voice note, rich13 * tasks, Markdown paste, motion + reduced motion, Universal14 * Command Center, panels, design tokens. Desktop Chromium,15 * scratch database only.16 * Module : tests17 * Repository : https://git.spboucher.ai/note-spboucher-ai18 * Project Website : https://note.spboucher.ai19 * Created : 2026-11-1920 * Last Modified : 2026-11-1921 *22 * Author : Simon-Pierre Boucher23 * Position : Professor of Finance24 * Institution : Université du Québec en Outaouais (UQO)25 * Organization : SP Boucher26 * Website : https://spboucher.ai27 * Git : https://git.spboucher.ai28 *29 * Preferred Contact: contact@spboucher.ai30 * Development : dev@spboucher.ai31 * Support : support@spboucher.ai32 * Security/Admin : admin@spboucher.ai33 *34 * Copyright (c) 202635 * Simon-Pierre Boucher36 * All rights reserved where applicable. This file is governed by the37 * applicable project license, copyright notices and relevant law.38 * Existing third-party rights and notices remain unaffected.39 *40 * License : None specified (no license file in this repository)41 *42 * Do not embed credentials, private keys, access tokens,43 * certificates or confidential personal information.44 *45 * =============================================================================46 * END OF SP BOUCHER SOURCE HEADER47 * =============================================================================48 */4950import { test, expect, type Page } from "@playwright/test";51import fs from "node:fs";52import crypto from "node:crypto";53import { execFileSync } from "node:child_process";54import { apiCall, docOf, para, PDF, sql, ORIGIN, expectNoHorizontalOverflow } from "./helpers";5556const made: string[] = [];57/** A task id of this run: a fixed id left behind by an interrupted run made the next run fail (the id was taken). */58const TASK_ID = crypto.randomUUID();59const newPage = async (page: Page, title: string, content?: unknown) => { const r = await apiCall(page, "POST", "/api/pages", { title: `E2E-next ${title} ${Date.now().toString(36)}`, ...(content ? { content } : {}) }); expect(r.status).toBe(201); made.push(r.body.id); return r.body as { id: string; version: number; title: string }; };60const server = async (page: Page, id: string) => (await apiCall(page, "GET", `/api/pages/${id}`)).body;61const saved = (page: Page) => expect(page.getByRole("status").filter({ hasText: /^Saved/ }).first()).toBeVisible({ timeout: 15_000 });62const editor = (page: Page) => page.locator("#main-scroll .note-editor .ProseMirror").first();63const open = async (page: Page, id: string) => { await page.goto(`/p/${id}`); await editor(page).waitFor(); };64const find = (n: any, type: string): any[] => [...(n?.type === type ? [n] : []), ...((n?.content ?? []) as any[]).flatMap((c) => find(c, type))];65const waitFor = async <T>(fn: () => Promise<T | null | undefined | false>, ms = 15_000): Promise<T> => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) throw new Error("condition not met in time"); await new Promise((r) => setTimeout(r, 300)); } };66/** Put the caret in a fresh empty paragraph at the very end of the page. */67const newLine = async (page: Page) => { await editor(page).locator("> p").last().click(); await page.keyboard.press("ControlOrMeta+End"); await page.keyboard.press(process.platform === "darwin" ? "Meta+ArrowDown" : "Control+End"); await page.keyboard.press("Enter"); };68const slash = async (page: Page, query: string) => { await newLine(page); await page.keyboard.type(`/${query}`); await expect(page.locator("[id^='sg-']").first()).toBeVisible(); await page.keyboard.press("Enter"); };69test.afterAll(async () => { await sql`delete from tasks where id = ${TASK_ID} or page_id = any(${made}::uuid[]) or page_id in (select id from pages where title like 'E2E-next %')`; if (made.length) await sql`delete from pages where id = any(${made}::uuid[]) or title like 'E2E-next %'`; });7071test("unknown content: a node type, a mark and an attr this client does not know survive an edit byte-identical", async ({ page }) => {72 await page.goto("/");73 const alien = { type: "hologram3000", attrs: { beam: { hue: 271, layers: ["a", "b"] }, id: "alienBlock1" }, content: [{ type: "paragraph", content: [{ type: "text", text: "from the future" }] }] };74 const marked = { type: "paragraph", content: [{ type: "text", text: "shimmering", marks: [{ type: "shimmer", attrs: { speed: 2 } }] }, { type: "text", text: " and " }, { type: "inlineGadget", attrs: { k: 1 } }] };75 const withAttr = { type: "callout", attrs: { kind: "note", icon: "💡", futureAttr: { keep: true } }, content: [para("known block, unknown attribute")] };76 const p = await newPage(page, "unknown", docOf(para("before"), alien, marked, withAttr, para("after")));77 const before = await server(page, p.id);78 await open(page, p.id);79 await expect(page.locator(".nb[data-node='unknownBlock']")).toContainText("hologram3000");80 await expect(page.getByText("This block was made with a newer version of SP Note.")).toBeVisible();81 await expect(page.locator(".unknown-mark")).toHaveText("shimmering"); await expect(page.locator(".unknown-inline")).toContainText("inlineGadget");82 await expect(page.getByTestId("editor-lock")).toHaveCount(0);83 await editor(page).locator("> p").first().click(); await page.keyboard.press("End"); await page.keyboard.type(" — typed elsewhere"); await saved(page);84 const after = await waitFor(async () => { const s = await server(page, p.id); return s.version > before.version ? s : null; });85 expect(JSON.stringify(after.content)).toContain("typed elsewhere");86 const pick = (doc: any) => ({ alien: JSON.stringify(find(doc, "hologram3000")[0]), gadget: JSON.stringify(find(doc, "inlineGadget")[0]), marks: JSON.stringify(doc.content[2].content[0].marks), attr: JSON.stringify(find(doc, "callout")[0].attrs) });87 expect(pick(after.content)).toEqual(pick(before.content)); // byte-identical JSON for everything unknown88 expect(JSON.stringify(after.content)).not.toMatch(/unknownBlock|unknownInline|unknownMark|xattrs/); // nothing internal leaks into the stored document89 // and it is still there after a reload90 await page.reload(); await expect(page.locator(".nb[data-node='unknownBlock']")).toBeVisible();91});9293test("content error: a document that fails the schema check opens read-only and is never autosaved", async ({ page }) => {94 await page.goto("/");95 // a block nested where the schema allows inline content only: the structure of a future version96 const bad = docOf(para("kept safe"), { type: "paragraph", content: [{ type: "paragraph", content: [{ type: "text", text: "nested block" }] }] }, { type: "table", content: [{ type: "tableRow", content: [{ type: "futureCell", attrs: { span: 2 } }] }] });97 const p = await newPage(page, "content error", bad); const before = await server(page, p.id);98 await open(page, p.id);99 const lock = page.getByTestId("editor-lock"); await expect(lock).toBeVisible(); await expect(lock).toContainText("Read-only — this page holds newer content"); await expect(lock).toContainText("Nothing was changed");100 await expect(editor(page)).toHaveAttribute("contenteditable", "false");101 await editor(page).click({ force: true }); await page.keyboard.type("must not be saved"); await page.waitForTimeout(2500);102 // leaving the page (last-chance save path) must not write either103 await page.goto("/"); await page.waitForTimeout(800);104 const after = await server(page, p.id); expect(after.version).toBe(before.version); expect(JSON.stringify(after.content)).toBe(JSON.stringify(before.content));105 expect((await sql`select count(*)::int as n from page_versions where page_id = ${p.id}`)[0].n).toBe(0);106 // the title is still editable and saving it does not touch the content107 await open(page, p.id); await page.getByLabel("Page title").fill("E2E-next renamed while locked"); await saved(page);108 const renamed = await waitFor(async () => { const s = await server(page, p.id); return s.title === "E2E-next renamed while locked" ? s : null; });109 expect(JSON.stringify(renamed.content)).toBe(JSON.stringify(before.content));110});111112test("every new block: insert from the slash menu, save, reload — still there and rendered", async ({ page }) => {113 test.setTimeout(120_000);114 await page.goto("/"); const p = await newPage(page, "all blocks", docOf(para("start"))); await open(page, p.id);115 const blocks: [string, string][] = [["diagram", "mermaid"], ["graphique", "chart"], ["runnable", "runCode"], ["drawing", "drawing"], ["annotate", "pdf"], ["voice", "audio"], ["canvas", "canvasLink"], ["bibliography", "bibliography"], ["transclusion", "blockRef"], ["living", "queryView"]];116 for (const [q, type] of blocks) { await slash(page, q); await expect(page.locator(`.nb[data-node='${type}']`).first(), type).toBeVisible(); }117 await slash(page, "citation"); await expect(page.getByLabel("Search references")).toBeVisible(); await page.keyboard.press("Escape"); await expect(page.locator("[data-node='citation']")).toHaveCount(1);118 await slash(page, "hypothesis"); // the knowledge callouts (kind switch between the eight kinds: context-bar test)119 await saved(page);120 const doc = (await waitFor(async () => { const s = await server(page, p.id); return find(s.content, "callout").length === 1 ? s : null; })).content;121 for (const [, type] of blocks) { const n = find(doc, type); expect(n.length, type).toBe(1); expect(typeof n[0].attrs.id, `${type} has a block id`).toBe("string"); }122 expect(find(doc, "citation").length).toBe(1); expect(find(doc, "callout").map((c) => c.attrs.kind)).toEqual(["hypothesis"]);123 // exact default attrs of SPEC §2 for a freshly inserted block124 const { id: _i, ...mm } = find(doc, "mermaid")[0].attrs; expect(mm).toEqual({ code: "", preview: null, previewHash: null });125 const { id: _a, ...au } = find(doc, "audio")[0].attrs; expect(au).toEqual({ attachmentId: null, duration: 0, title: "", recordedAt: null, transcript: [], transcriptStatus: "none", transcriptEngine: null, summary: null });126 const { id: _q, ...qv } = find(doc, "queryView")[0].attrs; expect(qv).toEqual({ source: "tasks", databaseId: null, viewId: null, filter: {}, layout: "list", limit: 25, title: "" });127 await page.reload(); await editor(page).waitFor();128 for (const [, type] of blocks) await expect(page.locator(`.nb[data-node='${type}']`), `${type} after reload`).toHaveCount(1);129 await expect(page.locator("[data-node='citation']")).toHaveCount(1); await expect(page.locator(".callout[data-kind='hypothesis']")).toHaveCount(1);130 await expect(page.getByTestId("editor-lock")).toHaveCount(0);131 // the live view feature-detects its endpoint: a server without POST /api/query shows a neutral state (or rows once the backend has it)132 await expect(page.locator(".nb[data-node='queryView']")).toContainText(/not available on this server yet|Nothing matches|Open|Updating|Live · updated/); // 3.0 backend: real rows + the live indicator (slice next-p-ra)133});134135test("mermaid renders; viewing stores nothing; the stored render follows the code once asked or edited (PNG preview + sha256 previewHash, never while typing)", async ({ page }) => {136 await page.goto("/"); const code = "flowchart LR\n Idea --> Draft\n Draft --> Published";137 const p = await newPage(page, "mermaid", docOf({ type: "mermaid", attrs: { code, preview: null, previewHash: null } }, para("tail"))); await open(page, p.id);138 await expect(page.getByTestId("mermaid-render").locator("svg")).toBeVisible({ timeout: 20_000 }); await expect(page.getByTestId("mermaid-render")).toContainText("Published");139 // merely viewing the page uploads nothing and saves nothing (no version, no `page.edited` event): the header says the render is not saved yet140 const v0 = (await server(page, p.id)).version; await page.waitForTimeout(5000); const viewed = await server(page, p.id); expect(viewed.version).toBe(v0); expect(find(viewed.content, "mermaid")[0].attrs.preview).toBeNull();141 await expect(page.locator(".nb[data-node='mermaid']")).toContainText("Render not saved yet");142 await page.locator(".nb[data-node='mermaid']").hover(); await page.getByRole("button", { name: "Save the render now" }).click();143 const first = await waitFor(async () => { const m = find((await server(page, p.id)).content, "mermaid")[0]; return m.attrs.preview ? m : null; }, 25_000);144 expect(first.attrs.previewHash).toBe(crypto.createHash("sha256").update(code, "utf8").digest("hex"));145 const img = await page.request.get(`/api/files/${first.attrs.preview}`); expect(img.status()).toBe(200); expect(img.headers()["content-type"]).toBe("image/png"); expect((await img.body()).subarray(1, 4).toString()).toBe("PNG");146 // edit the source: while the field is focused nothing is uploaded; after leaving it the preview and hash are refreshed147 await page.getByRole("button", { name: "Edit source" }).click(); const src = page.getByLabel("Mermaid source"); await src.click(); await page.keyboard.press("ControlOrMeta+End"); await page.keyboard.press("Meta+ArrowDown"); await page.keyboard.type("\n Published --> Archived");148 await expect(page.getByTestId("mermaid-render")).toContainText("Archived", { timeout: 15_000 }); await page.waitForTimeout(3500);149 const during = find((await server(page, p.id)).content, "mermaid")[0]; expect(during.attrs.code).toContain("Archived"); expect(during.attrs.preview, "no new render uploaded while the source field has the focus").toBe(first.attrs.preview);150 await editor(page).locator("> p").last().click();151 const second = await waitFor(async () => { const m = find((await server(page, p.id)).content, "mermaid")[0]; return m.attrs.preview !== first.attrs.preview ? m : null; }, 25_000);152 expect(second.attrs.previewHash).toBe(crypto.createHash("sha256").update(second.attrs.code, "utf8").digest("hex"));153 // a syntax error keeps the last valid render on screen and does not upload anything154 await src.click(); await page.keyboard.press("Meta+ArrowDown"); await page.keyboard.type("\n -->> ((("); await expect(page.getByText("This diagram has a syntax error")).toBeVisible({ timeout: 15_000 }); await expect(page.getByTestId("mermaid-render").locator("svg")).toBeVisible();155});156157test("runnable code: runs only on click, in a sandbox that has no network, no parent DOM, no cookies; an endless loop is killed", async ({ page }) => {158 test.setTimeout(90_000);159 await page.goto("/"); const attempts: string[] = []; const reached: string[] = [];160 // a request the browser starts and then refuses (CSP) still shows up as a request event: what matters is that none ever gets a response161 page.on("request", (r) => { if (r.url().includes("sandbox-probe")) attempts.push(`${r.url().split("sandbox-probe=")[1]}:${r.failure()?.errorText ?? "pending"}`); }); page.on("response", (r) => { if (r.url().includes("sandbox-probe")) reached.push(r.url()); }); page.on("requestfinished", (r) => { if (r.url().includes("sandbox-probe")) reached.push(r.url()); });162 const code = [163 "const out = {};",164 `try { const r = await fetch('${ORIGIN}/api/tree?sandbox-probe=1', { credentials: 'include' }); out.fetch = 'status ' + r.status; } catch (e) { out.fetch = 'blocked'; }`,165 `try { await new Promise((res, rej) => { const x = new XMLHttpRequest(); x.open('GET', '${ORIGIN}/api/tree?sandbox-probe=2'); x.onload = () => res(x.status); x.onerror = () => rej(new Error('xhr')); x.send(); }); out.xhr = 'reached'; } catch (e) { out.xhr = 'blocked'; }`,166 `try { importScripts('${ORIGIN}/sw.js?sandbox-probe=3'); out.importScripts = 'loaded'; } catch (e) { out.importScripts = 'blocked'; }`,167 "try { out.cookie = typeof document === 'undefined' ? 'no document' : 'cookie:' + document.cookie; } catch (e) { out.cookie = 'blocked'; }",168 "try { out.parentDom = typeof parent === 'undefined' || !parent ? 'no parent' : parent.document.title; } catch (e) { out.parentDom = 'blocked'; }",169 "try { out.topDom = typeof top === 'undefined' || !top ? 'no top' : top.document.body.innerHTML.length; } catch (e) { out.topDom = 'blocked'; }",170 "try { out.storage = typeof localStorage === 'undefined' ? 'no storage' : localStorage.getItem('note-ui'); } catch (e) { out.storage = 'blocked'; }",171 "try { out.idb = typeof indexedDB === 'undefined' ? 'no idb' : await new Promise((res) => { const q = indexedDB.open('note-local'); q.onsuccess = () => res('opened:' + q.result.objectStoreNames.length); q.onerror = () => res('blocked'); }); } catch (e) { out.idb = 'blocked'; }",172 "console.log('RESULT ' + JSON.stringify(out));", "21 * 2",173 ].join("\n");174 const p = await newPage(page, "sandbox", docOf({ type: "runCode", attrs: { language: "javascript", code, output: null } }, para("tail"))); await open(page, p.id);175 const block = page.locator(".nb[data-node='runCode']"); await expect(block).toBeVisible(); await page.waitForTimeout(1500);176 expect(await page.locator("iframe[sandbox]").count(), "nothing runs when the page opens").toBe(0); await expect(page.getByTestId("run-output")).toHaveCount(0);177 await block.getByRole("button", { name: "Run code" }).click();178 const out = page.getByTestId("run-output"); await expect(out).toContainText("RESULT", { timeout: 20_000 }); await expect(out).toContainText("42");179 const res = JSON.parse((await out.innerText()).split("RESULT ")[1].split("\n")[0]);180 expect(res.fetch).toBe("blocked"); expect(res.xhr).toBe("blocked"); expect(res.importScripts).toBe("blocked");181 expect(res.cookie).toMatch(/^(no document|blocked|cookie:)$/); expect(res.parentDom).toMatch(/^(no parent|blocked)$/); expect(res.topDom).toMatch(/^(no top|blocked)$/); expect(res.storage).toMatch(/^(no storage|blocked)$/);182 expect(String(res.idb)).not.toMatch(/^opened:[1-9]/); // an opaque origin never sees the app's IndexedDB stores183 expect(reached, `no request from the sandbox reached the server (attempts seen by the browser: ${attempts.join(", ") || "none"})`).toEqual([]);184 // the result is stored in the node (SPEC: output {text, error, ms, at})185 await saved(page); const stored = await waitFor(async () => { const n = find((await server(page, p.id)).content, "runCode")[0]; return n.attrs.output ? n : null; });186 expect(stored.attrs.output.error).toBe(false); expect(stored.attrs.output.text).toContain("RESULT"); expect(typeof stored.attrs.output.ms).toBe("number"); expect(new Date(stored.attrs.output.at).getTime()).toBeGreaterThan(0);187 // the frame itself: sandbox="allow-scripts" only, opaque origin, CSP without network — checked on a second run while it is alive188 const area = block.getByRole("textbox").first(); await area.click(); await page.keyboard.press("ControlOrMeta+a"); await page.keyboard.type("await new Promise((r) => setTimeout(r, 2500)); 'slow done'");189 await block.getByRole("button", { name: "Run code" }).click(); const frame = page.locator("iframe[sandbox]"); await expect(frame).toHaveCount(1);190 expect(await frame.getAttribute("sandbox")).toBe("allow-scripts"); const srcdoc = (await frame.getAttribute("srcdoc")) ?? ""; expect(srcdoc).toContain("default-src 'none'"); expect(srcdoc).not.toContain("slow done");191 await expect(out).toContainText("slow done", { timeout: 15_000 }); await expect(frame).toHaveCount(0);192 // endless loop: killed by the timeout while the app stays responsive193 await area.click(); await page.keyboard.press("ControlOrMeta+a"); await page.keyboard.type("for (;;) {}"); await block.getByRole("button", { name: "Run code" }).click();194 await expect(block.getByRole("button", { name: "Stop" })).toBeVisible(); await page.waitForTimeout(1200);195 // a stray key while the block card is selected must not replace it (AtomGuard): the text goes below196 await block.locator(".nb-label").click(); await page.keyboard.type("x"); await expect(block).toBeVisible();197 await editor(page).locator("> p").last().click(); await page.keyboard.type("still typing while it loops"); await expect(editor(page)).toContainText("still typing while it loops");198 await expect(out).toContainText(/Timed out/, { timeout: 20_000 }); await expect(page.locator("iframe[sandbox]")).toHaveCount(0);199});200201test("drawing: pen strokes with pointer events, undo, save → spn-ink-1 + PNG preview attachments", async ({ page }) => {202 await page.goto("/"); const p = await newPage(page, "drawing", docOf({ type: "drawing", attrs: { ink: null, preview: null, pk: null, width: 0, height: 0, background: "none" } }, para("tail"))); await open(page, p.id);203 await page.locator(".nb[data-node='drawing']").getByRole("button", { name: "Draw" }).click();204 const canvas = page.getByTestId("ink-canvas"); await expect(canvas).toBeVisible(); const box = (await canvas.boundingBox())!;205 const stroke = async (pts: [number, number][]) => { await page.mouse.move(box.x + pts[0][0], box.y + pts[0][1]); await page.mouse.down(); for (const [x, y] of pts.slice(1)) await page.mouse.move(box.x + x, box.y + y, { steps: 4 }); await page.mouse.up(); };206 await page.getByRole("button", { name: "Pen", exact: true }).click(); await stroke([[40, 40], [140, 60], [200, 140]]);207 await page.getByRole("button", { name: "Highlighter", exact: true }).click(); await stroke([[60, 180], [260, 180]]);208 await page.getByRole("button", { name: "Marker", exact: true }).click(); await stroke([[300, 40], [320, 200]]);209 await page.getByRole("button", { name: "Undo", exact: true }).click(); // removes the marker stroke210 await page.getByRole("button", { name: "Save drawing" }).click();211 const node = await waitFor(async () => { const n = find((await server(page, p.id)).content, "drawing")[0]; return n.attrs.ink && n.attrs.preview ? n : null; }, 20_000);212 expect(node.attrs.pk).toBeNull(); expect(node.attrs.width).toBeGreaterThan(0); expect(node.attrs.height).toBeGreaterThan(0);213 const ink = await (await page.request.get(`/api/files/${node.attrs.ink}`)).json();214 expect(ink.format).toBe("spn-ink-1"); expect(ink.width).toBe(node.attrs.width); expect(ink.strokes.map((s: any) => s.tool)).toEqual(["pen", "highlighter"]);215 for (const s of ink.strokes) { expect(s.color).toMatch(/^#[0-9a-f]{8}$/i); expect(s.points.length).toBeGreaterThan(1); for (const pt of s.points) { expect(pt.length).toBe(3); expect(pt[2]).toBeGreaterThanOrEqual(0); expect(pt[2]).toBeLessThanOrEqual(1); } }216 const png = await page.request.get(`/api/files/${node.attrs.preview}`); expect(png.headers()["content-type"]).toBe("image/png");217 await expect(page.locator(".nb[data-node='drawing'] img")).toBeVisible(); await page.reload(); await expect(page.locator(".nb[data-node='drawing'] img")).toBeVisible();218 // re-open: the saved ink is loaded back for editing219 await page.locator(".nb[data-node='drawing']").getByRole("button", { name: "Edit" }).click(); await expect(page.getByTestId("ink-canvas")).toBeVisible(); await expect(page.getByRole("button", { name: "Save drawing" })).toBeDisabled();220});221222test("pdf: upload, render, select text → highlight with normalised rects and a note stored in the node", async ({ page }) => {223 test.setTimeout(90_000);224 await page.goto("/"); const p = await newPage(page, "pdf", docOf({ type: "pdf", attrs: { attachmentId: null, name: "", page: 1, annotations: [] } }, para("tail"))); await open(page, p.id);225 const block = page.locator(".nb[data-node='pdf']");226 const [chooser] = await Promise.all([page.waitForEvent("filechooser"), block.getByRole("button", { name: "Choose a PDF" }).click()]); await chooser.setFiles({ name: "hello-note.pdf", mimeType: "application/pdf", buffer: PDF });227 await expect(page.getByTestId("pdf-canvas")).toBeVisible({ timeout: 30_000 });228 const layer = page.getByTestId("pdf-textlayer"); await expect(layer).toContainText("Hello note", { timeout: 20_000 });229 const painted = await page.getByTestId("pdf-canvas").evaluate((c: HTMLCanvasElement) => { const d = c.getContext("2d")!.getImageData(0, 0, c.width, c.height).data; let dark = 0; for (let i = 0; i < d.length; i += 4) if (d[i + 3] > 0 && d[i] < 100) dark++; return dark; }); expect(painted, "the page is really drawn").toBeGreaterThan(20);230 // select the text with the mouse (drag across the span), then highlight231 const span = layer.locator("span", { hasText: "Hello note" }).first(); const b = (await span.boundingBox())!;232 await page.mouse.move(b.x + 1, b.y + b.height / 2); await page.mouse.down(); await page.mouse.move(b.x + b.width - 1, b.y + b.height / 2, { steps: 8 }); await page.mouse.up();233 await block.getByRole("button", { name: "Highlight" }).first().click();234 await expect(page.getByTestId("pdf-annotation")).toHaveCount(1); await saved(page);235 const node = await waitFor(async () => { const n = find((await server(page, p.id)).content, "pdf")[0]; return n.attrs.annotations.length ? n : null; });236 const a = node.attrs.annotations[0]; expect(node.attrs.name).toBe("hello-note.pdf"); expect(a.kind).toBe("highlight"); expect(a.page).toBe(1); expect(a.text).toContain("Hello note"); expect(a.color).toMatch(/^#[0-9a-f]{6}$/i); expect(a.rects.length).toBeGreaterThan(0);237 for (const r of a.rects) { expect(r.length).toBe(4); for (const v of r) { expect(v).toBeGreaterThanOrEqual(0); expect(v).toBeLessThanOrEqual(1); } }238 // the text sits at x≈20/200, y≈100/200 from the bottom of a 200×200 page → about 10 % from the left and around the middle from the top239 expect(a.rects[0][0]).toBeGreaterThan(0.05); expect(a.rects[0][0]).toBeLessThan(0.2); expect(a.rects[0][1]).toBeGreaterThan(0.35); expect(a.rects[0][1]).toBeLessThan(0.6);240 await expect(page.getByTestId("pdf-annotation-list")).toContainText("Hello note");241 await page.reload(); await expect(page.getByTestId("pdf-annotation")).toHaveCount(1, { timeout: 30_000 });242});243244test("voice note: record with the microphone → uploaded attachment + player; transcription feature-detected", async ({ page }) => {245 test.setTimeout(90_000);246 await page.goto("/"); const p = await newPage(page, "audio", docOf({ type: "audio", attrs: { attachmentId: null, duration: 0, title: "", recordedAt: null, transcript: [], transcriptStatus: "none", transcriptEngine: null, summary: null } }, para("tail"))); await open(page, p.id);247 const block = page.locator(".nb[data-node='audio']"); await block.getByRole("button", { name: "Start recording" }).click();248 await expect(block.getByRole("timer")).toBeVisible({ timeout: 10_000 }); await page.waitForTimeout(1800); await block.getByRole("button", { name: "Stop recording" }).click();249 const node = await waitFor(async () => { const n = find((await server(page, p.id)).content, "audio")[0]; return n.attrs.attachmentId ? n : null; }, 30_000);250 expect(node.attrs.title).toMatch(/Voice note/); expect(new Date(node.attrs.recordedAt).getTime()).toBeGreaterThan(Date.now() - 120_000); expect(node.attrs.transcriptStatus).toBe("none");251 const file = await page.request.get(`/api/files/${node.attrs.attachmentId}`); expect(file.status()).toBe(200); expect(file.headers()["content-type"]).toMatch(/^audio\//); expect((await file.body()).length).toBeGreaterThan(200);252 await expect(block.getByRole("group", { name: "Audio player" })).toBeVisible(); await expect(block.getByLabel("Seek")).toBeVisible();253 // transcription: this server may not have POST /api/audio/<id>/transcribe yet → neutral state, node untouched254 await block.getByRole("button", { name: "Transcribe" }).click();255 await expect(block.getByText(/Transcription is not available on this server yet|in progress/i)).toBeVisible({ timeout: 10_000 });256 // a transcript written by another client shows clickable timestamps257 const withT = docOf({ type: "audio", attrs: { ...node.attrs, id: undefined, transcript: [{ t: 0, text: "bonjour" }, { t: 65, text: "second passage" }], transcriptStatus: "done", transcriptEngine: "test-engine" } });258 const p2 = await newPage(page, "audio transcript", withT); await open(page, p2.id);259 const list = page.getByRole("list", { name: "Transcript" }); await expect(list).toContainText("second passage"); await expect(list.getByRole("button").nth(1)).toContainText("1:05");260});261262test("chart: SVG render of the snapshot, kind switch and data grid edit are stored", async ({ page }) => {263 await page.goto("/"); const attrs = { kind: "bar", title: "Notes per month", columns: ["Month", "Notes"], rows: [["Aug", 12], ["Sep", 18], ["Oct", 25]], x: "Month", y: ["Notes"], source: null };264 const p = await newPage(page, "chart", docOf({ type: "chart", attrs }, para("tail"))); await open(page, p.id);265 const svg = page.getByTestId("chart-svg"); await expect(svg).toBeVisible(); expect(await svg.locator("rect").count()).toBeGreaterThanOrEqual(3); await expect(svg).toHaveAttribute("role", "img");266 const block = page.locator(".nb[data-node='chart']"); await block.getByRole("button", { name: "Line", exact: true }).click(); expect(await svg.locator("path").count()).toBeGreaterThan(0);267 await block.getByRole("button", { name: /Edit data/ }).click(); const grid = page.getByTestId("chart-grid"); await expect(grid).toBeVisible();268 const cell = grid.locator("tbody input").nth(1); await cell.fill("40"); await cell.blur(); await saved(page);269 const node = await waitFor(async () => { const n = find((await server(page, p.id)).content, "chart")[0]; return n.attrs.kind === "line" && n.attrs.rows[0][1] === 40 ? n : null; });270 expect(node.attrs.columns).toEqual(["Month", "Notes"]); expect(node.attrs.source).toBeNull(); expect(node.attrs.rows[1]).toEqual(["Sep", 18]);271});272273test("block reference: pick a page then a block → live read-only embed, jump to source; a removed target says so", async ({ page }) => {274 await page.goto("/"); const src = await newPage(page, "ref source", docOf({ type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: "Source heading" }] }, para("The sentence that gets transcluded.")));275 const srcDoc = (await server(page, src.id)).content; const target = srcDoc.content[1]; expect(typeof target.attrs.id).toBe("string");276 const p = await newPage(page, "ref host", docOf({ type: "blockRef", attrs: { pageId: null, blockId: null, mode: "embed" } }, para("tail"))); await open(page, p.id);277 const block = page.locator(".nb[data-node='blockRef']"); await block.getByLabel("Search a page").fill(src.title);278 await block.getByRole("option", { name: new RegExp(src.title.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) }).click();279 await page.getByTestId("blockref-blocks").getByRole("option", { name: /The sentence that gets transcluded/ }).click();280 await expect(page.getByTestId("blockref-embed")).toContainText("The sentence that gets transcluded."); await saved(page);281 const node = await waitFor(async () => { const n = find((await server(page, p.id)).content, "blockRef")[0]; return n.attrs.pageId ? n : null; }); expect(node.attrs).toMatchObject({ pageId: src.id, blockId: target.attrs.id, mode: "embed" });282 await expect(block.getByRole("link", { name: "Jump to the source" })).toHaveAttribute("href", `/p/${src.id}#block-${target.attrs.id}`);283 // live: the source changes, the embed follows after a reload of the host284 await apiCall(page, "PATCH", `/api/pages/${src.id}`, { content: docOf(srcDoc.content[0], { ...target, content: [{ type: "text", text: "Edited at the source." }] }) });285 await page.reload(); await expect(page.getByTestId("blockref-embed")).toContainText("Edited at the source.");286 const gone = await newPage(page, "ref missing", docOf({ type: "blockRef", attrs: { pageId: src.id, blockId: "doesNotExist", mode: "embed" } })); await open(page, gone.id);287 await expect(page.locator(".nb[data-node='blockRef']")).toContainText("Reference not found"); await expect(page.locator(".nb[data-node='blockRef']")).toContainText("Référence introuvable");288});289290test("rich tasks, callout kinds and AI sources: chips edit due / priority; the morphing bar follows the block type", async ({ page }) => {291 await page.goto("/");292 const p = await newPage(page, "tasks", docOf({ type: "taskList", content: [{ type: "taskItem", attrs: { checked: false, due: null, priority: null, taskId: TASK_ID }, content: [para("ship the editor")] }] }, { type: "callout", attrs: { kind: "note", icon: "💡" }, content: [para("a callout")] }, { type: "codeBlock", attrs: { language: "plaintext" }, content: [{ type: "text", text: "let x = 1" }] }, { type: "aiBlock", attrs: { model: "m", action: "synthesis", sources: [{ pageId: "11111111-2222-4333-8444-555555555555", blockId: "b1", title: "Field notes" }] }, content: [para("generated")] }, para("tail")));293 await open(page, p.id);294 await expect(page.locator(".ai-sources .cite-chip")).toHaveAttribute("href", "/p/11111111-2222-4333-8444-555555555555#block-b1"); await expect(page.locator(".ai-sources")).toContainText("Field notes");295 await expect(page.locator(".task-chip.is-linked")).toHaveCount(1);296 await editor(page).locator("li p", { hasText: "ship the editor" }).click();297 const bar = page.getByRole("toolbar", { name: "Task tools" }); await expect(bar).toBeVisible(); await bar.getByLabel("Due date").fill("2030-05-17"); await bar.getByRole("button", { name: "Priority high" }).click();298 await expect(page.locator(".task-chip.is-due")).toContainText("May 17"); await expect(page.locator(".task-chip.is-priority")).toHaveText("High");299 // chip editor (popover on the chip)300 await page.locator(".task-chip.is-priority").click(); const pop = page.getByRole("dialog", { name: "Task details" }); await expect(pop).toBeVisible(); await pop.getByRole("button", { name: "Low" }).click(); await pop.getByRole("button", { name: "Done" }).click(); await expect(page.locator(".task-chip.is-priority")).toHaveText("Low");301 // the bar morphs with the block under the cursor302 await page.getByText("a callout").click(); const cb = page.getByRole("toolbar", { name: "Callout tools" }); await expect(cb).toBeVisible(); await cb.getByRole("button", { name: "Decision" }).click(); await expect(page.locator(".callout")).toHaveAttribute("data-kind", "decision");303 await page.getByText("let x = 1").click(); const code = page.getByRole("toolbar", { name: "Code tools" }); await expect(code).toBeVisible(); await code.getByLabel("Code language").selectOption("typescript");304 await page.getByText("tail", { exact: true }).click(); await expect(page.locator(".context-bar")).toHaveCount(0);305 await saved(page);306 const doc = (await waitFor(async () => { const s = await server(page, p.id); return find(s.content, "callout")[0].attrs.kind === "decision" && find(s.content, "codeBlock")[0].attrs.language === "typescript" ? s : null; })).content;307 expect(find(doc, "taskItem")[0].attrs).toMatchObject({ checked: false, due: "2030-05-17", priority: "low", taskId: TASK_ID }); expect(typeof find(doc, "taskItem")[0].attrs.id).toBe("string");308 expect(find(doc, "callout")[0].attrs.icon).toBe("⚖️"); expect(find(doc, "aiBlock")[0].attrs.sources[0].title).toBe("Field notes"); expect(find(doc, "aiBlock")[0].attrs.action).toBe("synthesis");309});310311test("Markdown paste becomes blocks (including the new forms); plain prose stays text", async ({ page }) => {312 await page.goto("/"); const p = await newPage(page, "paste", docOf(para("start"))); await open(page, p.id);313 const paste = async (text: string) => { await newLine(page); await page.evaluate(async (t) => { await navigator.clipboard.writeText(t); }, text); await page.keyboard.press("ControlOrMeta+v"); };314 await paste("## Pasted heading\n\n- [x] done item\n- [ ] open item\n\n```mermaid\nflowchart LR\n P --> Q\n```\n\n> a quote");315 await expect(editor(page).locator("h2")).toHaveText("Pasted heading"); await expect(editor(page).locator("ul[data-type='taskList'] li")).toHaveCount(2); await expect(page.locator(".nb[data-node='mermaid']")).toHaveCount(1); await expect(editor(page).locator("blockquote")).toContainText("a quote");316 await paste("Just a sentence with a * star and an_underscore."); await expect(editor(page)).toContainText("Just a sentence with a * star and an_underscore.");317 await saved(page); const doc = (await server(page, p.id)).content; expect(find(doc, "mermaid")[0].attrs.code).toBe("flowchart LR\n P --> Q"); expect(find(doc, "taskItem").map((t) => t.attrs.checked)).toEqual([true, false]);318});319320test("Living Pages reveal and its reduced-motion fallback; motion classes degrade to a ≤ 120 ms cross-fade", async ({ page, browser }) => {321 await page.goto("/"); const many = docOf(...Array.from({ length: 40 }, (_, i) => para(`paragraph ${i + 1}`))); const p = await newPage(page, "motion", many);322 // animations run 25× slower while probed (DevTools playback rate): under load the 240 ms reveal used to be over before the probe ran. Reported timings are unchanged.323 const probe = async (pg: Page) => { const cdp = await pg.context().newCDPSession(pg); await cdp.send("Animation.enable"); await cdp.send("Animation.setPlaybackRate", { playbackRate: 0.04 }); await pg.goto(`/p/${p.id}`); await pg.locator("#main-scroll .note-editor .ProseMirror > p").first().waitFor(); return pg.evaluate(() => { const blocks = [...document.querySelectorAll("#main-scroll .note-editor .ProseMirror > *")]; const anims = blocks.map((b) => b.getAnimations().map((a) => ({ kf: (a.effect as KeyframeEffect).getKeyframes().map((k) => String(k.transform ?? "")), t: a.effect!.getTiming() }))); const root = document.querySelector("#main-scroll .note-editor .ProseMirror")!.getAnimations().map((a) => ({ d: a.effect!.getTiming().duration, kf: (a.effect as KeyframeEffect).getKeyframes().map((k) => String(k.transform ?? "none")) })); return { animated: anims.filter((a) => a.length).length, moving: anims.filter((a) => a.some((x) => x.kf.some((t) => t.includes("translateY(6px)")))).length, delays: anims.flatMap((a) => a.map((x) => Number(x.t.delay))).slice(0, 4), durations: anims.flatMap((a) => a.map((x) => Number(x.t.duration))).slice(0, 2), root }; }); };324 const normal = await probe(page);325 expect(normal.moving, "the first blocks rise 6 px").toBeGreaterThan(0); expect(normal.animated).toBeLessThanOrEqual(24); expect(normal.delays.slice(0, 3)).toEqual([0, 18, 36]); expect(normal.durations[0]).toBe(240);326 const ctx = await browser.newContext({ baseURL: ORIGIN, storageState: "test-results/.auth/state.json", viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" }); const rp = await ctx.newPage();327 const reduced = await probe(rp);328 expect(reduced.moving, "no block moves under Reduce Motion").toBe(0); expect(reduced.animated).toBe(0);329 for (const a of reduced.root) { expect(Number(a.d)).toBeLessThanOrEqual(120); expect(a.kf.every((t) => t === "none" || t === "")).toBe(true); }330 // CSS side: the command center (scale-in) and a menu (fade-up) become a plain 120 ms fade331 await rp.keyboard.press("Control+k"); const dlg = rp.getByRole("dialog", { name: "Command center" }); await expect(dlg).toBeVisible();332 const css = await rp.evaluate(() => { const el = document.querySelector("[cmdk-root]")!; const s = getComputedStyle(el); return { name: s.animationName, dur: s.animationDuration }; }); expect(css.name).toBe("fade-only"); expect(css.dur).toBe("0.12s");333 await rp.keyboard.press("Escape");334 // quick capture: the Lumen pulse exists in normal motion and is a static glow (no scale) under Reduce Motion335 const pulse = async (pg: Page) => pg.evaluate(async () => { const { lumenPulse } = await (window as any).__noteMotion(); lumenPulse(document.body); const el = document.querySelector(".lumen-pulse")!; return (el.getAnimations()[0].effect as KeyframeEffect).getKeyframes().map((k) => String(k.transform ?? "none")); });336 expect((await pulse(page)).some((t) => t.includes("scale"))).toBe(true); expect((await pulse(rp)).every((t) => t === "none")).toBe(true);337 await ctx.close();338});339340test("Universal Command Center: fuzzy commands + pages + recents, editor commands, keyboard only", async ({ page }) => {341 await page.goto("/"); const p = await newPage(page, "Zebra Quantum Ledger", docOf(para("body"))); await page.reload();342 await page.keyboard.press("Control+k"); const dlg = page.getByRole("dialog", { name: "Command center" }); await expect(dlg).toBeVisible(); const input = dlg.locator("[cmdk-input]");343 await expect(dlg).toContainText("Go to"); await expect(dlg).toContainText("navigate"); // groups + keyboard hints344 await input.fill("drk thm"); await expect(dlg.locator("[cmdk-item]").first()).toContainText("Dark theme"); await page.keyboard.press("Enter");345 await expect(dlg).toBeHidden(); await expect(page.locator("html")).toHaveClass(/dark/);346 await page.keyboard.press("Control+k"); await expect(dlg.locator("[cmdk-group-heading]").first()).toHaveText("Recent"); await expect(dlg.locator("[cmdk-item]").first()).toContainText("Dark theme"); // remembered347 await input.fill("light theme"); await page.keyboard.press("Enter"); await expect(page.locator("html")).not.toHaveClass(/dark/);348 // pages: fuzzy on the title, typo-tolerant subsequence349 await page.keyboard.press("Control+k"); await input.fill("zbra qntm"); await expect(dlg.locator("[cmdk-item]").first()).toContainText("Zebra Quantum Ledger"); await page.keyboard.press("Enter"); await expect(page).toHaveURL(new RegExp(`/p/${p.id}`)); await editor(page).waitFor();350 // contextual commands registered by the page and its editor351 await editor(page).locator("> p").last().click(); await page.keyboard.press("Control+k"); await input.fill("insert diagram"); await expect(dlg.locator("[cmdk-item]").first()).toContainText("Insert diagram"); await page.keyboard.press("Enter");352 await expect(page.locator(".nb[data-node='mermaid']")).toHaveCount(1);353 await page.keyboard.press("Control+k"); await input.fill("version history"); await page.keyboard.press("Enter"); await expect(page.getByRole("dialog", { name: "Version history" })).toBeVisible(); await page.keyboard.press("Escape");354 // semantic zoom through the command center: outline hides the body, a click on a heading comes back to the full text355 const z = await newPage(page, "zoom", docOf({ type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: "First part" }] }, para("intro sentence"), para("hidden detail"), { type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: "Second part" }] }, para("more"))); await open(page, z.id);356 await page.keyboard.press("Control+k"); await input.fill("outline zoom"); await expect(dlg.locator("[cmdk-item]").first()).toContainText("Zoom out to the outline"); await page.keyboard.press("Enter");357 await expect(page.getByText("hidden detail")).toBeHidden(); await expect(page.getByText("intro sentence")).toBeVisible(); await expect(page.getByText("Outline — click a heading")).toBeVisible();358 await page.getByRole("heading", { name: "Second part" }).click(); await expect(page.getByText("hidden detail")).toBeVisible();359 expect(JSON.stringify((await server(page, z.id)).content)).not.toContain("sz-"); // the zoom never touches the document360});361362test("workspace: outline panel, page open to the side (editable, saved), collapsible sidebar sections, system theme follows the OS", async ({ page }) => {363 await page.goto("/"); const side = await newPage(page, "side page", docOf(para("side body")));364 const main = await newPage(page, "main page", docOf({ type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: "Alpha section" }] }, para("main body"))); await open(page, main.id);365 await page.getByRole("button", { name: "Outline panel" }).click(); const panel = page.locator("aside[data-panel='outline']"); await expect(panel).toBeVisible(); await expect(panel.getByRole("navigation", { name: "Outline" })).toContainText("Alpha section");366 expect(await panel.evaluate((el) => getComputedStyle(el).animationName)).toBe("panel-in-right");367 const w0 = (await panel.boundingBox())!.width; const handle = panel.getByRole("separator", { name: "Resize panel" }); await handle.focus(); await page.keyboard.press("ArrowLeft"); await page.keyboard.press("ArrowLeft"); expect((await panel.boundingBox())!.width).toBeCloseTo(w0 + 48, 0);368 await page.evaluate((id) => (window as any).__noteUI().openPanel("page", id), side.id);369 const sp = page.getByTestId("side-page"); await expect(sp).toContainText("side body"); await sp.locator(".ProseMirror").click(); await page.keyboard.press("End"); await page.keyboard.type(" edited from the side");370 await waitFor(async () => JSON.stringify((await server(page, side.id)).content).includes("edited from the side"));371 expect(JSON.stringify((await server(page, main.id)).content)).not.toContain("edited from the side"); await expectNoHorizontalOverflow(page);372 await page.getByRole("button", { name: "Close panel" }).click(); await expect(page.locator("aside[data-panel]")).toHaveCount(0);373 // sidebar sections collapse and remember it374 const sec = page.getByRole("button", { name: "Intelligence" }); await expect(page.getByRole("link", { name: "Backlinks" })).toBeVisible(); await sec.click(); await expect(page.getByRole("link", { name: "Backlinks" })).toBeHidden(); await expect(sec).toHaveAttribute("aria-expanded", "false");375 await page.reload(); await expect(page.getByRole("button", { name: "Intelligence" })).toHaveAttribute("aria-expanded", "false"); await page.getByRole("button", { name: "Intelligence" }).click();376 // system theme: an OS change is followed while the app is open (was: only at load)377 await page.evaluate(() => (window as any).__noteUI().setTheme("system")); await page.emulateMedia({ colorScheme: "dark" }); await expect(page.locator("html")).toHaveClass(/dark/); await page.emulateMedia({ colorScheme: "light" }); await expect(page.locator("html")).not.toHaveClass(/dark/);378});379380test("design system: fonts are self-hosted and applied, tokens convert to the documented sRGB values, focus ring is solid", async ({ page }) => {381 await page.goto("/"); const p = await newPage(page, "Design tokens", docOf(para("body text"), { type: "codeBlock", attrs: { language: "plaintext" }, content: [{ type: "text", text: "mono" }] })); await open(page, p.id);382 const fonts = await page.evaluate(async () => { await (document as any).fonts.ready; const fam = (sel: string) => getComputedStyle(document.querySelector(sel)!).fontFamily; const loaded = [...(document as any).fonts].filter((f: any) => f.status === "loaded").map((f: any) => f.family.replace(/["']/g, "")); return { title: fam("[aria-label='Page title']"), body: fam("body"), code: fam(".note-editor pre"), loaded: [...new Set(loaded)] }; });383 expect(fonts.title).toContain("Source Serif 4 Variable"); expect(fonts.body).toContain("Inter Variable"); expect(fonts.code).toContain("JetBrains Mono Variable");384 for (const f of ["Inter Variable", "Source Serif 4 Variable", "JetBrains Mono Variable"]) expect(fonts.loaded, `${f} loaded from our origin`).toContain(f);385 const external = await page.evaluate(() => performance.getEntriesByType("resource").map((r) => r.name).filter((n) => /\.woff2?(\?|$)/.test(n) && !n.startsWith(location.origin))); expect(external).toEqual([]);386 // measured conversion of the oklch tokens (browser) = scripts/contrast.mjs (docs/next/DESIGN-SYSTEM-NEXT.md lists these exact values)387 const expected = JSON.parse(execFileSync("node", ["scripts/contrast.mjs", "--json"], { encoding: "utf8" })).hexes;388 for (const theme of ["light", "dark"] as const) {389 const measured = await page.evaluate((dark) => { document.documentElement.classList.toggle("dark", dark); const c = document.createElement("canvas"); c.width = c.height = 1; const ctx = c.getContext("2d", { colorSpace: "srgb" })!; const out: Record<string, string> = {}; for (const t of ["bg", "bg-elev", "bg-sunk", "bg-side", "bg-hover", "fg", "fg-muted", "fg-faint", "line", "line-strong", "accent", "accent-fg", "accent-soft", "ai", "ai-soft", "success", "warning", "danger"]) { ctx.clearRect(0, 0, 1, 1); ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue(`--${t}`).trim(); ctx.fillRect(0, 0, 1, 1); const d = ctx.getImageData(0, 0, 1, 1).data; out[t] = "#" + [d[0], d[1], d[2]].map((v) => v.toString(16).padStart(2, "0")).join("").toUpperCase(); } return out; }, theme === "dark");390 for (const [t, hex] of Object.entries(measured)) { const e = expected[theme][t]; const diff = [1, 3, 5].map((i) => Math.abs(parseInt(hex.slice(i, i + 2), 16) - parseInt(e.slice(i, i + 2), 16))); expect(Math.max(...diff), `${theme} --${t}: browser ${hex} vs script ${e}`).toBeLessThanOrEqual(2); }391 }392 await page.evaluate(() => document.documentElement.classList.remove("dark"));393 await page.keyboard.press("Tab"); const ring = await page.evaluate(() => { const el = document.activeElement as HTMLElement; const s = getComputedStyle(el); return { style: s.outlineStyle, width: s.outlineWidth, color: s.outlineColor }; });394 expect(ring.style).toBe("solid"); expect(parseFloat(ring.width)).toBeGreaterThanOrEqual(2); expect(ring.color).not.toMatch(/\/\s*0\.\d+\)|rgba\([^)]*,\s*0\.\d+\)/); // not a translucent ring395 // density had no CSS rule before 3.0396 const h = async () => page.evaluate(() => document.querySelector(".side-item")!.getBoundingClientRect().height); const comfy = await h(); await page.evaluate(() => { document.documentElement.dataset.density = "compact"; }); expect(await h()).toBeLessThan(comfy); await page.evaluate(() => { document.documentElement.dataset.density = "comfortable"; });397 expect(fs.existsSync("docs/next/DESIGN-SYSTEM-NEXT.md")).toBe(true);398});399