Tests: shared helpers once in helpers.ts, not copied into each spec

- The panes view's pane, tid, frames, still, library, clickOpen and
  noFaults were copied into colours, panes3, panes4 (and partly forks,
  libraries, phone) with identical bodies; wide() into annotate and
  links; linksHere into review and reviewer; the one-key-per-frame loop
  of the latency tests into six specs (paced). They live in helpers.ts.
  The specs whose own still() or open() differ keep theirs.
- `:` + type + Enter written out where command() does the same, the
  newDoc alias of addTop, nodes' copy of focusedTitle, forks.test's four
  isStr guards, an unused fixture and `void request`, Math.max(x, x).
- panes3 and panes4 no longer call themselves rounds three and four.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-17 16:25:27 -05:00
1 parent 52cb7c2065
commit dbbe3effac
18 files changed
+176 -297

No files matched your search

+13 -33
View File
@@ -7,20 +7,9 @@
* calculus, …) and the hashed-words embedder (IE_EMBED=fake).
*/
import { expect, test, type Page } from "@playwright/test";
import { addTop, autoLayout, command, idle, jump, keys, selected, settle, state, visit, writeReport } from "./helpers";
import { addTop, autoLayout, command, idle, jump, keys, linksHere, paced, selected, settle, state, visit, writeReport } from "./helpers";
const body = (page: Page) => state(page, (s) => s.snap.nodes[s.focus.node].body as string);
/** The links on the focused node: quote → target title (or node id). */
const linksHere = (page: Page) =>
state(page, (s) => {
const snap = s.snap;
const out: Record<string, string> = {};
for (const c of snap.nodes[s.focus.node].children) {
const n = snap.nodes[c];
if (n.kind === "note" && n.ref) out[n.anchors[0].text] = n.ref.kind === "wiki" ? n.ref.title : n.ref.kind === "node" ? `node:${snap.nodes[n.ref.id]?.title}` : n.ref.url;
}
return out;
});
const suggestions = (page: Page) => state(page, (s) => s.links.forNode(s.focus.node, s.snap).map((x: any) => x.quote) as string[]);
async function column(page: Page, path = "/") {
@@ -30,9 +19,6 @@ async function column(page: Page, path = "/") {
await page.evaluate(() => document.fonts.ready);
}
/** A new top-level section with this text, typed from the keyboard; the focus is on it afterwards. */
const newDoc = addTop;
test.describe.configure({ mode: "serial" });
test.beforeEach(async ({ context }) => {
@@ -49,7 +35,7 @@ test("with /autolink on, the sure links are made at once after an edit, as their
// With a model, review is the default (e2e/reviewer.spec.ts); on links the scanner's sure ones unreviewed.
expect(await state(page, (s) => s.settings.autolink)).toBe("review");
await command(page, "/autolink on");
await newDoc(page, "Autolink one", "The cephalopod met Fred Hoyle, who taught it the lambda calculus.");
await addTop(page, "Autolink one", "The cephalopod met Fred Hoyle, who taught it the lambda calculus.");
await idle(page);
await expect(page.locator("article .lnk")).toHaveCount(3);
expect(await linksHere(page)).toEqual({ cephalopod: "Cephalopod", "Fred Hoyle": "Fred Hoyle", "lambda calculus": "Lambda calculus" });
@@ -65,7 +51,7 @@ test("with /autolink on, the sure links are made at once after an edit, as their
test("suggestions are drawn in the text; Tab reaches them, y links one, n declines one for good; S lists the rest", async ({ page }) => {
await column(page);
await command(page, "/autolink suggest");
await newDoc(page, "Suggested links", "The cephalopod met Fred Hoyle.\n\nHe spoke of the Hoyle state of carbon-12 and of the lambda calculus.");
await addTop(page, "Suggested links", "The cephalopod met Fred Hoyle.\n\nHe spoke of the Hoyle state of carbon-12 and of the lambda calculus.");
await idle(page);
await expect(page.locator("article .sugg")).toHaveCount(5);
await expect(page.locator("article .lnk")).toHaveCount(0);
@@ -109,7 +95,7 @@ test("suggestions are drawn in the text; Tab reaches them, y links one, n declin
test("typing [[ in the editor completes from library titles first, then Wikipedia; the choice is linked on save", async ({ page }) => {
await column(page);
await newDoc(page, "Completer", "A start.");
await addTop(page, "Completer", "A start.");
await idle(page);
await keys(page, "c End");
await page.keyboard.type(" See [[Recursion with");
@@ -132,7 +118,7 @@ test("typing [[ in the editor completes from library titles first, then Wikipedi
test("a bare [[term]] is looked up when the edit is saved: found, it is linked; not found, the writer is told", async ({ page }) => {
await column(page);
await newDoc(page, "Bare marks", "The [[Hoyle state]] and [[a thing nobody wrote about]].");
await addTop(page, "Bare marks", "The [[Hoyle state]] and [[a thing nobody wrote about]].");
await idle(page);
expect(await body(page)).toBe("The Hoyle state and a thing nobody wrote about.");
expect(await linksHere(page)).toEqual({ "Hoyle state": "Hoyle state" });
@@ -142,7 +128,7 @@ test("a bare [[term]] is looked up when the edit is saved: found, it is linked;
test("text a model writes arrives without its marks, and the ones that check out are links", async ({ page }) => {
await column(page);
await command(page, "/autolink on");
await newDoc(page, "Model marks", "A leaf about sea creatures and recursion.");
await addTop(page, "Model marks", "A leaf about sea creatures and recursion.");
await idle(page);
// e on a node with text and no sections asks the model for sections; the mock marks a few phrases.
await keys(page, "e");
@@ -166,7 +152,7 @@ test("text a model writes arrives without its marks, and the ones that check out
test("the Related list sits under a node; a number links the selected words to that row's section", async ({ page }) => {
await column(page);
await newDoc(page, "Related here", "Fixed points of functions: a function maps a point to itself, and iterating finds the fixed point.");
await addTop(page, "Related here", "Fixed points of functions: a function maps a point to itself, and iterating finds the fixed point.");
await idle(page);
await expect(page.locator(".related-list li").first()).toBeVisible();
const first = await page.locator(".related-list li .bl-title").first().textContent();
@@ -224,7 +210,7 @@ test("/linkhere and /linkall look for links in the background, with progress in
test("/autolink off looks for nothing, suggest only suggests, on links", async ({ page }) => {
await column(page);
await command(page, "/autolink off");
await newDoc(page, "Modes", "The cephalopod.");
await addTop(page, "Modes", "The cephalopod.");
await idle(page);
await expect(page.locator("article .sugg")).toHaveCount(0);
await expect(page.locator("article .lnk")).toHaveCount(0);
@@ -249,7 +235,7 @@ test("Tab then Enter on an article that is still loading go to its first link on
await autoLayout(page);
await page.goto("/");
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await newDoc(page, "Slow article link", "About the [[Hoyle state]].");
await addTop(page, "Slow article link", "About the [[Hoyle state]].");
await idle(page);
expect(await linksHere(page)).toEqual({ "Hoyle state": "Hoyle state" });
// The article takes a while to come (a slow network); the reader does not wait for it.
@@ -270,21 +256,15 @@ test("Tab then Enter on an article that is still loading go to its first link on
test("keypress → paint stays within a frame while suggestions are on screen and scans run after edits", async ({ page }) => {
await column(page);
await command(page, "/autolink suggest");
await newDoc(page, "Latency", "The cephalopod met Fred Hoyle.\n\nHe spoke of the Hoyle state of carbon-12 and of the lambda calculus.");
await addTop(page, "Latency", "The cephalopod met Fred Hoyle.\n\nHe spoke of the Hoyle state of carbon-12 and of the lambda calculus.");
await idle(page);
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
const paced = async (seq: string) => {
for (const k of seq.split(" ")) {
await page.keyboard.press(k);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
}
};
for (let round = 0; round < 4; round++) {
await paced("Tab Tab Tab Tab Escape Escape i j j Escape");
await paced(page, "Tab Tab Tab Tab Escape Escape i j j Escape");
// An edit, saved: the scan it starts runs after the save, off the keystroke.
await paced("c");
await paced(page, "c");
await page.keyboard.type(` More ${round}.`);
await paced("Escape");
await paced(page, "Escape");
}
await idle(page);
const ms: number[] = (await state(page, (s) => s.samples)).filter((x: any) => x.what !== "first-token").map((x: any) => x.ms).sort((a: number, b: number) => a - b);