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

+1 -8
View File
@@ -5,17 +5,10 @@
* again in a later revision, or listed as detached when its words are gone. * again in a later revision, or listed as detached when its words are gone.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, seedLinks, selected, settle, state, visit } from "./helpers"; import { command, idle, jump, keys, seedLinks, selected, settle, state, visit, wide } from "./helpers";
const panes = (page: Page) => page.locator(".strip .pane"); const panes = (page: Page) => page.locator(".strip .pane");
async function wide(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await visit(page, path);
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
async function column(page: Page, path: string) { async function column(page: Page, path: string) {
await page.setViewportSize({ width: 1440, height: 900 }); await page.setViewportSize({ width: 1440, height: 900 });
// After wide(), this page's layout follows the window, and 1440 px is wide enough for panes. // After wide(), this page's layout follows the window, and 1440 px is wide enough for panes.
+16 -42
View File
@@ -7,33 +7,8 @@
* selection bar sits at its pane's level. Same build, mock model and mock Wikipedia as the others. * selection bar sits at its pane's level. Same build, mock model and mock Wikipedia as the others.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, pixels, seedLinks, settle, state } from "./helpers"; import { clickOpen, frames, library, pane, pixels, seedLinks, settle, state, still, tid } from "./helpers";
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
async function still(page: Page) {
await page.waitForFunction(
() =>
new Promise((r) => {
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
const x = at();
setTimeout(() => r(at() === x), 250);
}),
);
await frames(page);
}
/** Click a row (or words) in a pane, as the mouse would, wherever the pane is (a covered one too). */
async function open(page: Page, inPane: string, text: string, sel = ".row") {
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
await still(page);
}
async function library(page: Page) {
await autoLayout(page);
await page.goto("/");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
/** /**
* Every curve, with where it ends and what it lands in: its stroke's colour (RGB), its pane's * Every curve, with where it ends and what it lands in: its stroke's colour (RGB), its pane's
@@ -100,7 +75,7 @@ const alike = (a: number[] | null, b: number[] | null) => !!a && !!b && a.every(
test("every kind of pane's title rule is drawn by the curve into it, in the pane's colour: nodes (a top-level one too), articles and their sections", async ({ page }) => { test("every kind of pane's title rule is drawn by the curve into it, in the pane's colour: nodes (a top-level one too), articles and their sections", async ({ page }) => {
await library(page); await library(page);
for (const t of ["The tides", "Fixed points"]) await open(page, "Library", t); for (const t of ["The tides", "Fixed points"]) await clickOpen(page, "Library", t);
const seen = new Set<string>(); const seen = new Set<string>();
const check = async () => { const check = async () => {
for (const l of await lines(page)) { for (const l of await lines(page)) {
@@ -115,15 +90,15 @@ test("every kind of pane's title rule is drawn by the curve into it, in the pane
} }
}; };
await check(); await check();
await open(page, "Fixed points", "Recursion without names"); await clickOpen(page, "Fixed points", "Recursion without names");
await check(); await check();
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor"); await clickOpen(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible(); await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
// The article's head holds the focus now (its rule is then the text's ink): put the focus back in the section. // The article's head holds the focus now (its rule is then the text's ink): put the focus back in the section.
await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
await check(); await check();
await open(page, "Fixed-point combinator", "Y combinator", ".wrow .row"); await clickOpen(page, "Fixed-point combinator", "Y combinator", ".wrow .row");
await expect(page.locator(".wiki-pane .wiki-head .wsub")).toHaveCount(1); await expect(page.locator(".wiki-pane .wiki-head .wsub")).toHaveCount(1);
await still(page); await still(page);
await check(); await check();
@@ -138,9 +113,9 @@ test("every kind of pane's title rule is drawn by the curve into it, in the pane
test("a pane's colour is a function of the forest: unchanged by focus, a source scrolled out of sight, folding to a tab, or which way its rule is drawn", async ({ page }) => { test("a pane's colour is a function of the forest: unchanged by focus, a source scrolled out of sight, folding to a tab, or which way its rule is drawn", async ({ page }) => {
await library(page); await library(page);
for (const t of ["Infinispand", "Fixed points"]) await open(page, "Library", t); for (const t of ["Infinispand", "Fixed points"]) await clickOpen(page, "Library", t);
await open(page, "Infinispand", "Expansion by depth"); await clickOpen(page, "Infinispand", "Expansion by depth");
await open(page, "Fixed points", "The idea itself"); await clickOpen(page, "Fixed points", "The idea itself");
const colourOf = async () => Object.fromEntries((await lines(page)).map((l) => [l.to, { stroke: l.stroke, colour: l.colour, hue: l.paneHue }])); const colourOf = async () => Object.fromEntries((await lines(page)).map((l) => [l.to, { stroke: l.stroke, colour: l.colour, hue: l.paneHue }]));
const before = await colourOf(); const before = await colourOf();
const same = async (what: string) => { const same = async (what: string) => {
@@ -178,15 +153,14 @@ test("a pane's colour is a function of the forest: unchanged by focus, a source
await same("unfolded"); await same("unfolded");
}); });
test("the join of a curve and the rule it runs into is one stroke, on device pixels, at ratios 1, 1.25, 1.5, 2 and zoom 90 and 110 %", async ({ browser, request }) => { test("the join of a curve and the rule it runs into is one stroke, on device pixels, at ratios 1, 1.25, 1.5, 2 and zoom 90 and 110 %", async ({ browser }) => {
void request;
for (const dpr of [1, 1.25, 1.5, 2, 0.9, 1.1]) { for (const dpr of [1, 1.25, 1.5, 2, 0.9, 1.1]) {
const ctx = await browser.newContext({ viewport: { width: 1920, height: 760 }, deviceScaleFactor: dpr, colorScheme: "dark" }); const ctx = await browser.newContext({ viewport: { width: 1920, height: 760 }, deviceScaleFactor: dpr, colorScheme: "dark" });
await ctx.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort()); await ctx.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
const page = await ctx.newPage(); const page = await ctx.newPage();
await library(page); await library(page);
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t); for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await clickOpen(page, "Library", t);
await open(page, "The tides", "The force"); await clickOpen(page, "The tides", "The force");
// The focus to the last top-level pane, so The tides folds to its tab with its source out of sight. // The focus to the last top-level pane, so The tides folds to its tab with its source out of sight.
await pane(page, "Fixed points").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Fixed points").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
@@ -231,8 +205,8 @@ test("the join of a curve and the rule it runs into is one stroke, on device pix
test("a pane folded or scrolled past its title shows its tab, and its curve lands in the tab's foot; with its title in sight, in the title's rule", async ({ page }) => { test("a pane folded or scrolled past its title shows its tab, and its curve lands in the tab's foot; with its title in sight, in the title's rule", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 760 }); await page.setViewportSize({ width: 1920, height: 760 });
await library(page); await library(page);
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t); for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await clickOpen(page, "Library", t);
await open(page, "The tides", "The force"); await clickOpen(page, "The tides", "The force");
await pane(page, "Fixed points").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Fixed points").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
let ls = await lines(page); let ls = await lines(page);
@@ -283,9 +257,9 @@ test("a pane folded or scrolled past its title shows its tab, and its curve land
test("a pane covered across and down peeks out whole on both axes; the wheel scrolls it and it stays out; the selection bar of a pane under it is covered", async ({ page }) => { test("a pane covered across and down peeks out whole on both axes; the wheel scrolls it and it stays out; the selection bar of a pane under it is covered", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 760 }); await page.setViewportSize({ width: 1920, height: 760 });
await library(page); await library(page);
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t); for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await clickOpen(page, "Library", t);
await open(page, "Fixed points", "Recursion without names"); await clickOpen(page, "Fixed points", "Recursion without names");
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor"); await clickOpen(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible(); await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
await still(page); await still(page);
// The top-level trees' column is covered to spines, and folded down: hover the spine of a folded pane in it. // The top-level trees' column is covered to spines, and folded down: hover the spine of a folded pane in it.
+13 -31
View File
@@ -8,7 +8,7 @@
* the top-level trees are hoisted to (z) as in panes.spec.ts. * the top-level trees are hoisted to (z) as in panes.spec.ts.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state, visit } from "./helpers"; import { autoLayout, command, focusedTitle, frames, jump, keys, paced, pane, seedLinks, selected, settle, state, tid, visit } from "./helpers";
/** The first tree of panes by title, the picked child starred: [title, [children]] or a leaf's title. */ /** The first tree of panes by title, the picked child starred: [title, [children]] or a leaf's title. */
const tree = (page: Page) => const tree = (page: Page) =>
@@ -26,8 +26,6 @@ const columns = (page: Page) =>
[...c.querySelectorAll(":scope > .pane")].map((p) => p.querySelector(".wiki-head h2, .pane-head h2, .top h1")?.textContent?.trim() ?? ""), [...c.querySelectorAll(":scope > .pane")].map((p) => p.querySelector(".wiki-head h2, .pane-head h2, .top h1")?.textContent?.trim() ?? ""),
), ),
); );
/** A pane by its title. */
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
/** Each pane's box, by title. */ /** Each pane's box, by title. */
const boxes = (page: Page) => const boxes = (page: Page) =>
page.evaluate(() => page.evaluate(() =>
@@ -57,8 +55,6 @@ const curves = (page: Page) =>
return { from: Number(p.dataset.from), to: Number(p.dataset.to), cls: p.getAttribute("class") ?? "", a: { x: a.x + box.x, y: a.y + box.y }, b: { x: b.x + box.x, y: b.y + box.y } }; return { from: Number(p.dataset.from), to: Number(p.dataset.to), cls: p.getAttribute("class") ?? "", a: { x: a.x + box.x, y: a.y + box.y }, b: { x: b.x + box.x, y: b.y + box.y } };
}); });
}); });
const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
const nextFrames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
/** Wait until the strip and its columns have stopped scrolling (the strip follows the focus smoothly, columns other than the active pane's once the keys pause), and the curves have been drawn after. */ /** Wait until the strip and its columns have stopped scrolling (the strip follows the focus smoothly, columns other than the active pane's once the keys pause), and the curves have been drawn after. */
async function still(page: Page) { async function still(page: Page) {
await page.waitForFunction( await page.waitForFunction(
@@ -69,7 +65,7 @@ async function still(page: Page) {
setTimeout(() => r(at() === x), 300); setTimeout(() => r(at() === x), 300);
}), }),
); );
await nextFrames(page); await frames(page);
} }
async function open(page: Page) { async function open(page: Page) {
@@ -209,15 +205,9 @@ test("a link and an article's link open beside by default, in place with Shift;
// Twenty opens in a row: each a pane of its own, the column stacked, the keys still quick. // Twenty opens in a row: each a pane of its own, the column stacked, the keys still quick.
await open(page); await open(page);
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0)); await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
const paced = async (seq: string) => { await paced(page, "l l l");
for (const k of seq.split(" ")) { for (let i = 0; i < 20; i++) await paced(page, i % 4 === 3 ? "k k Enter" : "j Enter");
await page.keyboard.press(k); await paced(page, "[ [ [ ] ] ] l h j k");
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
}
};
await paced("l l l");
for (let i = 0; i < 20; i++) await paced(i % 4 === 3 ? "k k Enter" : "j Enter");
await paced("[ [ [ ] ] ] l h j k");
expect((await state(page, (s) => s.forest.trees[0].kids[0].kids.length)) as number).toBeGreaterThanOrEqual(3); expect((await state(page, (s) => s.forest.trees[0].kids[0].kids.length)) as number).toBeGreaterThanOrEqual(3);
const ms = (await state(page, (s) => s.samples.map((x: any) => x.ms))).sort((a: number, b: number) => a - b); const ms = (await state(page, (s) => s.samples.map((x: any) => x.ms))).sort((a: number, b: number) => a - b);
const p95 = ms[Math.floor(ms.length * 0.95)]; const p95 = ms[Math.floor(ms.length * 0.95)];
@@ -319,12 +309,12 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
// Scroll Eukaryote's text: the curve out of it moves with its link. // Scroll Eukaryote's text: the curve out of it moves with its link.
const before = edge("Eukaryote", "Bacteria")[0].a; const before = edge("Eukaryote", "Bacteria")[0].a;
await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 40)); await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 40));
await nextFrames(page); await frames(page);
cs = await curves(page); cs = await curves(page);
expect(Math.abs(edge("Eukaryote", "Bacteria")[0].a.y - (before.y - 40))).toBeLessThan(3); expect(Math.abs(edge("Eukaryote", "Bacteria")[0].a.y - (before.y - 40))).toBeLessThan(3);
// Scrolled out of its pane, the source is held at the pane's edge and the curve is dotted. // Scrolled out of its pane, the source is held at the pane's edge and the curve is dotted.
await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 400)); await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 400));
await nextFrames(page); await frames(page);
cs = await curves(page); cs = await curves(page);
expect(edge("Eukaryote", "Bacteria")[0].cls).toContain("lost"); expect(edge("Eukaryote", "Bacteria")[0].cls).toContain("lost");
// (The pane, scrolled past its title, shows its tab: its edge is the tab's foot; the curve ends turned up toward the link.) // (The pane, scrolled past its title, shows its tab: its edge is the tab's foot; the curve ends turned up toward the link.)
@@ -340,13 +330,9 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
expect(Math.abs(now.x - was.x)).toBeGreaterThan(20); expect(Math.abs(now.x - was.x)).toBeGreaterThan(20);
expect(now.x).toBeGreaterThan(r.x); expect(now.x).toBeGreaterThan(r.x);
// And they can be turned off, and on again. // And they can be turned off, and on again.
await page.keyboard.press(":"); await command(page, "/curves off");
await page.keyboard.type("/curves off");
await page.keyboard.press("Enter");
await expect(page.locator(".curves path")).toHaveCount(0); await expect(page.locator(".curves path")).toHaveCount(0);
await page.keyboard.press(":"); await command(page, "/curves on");
await page.keyboard.type("/curves on");
await page.keyboard.press("Enter");
await expect.poll(async () => (await curves(page)).length).toBeGreaterThan(3); await expect.poll(async () => (await curves(page)).length).toBeGreaterThan(3);
}); });
@@ -377,20 +363,16 @@ test("each fork has a colour, shared by its curve and the rule under its title;
// The active pane's heavy ink rule is as it was. // The active pane's heavy ink rule is as it was.
expect(await page.locator(".pane.active").evaluate((el) => getComputedStyle(el, "::after").height)).toBe("3px"); expect(await page.locator(".pane.active").evaluate((el) => getComputedStyle(el, "::after").height)).toBe("3px");
// Off: plain ink everywhere, as before colours. // Off: plain ink everywhere, as before colours.
await page.keyboard.press(":"); await command(page, "/colors off");
await page.keyboard.type("/colors off");
await page.keyboard.press("Enter");
await expect(page.locator(".panes")).toHaveAttribute("data-colors", "off"); await expect(page.locator(".panes")).toHaveAttribute("data-colors", "off");
await nextFrames(page); await frames(page);
expect((await curve("Simple cells")).stroke).toBe((await curve("Eukaryote")).stroke); expect((await curve("Simple cells")).stroke).toBe((await curve("Eukaryote")).stroke);
expect(await rule("Simple cells")).toBe(await rule("Complex cells")); expect(await rule("Simple cells")).toBe(await rule("Complex cells"));
// Kept with the settings. // Kept with the settings.
await page.reload(); await page.reload();
await page.waitForSelector(".strip .pane"); await page.waitForSelector(".strip .pane");
await expect(page.locator(".panes")).toHaveAttribute("data-colors", "off"); await expect(page.locator(".panes")).toHaveAttribute("data-colors", "off");
await page.keyboard.press(":"); await command(page, "/colors line");
await page.keyboard.type("/colors line");
await page.keyboard.press("Enter");
await expect(page.locator(".panes")).toHaveAttribute("data-colors", "line"); await expect(page.locator(".panes")).toHaveAttribute("data-colors", "line");
}); });
@@ -606,7 +588,7 @@ test("a pinned pane is not covered in its column, and outlives a closed parent a
expect((await columns(page))[2]).toEqual([grand]); expect((await columns(page))[2]).toEqual([grand]);
await expect(pane(page, grand).locator(".orphan-note")).toBeVisible(); await expect(pane(page, grand).locator(".orphan-note")).toBeVisible();
expect(await state(page, (s) => s.forest.trees.length)).toBe(2); expect(await state(page, (s) => s.forest.trees.length)).toBe(2);
await nextFrames(page); await frames(page);
expect((await curves(page)).filter((c) => c.to === orphan)).toHaveLength(0); expect((await curves(page)).filter((c) => c.to === orphan)).toHaveLength(0);
// Its own × closes it. // Its own × closes it.
await pane(page, grand).locator(".pane-ctl .pane-btn.close").click(); await pane(page, grand).locator(".pane-ctl .pane-btn.close").click();
+70 -3
View File
@@ -9,7 +9,7 @@
*/ */
import { writeFileSync } from "node:fs"; import { writeFileSync } from "node:fs";
import { inflateSync } from "node:zlib"; import { inflateSync } from "node:zlib";
import type { APIRequestContext, Page } from "@playwright/test"; import { expect, type APIRequestContext, type Page } from "@playwright/test";
/** A keypress → paint timing, as the page records it. */ /** A keypress → paint timing, as the page records it. */
export interface Sample { export interface Sample {
@@ -48,7 +48,7 @@ export async function libraryId(page: Page): Promise<string> {
} }
/** An address in the shared library: `/l/<id>` for its root, then a path within it (`/n/<node id>`, `/w/en/Octopus`). */ /** An address in the shared library: `/l/<id>` for its root, then a path within it (`/n/<node id>`, `/w/en/Octopus`). */
export async function libraryPath(page: Page, part = "/"): Promise<string> { async function libraryPath(page: Page, part = "/"): Promise<string> {
const base = `/l/${await libraryId(page)}`; const base = `/l/${await libraryId(page)}`;
return part === "/" ? base : base + part; return part === "/" ? base : base + part;
} }
@@ -138,6 +138,73 @@ export const selected = (page: Page) => state(page, (s) => (s.focus.range ? s.sn
/** Write a latency report to test-results/latency-<name>.json. */ /** Write a latency report to test-results/latency-<name>.json. */
export const writeReport = (name: string, report: unknown) => writeFileSync(`test-results/latency-${name}.json`, JSON.stringify(report, null, 2)); export const writeReport = (name: string, report: unknown) => writeFileSync(`test-results/latency-${name}.json`, JSON.stringify(report, null, 2));
/** Press space-separated keys one per frame, as a person types: each is painted before the next. */
export async function paced(page: Page, seq: string) {
for (const k of seq.split(" ")) {
await page.keyboard.press(k);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
}
}
/** The links on the focused node: quote → target title (`node:<title>` for a node, the address for the web). */
export 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;
});
// ---- the panes view ----
/** A pane of the strip by its title, exact, or matching a pattern. */
export const pane = (page: Page, title: string | RegExp) =>
typeof title === "string" ? page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first() : page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1)`, { hasText: title }) }).first();
/** A pane's id in the forest of panes, by its title. */
export const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
/** Two animation frames: what was laid out has been painted. */
export const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
/** Wait until the strip, its columns and its panes have stopped scrolling, and the curves have been drawn after. */
export async function still(page: Page) {
await page.waitForFunction(
() =>
new Promise((r) => {
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
const x = at();
setTimeout(() => r(at() === x), 250);
}),
);
await frames(page);
}
/** The library's panes at the site's root, laid out by the window, the fonts loaded. */
export async function library(page: Page) {
await autoLayout(page);
await page.goto("/");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
/** A window wide enough for panes, at a section (or an address, visit), the panes laid out by the window, the fonts loaded. */
export async function wide(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await visit(page, path);
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
/** Click a row (or the words `sel` matches) containing this text in a pane, as the mouse would, wherever the pane is (a covered one too); then wait until still. */
export async function clickOpen(page: Page, inPane: string, text: string, sel = ".row") {
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
await still(page);
}
/** Once still, no curve fails its invariant (curveFaults). */
export const noFaults = async (page: Page, when: string) => {
await still(page);
expect(await curveFaults(page), when).toEqual([]);
};
// ---- links written into the shared library ---- // ---- links written into the shared library ----
interface Snap { interface Snap {
@@ -277,7 +344,7 @@ export const curveFaults = (page: Page) =>
} }
// The start. // The start.
const pr = pe.getBoundingClientRect(); const pr = pe.getBoundingClientRect();
if (a.x < pr.left - 1 || a.x > Math.max(pr.right, pr.right) + 1) faults.push(`${name}: starts at x ${a.x}, outside its source pane ${pr.left}..${pr.right}`); if (a.x < pr.left - 1 || a.x > pr.right + 1) faults.push(`${name}: starts at x ${a.x}, outside its source pane ${pr.left}..${pr.right}`);
const footStart = Math.abs(a.y - (pr.top + TAB - 0.5)) <= 1.2 && Math.abs(a.x - Math.min(pr.right - 1, col.left)) <= 2; const footStart = Math.abs(a.y - (pr.top + TAB - 0.5)) <= 1.2 && Math.abs(a.x - Math.min(pr.right - 1, col.left)) <= 2;
if (lost || footStart) continue; if (lost || footStart) continue;
const cands = [...pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`)]; const cands = [...pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`)];
+5 -11
View File
@@ -4,7 +4,7 @@
* Latencies are measured in the page (keydown timestamp → the frame after the render). * Latencies are measured in the page (keydown timestamp → the frame after the render).
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { command, focusedTitle, idle, jump, keys, openPage, settle, state, writeReport, type Sample } from "./helpers"; import { command, focusedTitle, idle, jump, keys, openPage, paced, settle, state, type Sample, writeReport } from "./helpers";
const titlesUnder = (page: Page, title: string) => const titlesUnder = (page: Page, title: string) =>
page.evaluate((t) => { page.evaluate((t) => {
@@ -39,23 +39,17 @@ test("pre-generated expansions paint within the 50 ms budget", async ({ page })
await open(page); await open(page);
// One keystroke per frame (about 60 a second, well past any typist). Sent faster than that, // One keystroke per frame (about 60 a second, well past any typist). Sent faster than that,
// keys queue behind each other and the measurement becomes the length of the queue. // keys queue behind each other and the measurement becomes the length of the queue.
const keys = async (p: Page, seq: string) => {
for (const k of seq.split(" ")) {
await p.keyboard.press(k);
await p.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
}
};
// Walk the whole pre-generated outline: open every section, top to bottom, then every note in a few. // Walk the whole pre-generated outline: open every section, top to bottom, then every note in a few.
for (let i = 0; i < 70; i++) await keys(page, "j l"); for (let i = 0; i < 70; i++) await paced(page, "j l");
const opened = await page.locator(".node.open").count(); const opened = await page.locator(".node.open").count();
expect(opened).toBeGreaterThan(40); expect(opened).toBeGreaterThan(40);
// Close and reopen subtrees, and step through grains. // Close and reopen subtrees, and step through grains.
await keys(page, "O j l h l i j j i l l Escape Escape"); await paced(page, "O j l h l i j j i l l Escape Escape");
// Open notes in every form from the keyboard. // Open notes in every form from the keyboard.
await jump(page, "Levels of a node"); await jump(page, "Levels of a node");
await keys(page, "Tab Enter Tab Enter Tab Enter Escape Escape"); await paced(page, "Tab Enter Tab Enter Tab Enter Escape Escape");
await jump(page, "Expansion by depth"); await jump(page, "Expansion by depth");
await keys(page, "Tab Enter Tab Enter"); await paced(page, "Tab Enter Tab Enter");
await expect(page.locator(".gloss").first()).toBeVisible(); await expect(page.locator(".gloss").first()).toBeVisible();
await expect(page.locator(".inset").first()).toBeVisible(); await expect(page.locator(".inset").first()).toBeVisible();
await expect(page.locator(".sidenote").first()).toBeVisible(); await expect(page.locator(".sidenote").first()).toBeVisible();
+1 -2
View File
@@ -10,7 +10,7 @@
* at the end: the other specs share the first. * at the end: the other specs share the first.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, curveFaults, keys, libraryId, settle, state } from "./helpers"; import { autoLayout, command, curveFaults, frames, keys, libraryId, settle, state } from "./helpers";
const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready); const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready);
const status = (page: Page) => page.locator(".status .message"); const status = (page: Page) => page.locator(".status .message");
@@ -120,7 +120,6 @@ const rows = (page: Page) => panel(page).locator(".lib-row[data-lib]");
const row = (page: Page, title: string) => panel(page).locator(".lib-row[data-lib]", { has: page.locator(".lib-t", { hasText: title }) }); const row = (page: Page, title: string) => panel(page).locator(".lib-row[data-lib]", { has: page.locator(".lib-t", { hasText: title }) });
const titles = (page: Page) => rows(page).locator(".lib-t").allTextContents(); const titles = (page: Page) => rows(page).locator(".lib-t").allTextContents();
const loaded = (page: Page) => expect(panel(page)).not.toHaveAttribute("data-loading", /./); const loaded = (page: Page) => expect(panel(page)).not.toHaveAttribute("data-loading", /./);
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
/** Until the strip and its panes have stopped scrolling (a pane opened slides into view), then two frames for the curves. */ /** Until the strip and its panes have stopped scrolling (a pane opened slides into view), then two frames for the curves. */
async function still(page: Page) { async function still(page: Page) {
await page.waitForFunction( await page.waitForFunction(
+2 -15
View File
@@ -5,7 +5,7 @@
* the address it would have gone to. * the address it would have gone to.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state, visit, writeReport, type Sample } from "./helpers"; import { command, focusedTitle, jump, keys, paced, seedLinks, selected, settle, state, type Sample, visit, wide, writeReport } from "./helpers";
/** The panes' titles, left to right: a node's title, or W:article for a Wikipedia pane. */ /** The panes' titles, left to right: a node's title, or W:article for a Wikipedia pane. */
const trail = (page: Page) => const trail = (page: Page) =>
@@ -29,13 +29,6 @@ async function column(page: Page, path = "Fixed points") {
await page.waitForFunction(() => (globalThis as any).__ie?.ready); await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await page.evaluate(() => document.fonts.ready); await page.evaluate(() => document.fonts.ready);
} }
async function wide(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await visit(page, path);
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
/** Open a section in panes and select the first marked span in its text. */ /** Open a section in panes and select the first marked span in its text. */
async function inPane(page: Page, title: string, words: string) { async function inPane(page: Page, title: string, words: string) {
await jump(page, title); await jump(page, title);
@@ -507,12 +500,6 @@ test("a hostile article cannot run script or load anything from elsewhere, in a
}); });
test("keypress → paint stays within one frame budget through links and articles, in panes and in the column", async ({ page }) => { test("keypress → paint stays within one frame budget through links and articles, in panes and in the column", async ({ page }) => {
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))));
}
};
const report: Record<string, unknown> = {}; const report: Record<string, unknown> = {};
for (const view of ["panes", "column"] as const) { for (const view of ["panes", "column"] as const) {
if (view === "panes") await wide(page); if (view === "panes") await wide(page);
@@ -521,7 +508,7 @@ test("keypress → paint stays within one frame budget through links and article
const measure = async (passes: number) => { const measure = async (passes: number) => {
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0)); await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
for (let pass = 0; pass < passes; pass++) { for (let pass = 0; pass < passes; pass++) {
await paced(seq); await paced(page, seq);
await page.waitForTimeout(50); await page.waitForTimeout(50);
} }
const samples: Sample[] = await state(page, (s) => s.samples); const samples: Sample[] = await state(page, (s) => s.samples);
+5 -13
View File
@@ -1,6 +1,6 @@
/** The mouse, narrow screens, hover previews, hoisting, speculation, orphans, and an outside agent over HTTP. */ /** The mouse, narrow screens, hover previews, hoisting, speculation, orphans, and an outside agent over HTTP. */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { idle, jump, keys, openPage, settle, state } from "./helpers"; import { command, idle, jump, keys, openPage, settle, state } from "./helpers";
/** The first tree as the page (hoisted), with the library one step out. */ /** The first tree as the page (hoisted), with the library one step out. */
const open = (page: Page) => openPage(page, "Infinispand"); const open = (page: Page) => openPage(page, "Infinispand");
@@ -84,9 +84,7 @@ test("hoisting makes one node the whole page; Esc at its top steps out to its pa
test("with speculation on, the focused sentence is already being written when it is asked for", async ({ page }) => { test("with speculation on, the focused sentence is already being written when it is asked for", async ({ page }) => {
await open(page); await open(page);
await page.keyboard.press(":"); await command(page, "/speculate on");
await page.keyboard.type("/speculate on");
await page.keyboard.press("Enter");
await jump(page, "Typography"); await jump(page, "Typography");
await keys(page, "l i"); await keys(page, "l i");
await page.waitForTimeout(1200); // focus rests; the expansion is written in the background await page.waitForTimeout(1200); // focus rests; the expansion is written in the background
@@ -95,16 +93,12 @@ test("with speculation on, the focused sentence is already being written when it
// The whole text is there on the first frame: no stream to wait for. // The whole text is there on the first frame: no stream to wait for.
await expect(page.locator(".sidenote, .inset").filter({ hasText: "Mock" }).first()).toBeVisible({ timeout: 500 }); await expect(page.locator(".sidenote, .inset").filter({ hasText: "Mock" }).first()).toBeVisible({ timeout: 500 });
await idle(page); await idle(page);
await page.keyboard.press(":"); await command(page, "/speculate off");
await page.keyboard.type("/speculate off");
await page.keyboard.press("Enter");
}); });
test("deleting the words a note is about orphans the note, visibly", async ({ page }) => { test("deleting the words a note is about orphans the note, visibly", async ({ page }) => {
await open(page); await open(page);
await page.keyboard.press(":"); await command(page, "/auto off");
await page.keyboard.type("/auto off");
await page.keyboard.press("Enter");
await jump(page, "Focus and grain"); await jump(page, "Focus and grain");
await keys(page, "l Tab Enter"); // open its pre-generated note await keys(page, "l Tab Enter"); // open its pre-generated note
await expect(page.locator(".sidenote", { hasText: "A cursor that only addressed nodes" })).toHaveCount(1); await expect(page.locator(".sidenote", { hasText: "A cursor that only addressed nodes" })).toHaveCount(1);
@@ -117,9 +111,7 @@ test("deleting the words a note is about orphans the note, visibly", async ({ pa
await keys(page, "u"); // and undo brings the words, and the anchor, back await keys(page, "u"); // and undo brings the words, and the anchor, back
await expect(orphan).toHaveCount(0); await expect(orphan).toHaveCount(0);
await expect(page.locator(".sidenote", { hasText: "A cursor that only addressed nodes" })).toHaveCount(1); await expect(page.locator(".sidenote", { hasText: "A cursor that only addressed nodes" })).toHaveCount(1);
await page.keyboard.press(":"); await command(page, "/auto on");
await page.keyboard.type("/auto on");
await page.keyboard.press("Enter");
}); });
test("an outside agent edits over HTTP with the same ops, and the open page follows", async ({ page, request }) => { test("an outside agent edits over HTTP with the same ops, and the open page follows", async ({ page, request }) => {
+11 -12
View File
@@ -6,7 +6,7 @@
* (under “Scratch pad”) and leave the starter trees alone: the other specs share them. * (under “Scratch pad”) and leave the starter trees alone: the other specs share them.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, nodeAt, openAt, openPage, settle, state, synced } from "./helpers"; import { autoLayout, command, focusedTitle, idle, jump, keys, nodeAt, openAt, openPage, settle, state, synced } from "./helpers";
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { parseDoc } from "../src/core/format"; import { parseDoc } from "../src/core/format";
@@ -15,7 +15,6 @@ const FIXTURE = fileURLToPath(new URL("../tests/fixtures/menu-fixture.md", impor
/** The fixture with a link inside it, written relative to its top. */ /** The fixture with a link inside it, written relative to its top. */
const LINKED = readFileSync(FIXTURE, "utf8").replace("More text.", "More text.\n\n^ \"More text\" link -> ./First section"); const LINKED = readFileSync(FIXTURE, "utf8").replace("More text.", "More text.\n\n^ \"More text\" link -> ./First section");
const focusTitle = (page: Page) => state(page, (s) => s.snap.nodes[s.focus.node].title as string);
/** The title of the parent of the (first) node with this title. */ /** The title of the parent of the (first) node with this title. */
const parentOf = (page: Page, title: string) => const parentOf = (page: Page, title: string) =>
page.evaluate((t) => { page.evaluate((t) => {
@@ -96,7 +95,7 @@ test("the library root is the first page and a node like any other: its sections
await expect(page.locator(".top .byline")).toContainText(/^\d+ sections · \d+ nodes/); await expect(page.locator(".top .byline")).toContainText(/^\d+ sections · \d+ nodes/);
await keys(page, "Escape"); await keys(page, "Escape");
await expect(page.locator(".top h1")).toHaveText("Library"); await expect(page.locator(".top h1")).toHaveText("Library");
expect(await focusTitle(page)).toBe("Infinispand"); expect(await focusedTitle(page)).toBe("Infinispand");
}); });
test("an address names a node by its id, and survives a reload, Back and Forward; an old /doc/ address shows the library", async ({ page }) => { test("an address names a node by its id, and survives a reload, Back and Forward; an old /doc/ address shows the library", async ({ page }) => {
@@ -109,13 +108,13 @@ test("an address names a node by its id, and survives a reload, Back and Forward
expect(await state(page, (s) => s.focus.node)).toBe(amph); expect(await state(page, (s) => s.focus.node)).toBe(amph);
// A link to another node opens it; Back returns, Forward comes again. // A link to another node opens it; Back returns, Forward comes again.
await openAt(page, "Fixed points"); await openAt(page, "Fixed points");
expect(await focusTitle(page)).toBe("Fixed points"); expect(await focusedTitle(page)).toBe("Fixed points");
await page.goBack(); await page.goBack();
await ready(page); await ready(page);
await expect.poll(() => state(page, (s) => s.focus.node)).toBe(amph); await expect.poll(() => state(page, (s) => s.focus.node)).toBe(amph);
await page.goForward(); await page.goForward();
await ready(page); await ready(page);
await expect.poll(() => focusTitle(page)).toBe("Fixed points"); await expect.poll(() => focusedTitle(page)).toBe("Fixed points");
// What names nothing says so and shows the library: an address from before, a node that is gone. // What names nothing says so and shows the library: an address from before, a node that is gone.
await page.goto("/doc/the-tides"); await page.goto("/doc/the-tides");
await page.waitForSelector("article"); await page.waitForSelector("article");
@@ -138,17 +137,17 @@ test("the jump box searches the whole library, says where each match is, and goe
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
// Outside the hoisted node: the page goes back to the library, with the node open to it. // Outside the hoisted node: the page goes back to the library, with the node open to it.
await expect(page.locator(".top h1")).toHaveText("Library"); await expect(page.locator(".top h1")).toHaveText("Library");
expect(await focusTitle(page)).toBe("Amphidromes"); expect(await focusedTitle(page)).toBe("Amphidromes");
// Back to where the jump started. // Back to where the jump started.
await page.goBack(); await page.goBack();
await ready(page); await ready(page);
await expect.poll(() => focusTitle(page)).toBe("Infinispand"); await expect.poll(() => focusedTitle(page)).toBe("Infinispand");
// A top-level node is found like any other, and says it is in the library. // A top-level node is found like any other, and says it is in the library.
await page.keyboard.press("/"); await page.keyboard.press("/");
await page.keyboard.type("Fixed points"); await page.keyboard.type("Fixed points");
await expect(page.locator(".jump li").first().locator(".in")).toHaveText("Library"); await expect(page.locator(".jump li").first().locator(".in")).toHaveText("Library");
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
expect(await focusTitle(page)).toBe("Fixed points"); expect(await focusedTitle(page)).toBe("Fixed points");
}); });
test("a .md file is imported into a node deep in the library, exported from there the same, and copied just after itself", async ({ page }) => { test("a .md file is imported into a node deep in the library, exported from there the same, and copied just after itself", async ({ page }) => {
@@ -167,7 +166,7 @@ test("a .md file is imported into a node deep in the library, exported from ther
await command(page, "/import"); await command(page, "/import");
await (await chooser).setFiles({ name: "menu-fixture.md", mimeType: "text/markdown", buffer: Buffer.from(LINKED) }); await (await chooser).setFiles({ name: "menu-fixture.md", mimeType: "text/markdown", buffer: Buffer.from(LINKED) });
await expect(status(page)).toContainText("Imported menu-fixture.md as “Menu fixture”, under “Inbox”"); await expect(status(page)).toContainText("Imported menu-fixture.md as “Menu fixture”, under “Inbox”");
await expect.poll(() => focusTitle(page)).toBe("Menu fixture"); await expect.poll(() => focusedTitle(page)).toBe("Menu fixture");
expect(await parentOf(page, "Menu fixture")).toBe("Inbox"); expect(await parentOf(page, "Menu fixture")).toBe("Inbox");
// Its link, written relative to the file's top, is kept from the library root, and finds its section. // Its link, written relative to the file's top, is kept from the library root, and finds its section.
const link = await state(page, (s) => { const link = await state(page, (s) => {
@@ -185,7 +184,7 @@ test("a .md file is imported into a node deep in the library, exported from ther
// :/duplicate copies it with everything under it, just after itself, as one commit; the copy has the focus. // :/duplicate copies it with everything under it, just after itself, as one commit; the copy has the focus.
await command(page, "/duplicate"); await command(page, "/duplicate");
await expect(status(page)).toContainText("Saved a copy as “Menu fixture (copy)”"); await expect(status(page)).toContainText("Saved a copy as “Menu fixture (copy)”");
expect(await focusTitle(page)).toBe("Menu fixture (copy)"); expect(await focusedTitle(page)).toBe("Menu fixture (copy)");
expect(await kids(page, "Inbox")).toEqual(["Menu fixture", "Menu fixture (copy)"]); expect(await kids(page, "Inbox")).toEqual(["Menu fixture", "Menu fixture (copy)"]);
expect(await kids(page, "Menu fixture (copy)")).toEqual(["First section", "Second section"]); expect(await kids(page, "Menu fixture (copy)")).toEqual(["First section", "Second section"]);
expect(await state(page, (s) => s.commits()[0].message)).toBe("Duplicate “Menu fixture” as “Menu fixture (copy)”"); expect(await state(page, (s) => s.commits()[0].message)).toBe("Duplicate “Menu fixture” as “Menu fixture (copy)”");
@@ -234,7 +233,7 @@ test("Move under…: M picks any node in the library, or the root, and the node
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
await expect(picker).toHaveCount(0); await expect(picker).toHaveCount(0);
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Scratch pad"); expect(await parentOf(page, "Menu fixture (copy)")).toBe("Scratch pad");
expect(await focusTitle(page)).toBe("Menu fixture (copy)"); expect(await focusedTitle(page)).toBe("Menu fixture (copy)");
expect(await state(page, (s) => s.commits()[0].message)).toBe("Move “Menu fixture (copy)” under “Scratch pad”"); expect(await state(page, (s) => s.commits()[0].message)).toBe("Move “Menu fixture (copy)” under “Scratch pad”");
await expect(status(page)).toContainText("Moved “Menu fixture (copy)” under “Scratch pad”. u undoes."); await expect(status(page)).toContainText("Moved “Menu fixture (copy)” under “Scratch pad”. u undoes.");
await keys(page, "u"); await keys(page, "u");
@@ -323,7 +322,7 @@ test("a note being written in one place lands there after the reader has gone el
await quiet(page); await quiet(page);
await jump(page, "Inbox"); await jump(page, "Inbox");
await keys(page, "l j"); // Inbox open, and its first section: Menu fixture await keys(page, "l j"); // Inbox open, and its first section: Menu fixture
expect(await focusTitle(page)).toBe("Menu fixture"); expect(await focusedTitle(page)).toBe("Menu fixture");
await keys(page, "l i j e"); // select its second sentence and expand it await keys(page, "l i j e"); // select its second sentence and expand it
await expect.poll(() => state(page, (s) => s.pending.size)).toBe(1); await expect.poll(() => state(page, (s) => s.pending.size)).toBe(1);
await jump(page, "Fixed points"); await jump(page, "Fixed points");
+5 -12
View File
@@ -5,7 +5,7 @@
* (z) and start from it, as the first pane. * (z) and start from it, as the first pane.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, idle, jump, keys, openAt, settle, state, writeReport, type Sample } from "./helpers"; import { autoLayout, command, focusedTitle, idle, jump, keys, openAt, paced, settle, state, type Sample, writeReport } from "./helpers";
/** Each pane's title and box, left to right. */ /** Each pane's title and box, left to right. */
const panes = (page: Page) => const panes = (page: Page) =>
@@ -277,24 +277,17 @@ test("editing in a pane: c, type, Esc", async ({ page }) => {
test("keypress → paint stays within the 50 ms budget in panes", async ({ page }) => { test("keypress → paint stays within the 50 ms budget in panes", async ({ page }) => {
await open(page); await open(page);
// One keystroke per frame, as in the column test.
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))));
}
};
// Walk down and across: open each top-level section, then three of its children in turn, // Walk down and across: open each top-level section, then three of its children in turn,
// read a sentence of the last, close back up and move to the next section. // read a sentence of the last, close back up and move to the next section.
for (let pass = 0; pass < 2; pass++) { for (let pass = 0; pass < 2; pass++) {
await paced("O"); await paced(page, "O");
for (let i = 0; i < 10; i++) await paced(`${i === 0 ? "l" : "j"} l l l j l j l i j Escape h h`); for (let i = 0; i < 10; i++) await paced(page, `${i === 0 ? "l" : "j"} l l l j l j l i j Escape h h`);
} }
// Open notes in a pane from the keyboard. // Open notes in a pane from the keyboard.
await jump(page, "Levels of a node"); await jump(page, "Levels of a node");
await paced("Tab Enter Tab Enter Tab Enter Escape Escape"); await paced(page, "Tab Enter Tab Enter Tab Enter Escape Escape");
await jump(page, "Expansion by depth"); await jump(page, "Expansion by depth");
await paced("l Tab Enter Tab Enter Escape Escape"); await paced(page, "l Tab Enter Tab Enter Escape Escape");
const samples: Sample[] = await state(page, (s) => s.samples); const samples: Sample[] = await state(page, (s) => s.samples);
const ms = samples.filter((x) => x.what !== "first-token").map((x) => x.ms).sort((a, b) => a - b); const ms = samples.filter((x) => x.what !== "first-token").map((x) => x.ms).sort((a, b) => a - b);
const pct = (p: number) => ms[Math.min(ms.length - 1, Math.floor(ms.length * p))]; const pct = (p: number) => ms[Math.min(ms.length - 1, Math.floor(ms.length * p))];
+22 -49
View File
@@ -1,5 +1,5 @@
/** /**
* The panes view, round three: a click anywhere in a pane makes it active and anywhere clears a * The panes view: a click anywhere in a pane makes it active and anywhere clears a
* selection; a column's panes stand in the order of their sources; every pane in a crowded column * selection; a column's panes stand in the order of their sources; every pane in a crowded column
* shows at least its tab, above or below; a pane cut off for any reason peeks out whole; the curves * shows at least its tab, above or below; a pane cut off for any reason peeks out whole; the curves
* keep to their sources and landing lines through every kind of layout change (curveFaults); the * keep to their sources and landing lines through every kind of layout change (curveFaults); the
@@ -7,39 +7,12 @@
* between panes. Same build, mock model and mock Wikipedia as the others. * between panes. Same build, mock model and mock Wikipedia as the others.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, curveFaults, keys, seedLinks, settle, state } from "./helpers"; import { clickOpen, curveFaults, keys, library, noFaults, pane, seedLinks, settle, state, still } from "./helpers";
const TAB = 30; const TAB = 30;
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
async function still(page: Page) {
await page.waitForFunction(
() =>
new Promise((r) => {
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
const x = at();
setTimeout(() => r(at() === x), 250);
}),
);
await frames(page);
}
async function open(page: Page, inPane: string, text: string, sel = ".row") {
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
await still(page);
}
async function library(page: Page) {
await autoLayout(page);
await page.goto("/");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
const activeTitle = (page: Page) => page.locator(".pane.active").evaluate((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? ""); const activeTitle = (page: Page) => page.locator(".pane.active").evaluate((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? "");
const colTitles = (page: Page, i: number) => const colTitles = (page: Page, i: number) =>
page.evaluate((i) => [...document.querySelectorAll(".strip > .col")[i].querySelectorAll(":scope > .pane")].map((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? ""), i); page.evaluate((i) => [...document.querySelectorAll(".strip > .col")[i].querySelectorAll(":scope > .pane")].map((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? ""), i);
const noFaults = async (page: Page, when: string) => {
await still(page);
expect(await curveFaults(page), when).toEqual([]);
};
test.use({ viewport: { width: 1920, height: 1080 }, colorScheme: "dark" }); test.use({ viewport: { width: 1920, height: 1080 }, colorScheme: "dark" });
test.describe.configure({ mode: "serial" }); test.describe.configure({ mode: "serial" });
@@ -53,10 +26,10 @@ test.afterEach(({ page }) => settle(page));
test("a column's panes stand in the order of their sources: opened from a row higher up, a pane stands higher", async ({ page }) => { test("a column's panes stand in the order of their sources: opened from a row higher up, a pane stands higher", async ({ page }) => {
await library(page); await library(page);
await open(page, "Library", "Octopus minds"); await clickOpen(page, "Library", "Octopus minds");
await open(page, "Library", "Infinispand"); await clickOpen(page, "Library", "Infinispand");
await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Octopus minds"]); await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Octopus minds"]);
await open(page, "Library", "Fixed points"); await clickOpen(page, "Library", "Fixed points");
await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Fixed points", "Octopus minds"]); await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Fixed points", "Octopus minds"]);
// Kept with the view. // Kept with the view.
await page.reload(); await page.reload();
@@ -67,8 +40,8 @@ test("a column's panes stand in the order of their sources: opened from a row hi
test("a click anywhere in a pane that is not text, a row or a link makes that pane the active one; anywhere at all clears a selection, and so does Esc", async ({ page }) => { test("a click anywhere in a pane that is not text, a row or a link makes that pane the active one; anywhere at all clears a selection, and so does Esc", async ({ page }) => {
await library(page); await library(page);
await open(page, "Library", "Fixed points"); await clickOpen(page, "Library", "Fixed points");
await open(page, "Fixed points", "The idea itself"); await clickOpen(page, "Fixed points", "The idea itself");
for (const t of ["Library", "Fixed points", "The idea itself", "Library", "The idea itself", "Fixed points"]) { for (const t of ["Library", "Fixed points", "The idea itself", "Library", "The idea itself", "Fixed points"]) {
const p = pane(page, t); const p = pane(page, t);
/** A grid of points over the pane; those that fall on nothing that acts. */ /** A grid of points over the pane; those that fall on nothing that acts. */
@@ -125,7 +98,7 @@ test("a click anywhere in a pane that is not text, a row or a link makes that pa
test("every pane of a crowded column shows at least its tab, above or below the one looked at; tabs line up with the active rule; curves stay on their sources and lines", async ({ page }) => { test("every pane of a crowded column shows at least its tab, above or below the one looked at; tabs line up with the active rule; curves stay on their sources and lines", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 700 }); await page.setViewportSize({ width: 1920, height: 700 });
await library(page); await library(page);
for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points", "What a proof is"]) await open(page, "Library", t); for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points", "What a proof is"]) await clickOpen(page, "Library", t);
// The one looked at near the top: those below it stack at the column's foot. // The one looked at near the top: those below it stack at the column's foot.
await pane(page, "Infinispand").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Infinispand").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
@@ -172,7 +145,7 @@ test("every pane of a crowded column shows at least its tab, above or below the
test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => { test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 700 }); await page.setViewportSize({ width: 1920, height: 700 });
await library(page); await library(page);
for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points"]) await open(page, "Library", t); for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points"]) await clickOpen(page, "Library", t);
/** Hover each pane of the top-level trees' column that is cut off, and check it comes out whole, and the curves with it. */ /** Hover each pane of the top-level trees' column that is cut off, and check it comes out whole, and the curves with it. */
const sweep = async (label: string, across: boolean) => { const sweep = async (label: string, across: boolean) => {
const col = page.locator(".strip > .col").nth(1); const col = page.locator(".strip > .col").nth(1);
@@ -230,8 +203,8 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
expect(await sweep("beside a pinned one", false)).toBeGreaterThan(0); expect(await sweep("beside a pinned one", false)).toBeGreaterThan(0);
await keys(page, "P"); await keys(page, "P");
// Its column covered too: deeper panes push it under; a cut-off pane comes out across and down at once. // Its column covered too: deeper panes push it under; a cut-off pane comes out across and down at once.
await open(page, "Fixed points", "The idea itself"); await clickOpen(page, "Fixed points", "The idea itself");
await open(page, "The idea itself", "Three questions"); await clickOpen(page, "The idea itself", "Three questions");
await still(page); await still(page);
const col = page.locator(".strip > .col").nth(1); const col = page.locator(".strip > .col").nth(1);
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true); expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
@@ -241,8 +214,8 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
await page.setViewportSize({ width: 1920, height: 1080 }); await page.setViewportSize({ width: 1920, height: 1080 });
await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k))); await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k)));
await library(page); await library(page);
await open(page, "Library", "Infinispand"); await clickOpen(page, "Library", "Infinispand");
await open(page, "Library", "Octopus minds"); await clickOpen(page, "Library", "Octopus minds");
await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false); expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
@@ -251,10 +224,10 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
test("the curves keep to their sources and landing lines through every kind of layout change: scrolls, a resize, folding, a drag, an article arriving, a sticky tab", async ({ page }) => { test("the curves keep to their sources and landing lines through every kind of layout change: scrolls, a resize, folding, a drag, an article arriving, a sticky tab", async ({ page }) => {
await library(page); await library(page);
for (const t of ["Infinispand", "Fixed points"]) await open(page, "Library", t); for (const t of ["Infinispand", "Fixed points"]) await clickOpen(page, "Library", t);
await open(page, "Fixed points", "Recursion without names"); await clickOpen(page, "Fixed points", "Recursion without names");
await noFaults(page, "opened"); await noFaults(page, "opened");
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor"); await clickOpen(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible(); await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
await noFaults(page, "article arrived"); await noFaults(page, "article arrived");
// Scrolls: a pane's text, the strip. // Scrolls: a pane's text, the strip.
@@ -282,7 +255,7 @@ test("the curves keep to their sources and landing lines through every kind of l
test("the selection bar keeps clear of a pane's tab and of the words it is about", async ({ page }) => { test("the selection bar keeps clear of a pane's tab and of the words it is about", async ({ page }) => {
await library(page); await library(page);
await open(page, "Library", "Fixed points"); await clickOpen(page, "Library", "Fixed points");
const p = pane(page, "Fixed points"); const p = pane(page, "Fixed points");
await p.locator(".pane-scroll").evaluate((el) => (el.scrollTop = 160)); await p.locator(".pane-scroll").evaluate((el) => (el.scrollTop = 160));
await expect(p).toHaveAttribute("data-scrolled", ""); await expect(p).toHaveAttribute("data-scrolled", "");
@@ -306,7 +279,7 @@ test("the selection bar keeps clear of a pane's tab and of the words it is about
test("a dotted curve to a source out of sight in its pane turns, at its end, toward where the source is", async ({ page }) => { test("a dotted curve to a source out of sight in its pane turns, at its end, toward where the source is", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 560 }); await page.setViewportSize({ width: 1920, height: 560 });
await library(page); await library(page);
await open(page, "Library", "A mind made of text"); await clickOpen(page, "Library", "A mind made of text");
const lib = pane(page, "Library").locator(".pane-scroll"); const lib = pane(page, "Library").locator(".pane-scroll");
const lead = async () => const lead = async () =>
page.evaluate(() => { page.evaluate(() => {
@@ -331,9 +304,9 @@ test("a dotted curve to a source out of sight in its pane turns, at its end, tow
test("Alt with h j k l moves between panes from a node, a selection or an article; left then right comes back; [ ] still go up and down", async ({ page }) => { test("Alt with h j k l moves between panes from a node, a selection or an article; left then right comes back; [ ] still go up and down", async ({ page }) => {
await library(page); await library(page);
await open(page, "Library", "Infinispand"); await clickOpen(page, "Library", "Infinispand");
await open(page, "Library", "Fixed points"); await clickOpen(page, "Library", "Fixed points");
await open(page, "Fixed points", "Recursion without names"); await clickOpen(page, "Fixed points", "Recursion without names");
await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
expect(await activeTitle(page)).toBe("Recursion without names"); expect(await activeTitle(page)).toBe("Recursion without names");
@@ -362,7 +335,7 @@ test("Alt with h j k l moves between panes from a node, a selection or an articl
await page.keyboard.press("Alt+h"); await page.keyboard.press("Alt+h");
await expect.poll(() => activeTitle(page)).toBe("Fixed points"); await expect.poll(() => activeTitle(page)).toBe("Fixed points");
await page.keyboard.press("Alt+l"); await page.keyboard.press("Alt+l");
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor"); await clickOpen(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible(); await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
await pane(page, "Fixed-point combinator").locator(".wiki-head h2").dispatchEvent("click"); await pane(page, "Fixed-point combinator").locator(".wiki-head h2").dispatchEvent("click");
await expect.poll(() => activeTitle(page)).toBe("Fixed-point combinator"); await expect.poll(() => activeTitle(page)).toBe("Fixed-point combinator");
+2 -26
View File
@@ -1,26 +1,12 @@
/** /**
* The panes view, round four: curves over the panes' edges and under the selection bar and menus; * The panes view: curves over the panes' edges and under the selection bar and menus;
* a pane peeking out leaves every other curve clear of its place, and nothing stale behind; a * a pane peeking out leaves every other curve clear of its place, and nothing stale behind; a
* pane's title and its tab never show together; a peeking pane and the active one have clear edges; * pane's title and its tab never show together; a peeking pane and the active one have clear edges;
* a menu's button closes it; a link's underline and its curve are one stroke at every pixel ratio. * a menu's button closes it; a link's underline and its curve are one stroke at every pixel ratio.
*/ */
import { expect, test, type Browser, type Page } from "@playwright/test"; import { expect, test, type Browser, type Page } from "@playwright/test";
import { autoLayout, curveFaults, pixels, seedLinks, settle, visit } from "./helpers"; import { autoLayout, curveFaults, frames, library, noFaults, pane, pixels, seedLinks, settle, still, visit } from "./helpers";
const pane = (page: Page, title: string | RegExp) =>
typeof title === "string" ? page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first() : page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1)`, { hasText: title }) }).first();
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
async function still(page: Page) {
await page.waitForFunction(
() =>
new Promise((r) => {
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
const x = at();
setTimeout(() => r(at() === x), 250);
}),
);
await frames(page);
}
async function open(page: Page, inPane: string | RegExp, text: string | RegExp, sel = ".row") { async function open(page: Page, inPane: string | RegExp, text: string | RegExp, sel = ".row") {
// A row by its exact title (the shared library has top-level nodes whose titles start the same). // A row by its exact title (the shared library has top-level nodes whose titles start the same).
const it = sel === ".row" && typeof text === "string" ? pane(page, inPane).locator(".row", { has: page.locator(`.title:text-is("${text}")`) }) : pane(page, inPane).locator(sel, { hasText: text }); const it = sel === ".row" && typeof text === "string" ? pane(page, inPane).locator(".row", { has: page.locator(`.title:text-is("${text}")`) }) : pane(page, inPane).locator(sel, { hasText: text });
@@ -35,12 +21,6 @@ async function openNth(page: Page, inPane: string, n: number): Promise<string> {
await still(page); await still(page);
return title; return title;
} }
async function library(page: Page) {
await autoLayout(page);
await page.goto("/");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
/** The owner's kind of forest: several columns, crowded. */ /** The owner's kind of forest: several columns, crowded. */
async function forest(page: Page) { async function forest(page: Page) {
await library(page); await library(page);
@@ -59,10 +39,6 @@ async function forest(page: Page) {
await pane(page, "Generation on demand").locator(".pane-head h2").dispatchEvent("click"); await pane(page, "Generation on demand").locator(".pane-head h2").dispatchEvent("click");
await still(page); await still(page);
} }
const noFaults = async (page: Page, when: string) => {
await still(page);
expect(await curveFaults(page), when).toEqual([]);
};
test.use({ viewport: { width: 2000, height: 1000 }, colorScheme: "dark" }); test.use({ viewport: { width: 2000, height: 1000 }, colorScheme: "dark" });
test.describe.configure({ mode: "serial" }); test.describe.configure({ mode: "serial" });
+3 -8
View File
@@ -7,7 +7,7 @@
* directory, each state is saved there, light and dark. * directory, each state is saved there, light and dark.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, seedLinks, settle, state } from "./helpers"; import { autoLayout, command, frames, seedLinks, settle, state } from "./helpers";
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true, deviceScaleFactor: 3 }); test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true, deviceScaleFactor: 3 });
@@ -22,7 +22,6 @@ async function shot(page: Page, name: string) {
await page.emulateMedia({ colorScheme: "light" }); await page.emulateMedia({ colorScheme: "light" });
} }
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
async function start(page: Page) { async function start(page: Page) {
await seedLinks(page.request); await seedLinks(page.request);
@@ -347,13 +346,9 @@ test("the libraries panel, the top menu, and the other layouts are a tap away; a
await page.locator(".menu.sheet .choices button", { hasText: "auto" }).tap(); await page.locator(".menu.sheet .choices button", { hasText: "auto" }).tap();
await at(page, "Fixed points", 1); await at(page, "Fixed points", 1);
// /view panes: side by side even here; /view auto: pages again. // /view panes: side by side even here; /view auto: pages again.
await page.keyboard.press(":"); await command(page, "/view panes");
await page.keyboard.type("/view panes");
await page.keyboard.press("Enter");
await expect(page.locator(".panes:not([data-layout])")).toHaveCount(1); await expect(page.locator(".panes:not([data-layout])")).toHaveCount(1);
await page.keyboard.press(":"); await command(page, "/view auto");
await page.keyboard.type("/view auto");
await page.keyboard.press("Enter");
await at(page, "Fixed points", 1); await at(page, "Fixed points", 1);
// Keys: Alt+h to where the pane was opened from, Alt+l back; l on a row opens it and goes there. // Keys: Alt+h to where the pane was opened from, Alt+l back; l on a row opens it and goes there.
await page.keyboard.press("Alt+h"); await page.keyboard.press("Alt+h");
-1
View File
@@ -6,7 +6,6 @@
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { command, idle, jump, keys, openPage, settle, state } from "./helpers"; import { command, idle, jump, keys, openPage, settle, state } from "./helpers";
async function open(page: Page) { async function open(page: Page) {
// Record what would open in a new tab instead of opening it. // Record what would open in a new tab instead of opening it.
await page.addInitScript(() => { await page.addInitScript(() => {
+13 -33
View File
@@ -7,20 +7,9 @@
* calculus, …) and the hashed-words embedder (IE_EMBED=fake). * calculus, …) and the hashed-words embedder (IE_EMBED=fake).
*/ */
import { expect, test, type Page } from "@playwright/test"; 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); 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[]); 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 = "/") { async function column(page: Page, path = "/") {
@@ -30,9 +19,6 @@ async function column(page: Page, path = "/") {
await page.evaluate(() => document.fonts.ready); 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.describe.configure({ mode: "serial" });
test.beforeEach(async ({ context }) => { 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. // 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"); expect(await state(page, (s) => s.settings.autolink)).toBe("review");
await command(page, "/autolink on"); 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 idle(page);
await expect(page.locator("article .lnk")).toHaveCount(3); await expect(page.locator("article .lnk")).toHaveCount(3);
expect(await linksHere(page)).toEqual({ cephalopod: "Cephalopod", "Fred Hoyle": "Fred Hoyle", "lambda calculus": "Lambda calculus" }); 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 }) => { 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 column(page);
await command(page, "/autolink suggest"); 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 idle(page);
await expect(page.locator("article .sugg")).toHaveCount(5); await expect(page.locator("article .sugg")).toHaveCount(5);
await expect(page.locator("article .lnk")).toHaveCount(0); 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 }) => { test("typing [[ in the editor completes from library titles first, then Wikipedia; the choice is linked on save", async ({ page }) => {
await column(page); await column(page);
await newDoc(page, "Completer", "A start."); await addTop(page, "Completer", "A start.");
await idle(page); await idle(page);
await keys(page, "c End"); await keys(page, "c End");
await page.keyboard.type(" See [[Recursion with"); 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 }) => { 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 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); await idle(page);
expect(await body(page)).toBe("The Hoyle state and a thing nobody wrote about."); expect(await body(page)).toBe("The Hoyle state and a thing nobody wrote about.");
expect(await linksHere(page)).toEqual({ "Hoyle state": "Hoyle state" }); 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 }) => { test("text a model writes arrives without its marks, and the ones that check out are links", async ({ page }) => {
await column(page); await column(page);
await command(page, "/autolink on"); 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); await idle(page);
// e on a node with text and no sections asks the model for sections; the mock marks a few phrases. // e on a node with text and no sections asks the model for sections; the mock marks a few phrases.
await keys(page, "e"); 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 }) => { 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 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 idle(page);
await expect(page.locator(".related-list li").first()).toBeVisible(); await expect(page.locator(".related-list li").first()).toBeVisible();
const first = await page.locator(".related-list li .bl-title").first().textContent(); 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 }) => { test("/autolink off looks for nothing, suggest only suggests, on links", async ({ page }) => {
await column(page); await column(page);
await command(page, "/autolink off"); await command(page, "/autolink off");
await newDoc(page, "Modes", "The cephalopod."); await addTop(page, "Modes", "The cephalopod.");
await idle(page); await idle(page);
await expect(page.locator("article .sugg")).toHaveCount(0); await expect(page.locator("article .sugg")).toHaveCount(0);
await expect(page.locator("article .lnk")).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 autoLayout(page);
await page.goto("/"); await page.goto("/");
await page.waitForFunction(() => (globalThis as any).__ie?.ready); 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); await idle(page);
expect(await linksHere(page)).toEqual({ "Hoyle state": "Hoyle state" }); 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. // 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 }) => { test("keypress → paint stays within a frame while suggestions are on screen and scans run after edits", async ({ page }) => {
await column(page); await column(page);
await command(page, "/autolink suggest"); 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 idle(page);
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0)); 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++) { 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. // 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 page.keyboard.type(` More ${round}.`);
await paced("Escape"); await paced(page, "Escape");
} }
await idle(page); 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); 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);
+5 -19
View File
@@ -11,21 +11,10 @@
* IE_SHOTS=<dir> also saves the links list with each filter, light and dark, into that directory. * IE_SHOTS=<dir> also saves the links list with each filter, light and dark, into that directory.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { addTop, command, idle, keys, selected, settle, state, visit } from "./helpers"; import { addTop, command, idle, keys, linksHere, selected, settle, state, visit } from "./helpers";
const SHOTS = process.env.IE_SHOTS; const SHOTS = process.env.IE_SHOTS;
/** The links on the focused node: quote → target title. */
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 nolink = (page: Page) => state(page, (s) => (s.snap.nodes[s.focus.node].nolink ?? []) as string[]); const nolink = (page: Page) => state(page, (s) => (s.snap.nodes[s.focus.node].nolink ?? []) as string[]);
const panel = (page: Page) => page.locator("[data-links-panel]"); const panel = (page: Page) => page.locator("[data-links-panel]");
const count = (page: Page, status: string) => panel(page).locator(`.lfilter[data-filter=${status}] .n`); const count = (page: Page, status: string) => panel(page).locator(`.lfilter[data-filter=${status}] .n`);
@@ -38,9 +27,6 @@ async function column(page: Page) {
await page.evaluate(() => document.fonts.ready); 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.describe.configure({ mode: "serial" });
test.beforeEach(async ({ context }) => { test.beforeEach(async ({ context }) => {
@@ -54,7 +40,7 @@ test.afterEach(async ({ page }) => {
test("review mode: the approved links are made as one commit by the reviewer, the rejected wait behind a filter with the reason, and u undoes", async ({ page }) => { test("review mode: the approved links are made as one commit by the reviewer, the rejected wait behind a filter with the reason, and u undoes", async ({ page }) => {
await column(page); await column(page);
expect(await state(page, (s) => s.settings.autolink)).toBe("review"); expect(await state(page, (s) => s.settings.autolink)).toBe("review");
await newDoc(page, "Reviewed links", "The cephalopod met Fred Hoyle, who taught it the lambda calculus."); await addTop(page, "Reviewed links", "The cephalopod met Fred Hoyle, who taught it the lambda calculus.");
await idle(page); await idle(page);
expect(await linksHere(page)).toEqual({ "Fred Hoyle": "Fred Hoyle", "lambda calculus": "Lambda calculus" }); expect(await linksHere(page)).toEqual({ "Fred Hoyle": "Fred Hoyle", "lambda calculus": "Lambda calculus" });
const top = await state(page, (s) => s.commits()[0]); const top = await state(page, (s) => s.commits()[0]);
@@ -94,7 +80,7 @@ test("review mode: the approved links are made as one commit by the reviewer, th
test("in the list a person reverses the reviewer either way: links one it rejected, removes one it linked for good", async ({ page }) => { test("in the list a person reverses the reviewer either way: links one it rejected, removes one it linked for good", async ({ page }) => {
await column(page); await column(page);
await newDoc(page, "Reversed links", "The cephalopod met Fred Hoyle, who taught it the lambda calculus."); await addTop(page, "Reversed links", "The cephalopod met Fred Hoyle, who taught it the lambda calculus.");
await idle(page); await idle(page);
await keys(page, "S 2"); await keys(page, "S 2");
// Select the rejected row with a click: its words are selected in the text. // Select the rejected row with a click: its words are selected in the text.
@@ -125,7 +111,7 @@ test("in the list a person reverses the reviewer either way: links one it reject
test("a link removed in the text, by D or by the right-click menu, is declined and not made again on a rescan", async ({ page }) => { test("a link removed in the text, by D or by the right-click menu, is declined and not made again on a rescan", async ({ page }) => {
await column(page); await column(page);
await newDoc(page, "Removed links", "Fred Hoyle wrote about the lambda calculus and the Hoyle state."); await addTop(page, "Removed links", "Fred Hoyle wrote about the lambda calculus and the Hoyle state.");
await idle(page); await idle(page);
expect(Object.keys(await linksHere(page)).sort()).toEqual(["Fred Hoyle", "Hoyle state", "lambda calculus"]); expect(Object.keys(await linksHere(page)).sort()).toEqual(["Fred Hoyle", "Hoyle state", "lambda calculus"]);
// By key: Tab to the first link, D. // By key: Tab to the first link, D.
@@ -160,7 +146,7 @@ test("a link removed in the text, by D or by the right-click menu, is declined a
test("when the model fails, nothing is linked unreviewed: everything is suggested, and the status line says so", async ({ page }) => { test("when the model fails, nothing is linked unreviewed: everything is suggested, and the status line says so", async ({ page }) => {
await column(page); await column(page);
await newDoc(page, "Failed review", "Fred Hoyle left mockfail notes on the lambda calculus."); await addTop(page, "Failed review", "Fred Hoyle left mockfail notes on the lambda calculus.");
await idle(page); await idle(page);
await expect(page.locator("article .lnk")).toHaveCount(0); await expect(page.locator("article .lnk")).toHaveCount(0);
await expect(page.locator("article .sugg")).toHaveCount(2); await expect(page.locator("article .sugg")).toHaveCount(2);
+1 -8
View File
@@ -6,16 +6,9 @@
* store call to the painted frame. Runs last: it fills the shared library. * store call to the painted frame. Runs last: it fills the shared library.
*/ */
import { expect, test, type Page } from "@playwright/test"; import { expect, test, type Page } from "@playwright/test";
import { autoLayout, idle, state, synced, writeReport, type Sample, visit } from "./helpers"; import { autoLayout, idle, paced, state, synced, type Sample, visit, writeReport } from "./helpers";
const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready === true, undefined, { timeout: 30_000 }); const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready === true, undefined, { timeout: 30_000 });
/** One keystroke per frame, as in the other latency tests. */
const paced = async (page: Page, seq: string) => {
for (const k of seq.split(" ")) {
await page.keyboard.press(k);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
}
};
const SENTENCE = "This sentence is about something that matters here. Another follows it, with a few more words. "; const SENTENCE = "This sentence is about something that matters here. Another follows it, with a few more words. ";
/** Edit a leaf's body through the store, and time it to the painted frame. */ /** Edit a leaf's body through the store, and time it to the painted frame. */
+1 -4
View File
@@ -6,6 +6,7 @@ import { HUES, all, besideInColumn, close, columns, find, focus, focused, load,
type F = Forest<string>; type F = Forest<string>;
type T = Tree<string>; type T = Tree<string>;
const same = (a: string, b: string) => a === b; const same = (a: string, b: string) => a === b;
const isStr = (r: unknown): r is string => typeof r === "string";
const branch = (f: F) => path(focused(f)).map((n) => n.ref); const branch = (f: F) => path(focused(f)).map((n) => n.ref);
/** A tree drawn as nested lists, the picked child starred, a pinned pane marked with a leading ^. */ /** A tree drawn as nested lists, the picked child starred, a pinned pane marked with a leading ^. */
const shape = (t: T | null): unknown => { const shape = (t: T | null): unknown => {
@@ -140,7 +141,6 @@ describe("forks", () => {
expect(col2(f)).toEqual(["b2", "b1", "c1", "c2"]); expect(col2(f)).toEqual(["b2", "b1", "c1", "c2"]);
f = open(focus(f, idOf(f, "b1")), 1, "bx", false, same); f = open(focus(f, idOf(f, "b1")), 1, "bx", false, same);
expect(col2(f)).toEqual(["b2", "bx", "c1", "c2"]); expect(col2(f)).toEqual(["b2", "bx", "c1", "c2"]);
const isStr = (r: unknown): r is string => typeof r === "string";
const back = restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at })), isStr); const back = restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at })), isStr);
expect(col2(back)).toEqual(["b2", "bx", "c1", "c2"]); expect(col2(back)).toEqual(["b2", "bx", "c1", "c2"]);
}); });
@@ -179,7 +179,6 @@ describe("forks", () => {
f = open(f, 0, "x", true, same); f = open(f, 0, "x", true, same);
f = pin(f, idOf(f, "c"), true); f = pin(f, idOf(f, "c"), true);
f = close(f, idOf(f, "b"), idOf(f, "x")).forest; f = close(f, idOf(f, "b"), idOf(f, "x")).forest;
const isStr = (r: unknown): r is string => typeof r === "string";
const stored = JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at })); const stored = JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at }));
const back = restore<string, unknown>(stored, isStr); const back = restore<string, unknown>(stored, isStr);
expect(shapes(back)).toEqual(shapes(f)); expect(shapes(back)).toEqual(shapes(f));
@@ -272,7 +271,6 @@ describe("forks", () => {
}); });
describe("branch colours", () => { describe("branch colours", () => {
const isStr = (r: unknown): r is string => typeof r === "string";
/** Each pane's colour by its ref, "-" for none. */ /** Each pane's colour by its ref, "-" for none. */
const hues = (f: F) => Object.fromEntries(all(f).map((x) => [x.node.ref, x.node.hue ?? "-"])); const hues = (f: F) => Object.fromEntries(all(f).map((x) => [x.node.ref, x.node.hue ?? "-"]));
const roundTrip = (f: F) => restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at, hues: f.hues ?? 0 })), isStr); const roundTrip = (f: F) => restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at, hues: f.hues ?? 0 })), isStr);
@@ -392,7 +390,6 @@ describe("column order", () => {
f = setSources(f, new Map([[idOf(f, "o1"), 5], [idOf(f, "e2"), 90], [idOf(f, "e1"), 20]])); f = setSources(f, new Map([[idOf(f, "o1"), 5], [idOf(f, "e2"), 90], [idOf(f, "e1"), 20]]));
expect(col(f, 2)).toEqual(["e1", "e2", "o1"]); expect(col(f, 2)).toEqual(["e1", "e2", "o1"]);
// Stored with the view. // Stored with the view.
const isStr = (r: unknown): r is string => typeof r === "string";
const back = restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at, hues: f.hues })), isStr); const back = restore<string, unknown>(JSON.parse(JSON.stringify({ forest: f.trees.map((t) => save(t, (r) => r)), at: f.at, hues: f.hues })), isStr);
expect(col(back, 2)).toEqual(["e1", "e2", "o1"]); expect(col(back, 2)).toEqual(["e1", "e2", "o1"]);
}); });