Browser tests: nodes instead of documents; addresses by node id; /linkhere and /linkall

menu.spec.ts becomes nodes.spec.ts: standing on the library root, /n/<id> addresses through a
reload, Back and Forward (and an old /doc/ address), the jump box, a file imported into a node two
levels down with a link relative to its top, exported back the same and copied just after itself,
Move under… by key and by the menu (never under itself; the root offered first), history's f and r
on the node the reader is on, the offline round trip, the node routes over HTTP, and panes and
phone width.

The other specs open a tree by its titles (helpers openAt, openPage, visit: /n/<id>, hoisted in the
column as /doc/ was), make top-level sections from the library page instead of /new, scan with
/linkhere (and check its scope against /linkall's), and expect a section's head on every pane but
the first.

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 01:49:22 -05:00
1 parent bed47c0c7a
commit c4d6856649
17 files changed
+584 -490

No files matched your search

+10 -10
View File
@@ -5,14 +5,14 @@
* again in a later revision, or listed as detached when its words are gone.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, seedLinks, selected, settle, state } from "./helpers";
import { autoLayout, command, idle, jump, keys, seedLinks, selected, settle, state, visit } from "./helpers";
const panes = (page: Page) => page.locator(".strip .pane");
async function wide(page: Page, path = "/doc/fixed-points") {
async function wide(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await page.goto(path);
await visit(page, path);
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
@@ -20,7 +20,7 @@ async function column(page: Page, path: string) {
await page.setViewportSize({ width: 1440, height: 900 });
// After wide(), this page's layout follows the window, and 1440 px is wide enough for panes.
if (page.url().startsWith("http")) await page.evaluate(() => localStorage.setItem("ie:settings", JSON.stringify({ ...JSON.parse(localStorage.getItem("ie:settings") ?? "{}"), view: "column" })));
await page.goto(path);
await visit(page, path);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
}
async function tabTo(page: Page, words: string) {
@@ -46,7 +46,7 @@ test.afterEach(({ page }) => settle(page));
test("words of an article are selected with the node keys, and a lens writes a note on them that the library keeps", async ({ page }) => {
await wide(page);
const docs = await state(page, (s) => s.menuItems("").length);
const docs = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c]).length);
await jump(page, "Recursion without names");
await tabTo(page, "fixed-point combinator");
await keys(page, "Enter");
@@ -80,9 +80,9 @@ test("words of an article are selected with the node keys, and a lens writes a n
await expect(art.locator(".wiki-text .gloss")).toContainText("mock gloss of Haskell Curry");
await expect(art.locator(".wiki-text .anchor.a-gloss")).toHaveText("Haskell Curry");
expect((await annotations(page)).sort()).toEqual([`Haskell Curry | mock gloss of Haskell Curry`, `${sentence} | Mock note on “${sentence!.slice(0, 47)}…” through the why lens. It is two sentences long.`].sort());
// The article's node is in the library's Wikipedia container, which is not a document.
expect(await state(page, (s) => s.menuItems("").length)).toBe(docs);
expect(await state(page, (s) => s.menuItems("").some((d: any) => d.title === "Wikipedia"))).toBe(false);
// The article's node is in the library's Wikipedia container, which is not one of the root's sections.
expect(await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c]).length)).toBe(docs);
expect(await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c]).some((d: any) => d.title === "Wikipedia"))).toBe(false);
// Keys that only make sense on a node say why not.
await keys(page, "Escape Escape");
await keys(page, "c");
@@ -150,9 +150,9 @@ test("an article's annotations show wherever it is opened: from another link, fr
await keys(page, "x");
await idle(page);
await expect(under.locator(".wiki-text .inset")).toContainText("through the example lens");
// From another document's link to it.
// From a link to it in another tree.
await settle(page);
await wide(page, "/doc/what-a-proof-is");
await wide(page, "What a proof is");
await jump(page, "Proofs as programs");
await tabTo(page, "a function turning proofs");
await keys(page, "Enter");
+8 -6
View File
@@ -98,7 +98,7 @@ const near = (a: number, b: number, d = 1) => Math.abs(a - b) <= d;
/** Two colours alike, but for rounding (a colour at part strength, un-premultiplied, may differ by a unit or two). */
const alike = (a: number[] | null, b: number[] | null) => !!a && !!b && a.every((v, i) => Math.abs(v - b[i]) <= 3);
test("every kind of pane's title rule is drawn by the curve into it, in the pane's colour: pages, sections, 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);
for (const t of ["The tides", "Fixed points"]) await open(page, "Library", t);
const seen = new Set<string>();
@@ -127,7 +127,9 @@ test("every kind of pane's title rule is drawn by the curve into it, in the pane
await expect(page.locator(".wiki-pane .wiki-head .wsub")).toHaveCount(1);
await still(page);
await check();
expect([...seen].sort(), JSON.stringify((await lines(page)).map((l) => [l.kind, l.ruled, l.cls, l.folded, l.scrolled]))).toEqual(["article", "article section", "page", "section"]);
expect([...seen].sort(), JSON.stringify((await lines(page)).map((l) => [l.kind, l.ruled, l.cls, l.folded, l.scrolled]))).toEqual(["article", "article section", "section"]);
// A top-level node's pane is headed like any other: only the first pane is a page.
expect(await page.locator(".strip .pane:not(.root) > .pane-scroll > .pane-body > .top").count()).toBe(0);
// The two forks out of the library are two colours; the top node has none.
expect(await pane(page, "Library").getAttribute("data-hue")).toBeNull();
expect(await pane(page, "The tides").getAttribute("data-hue")).not.toBe(await pane(page, "Fixed points").getAttribute("data-hue"));
@@ -185,8 +187,8 @@ test("the join of a curve and the rule it runs into is one stroke, on device pix
await library(page);
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t);
await open(page, "The tides", "The force");
// The focus to the last document, so The tides folds to its tab with its source out of sight.
await pane(page, "Fixed points").locator(".top h1").dispatchEvent("click");
// 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 still(page);
const ls = await lines(page);
const shot = pixels(await page.screenshot());
@@ -231,7 +233,7 @@ test("a pane folded or scrolled past its title shows its tab, and its curve land
await library(page);
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t);
await open(page, "The tides", "The force");
await pane(page, "Fixed points").locator(".top h1").dispatchEvent("click");
await pane(page, "Fixed points").locator(".pane-head h2").dispatchEvent("click");
await still(page);
let ls = await lines(page);
let checked = 0;
@@ -242,7 +244,7 @@ test("a pane folded or scrolled past its title shows its tab, and its curve land
if (!l || l.cls.includes("lost") || l.focused) continue;
checked++;
const visible = await pane(page, t).evaluate((p) => {
const h = p.querySelector<HTMLElement>(".top h1")!.getBoundingClientRect();
const h = p.querySelector<HTMLElement>(".pane-head, .top h1")!.getBoundingClientRect();
const r = p.getBoundingClientRect();
const next = (p.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity;
const covered = p.hasAttribute("data-covered") || p.hasAttribute("data-scrolled");
+8 -8
View File
@@ -8,7 +8,7 @@
* the documents are hoisted to (z) as in panes.spec.ts.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state } from "./helpers";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state, visit } from "./helpers";
/** The first tree of panes by title, the picked child starred: [title, [children]] or a leaf's title. */
const tree = (page: Page) =>
@@ -73,7 +73,7 @@ async function still(page: Page) {
}
async function open(page: Page) {
await page.goto("/doc/infinispand");
await visit(page, "Infinispand");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await expect(page.locator(".strip .pane")).toHaveCount(2);
@@ -92,7 +92,7 @@ async function tabTo(page: Page, words: string) {
/** The owner's screenshot: Two kinds of cell, with Eukaryote (opened from its link), Simple cells and Complex cells beside each other in the next column, and Bacteria opened from Eukaryote's text. */
async function cells(page: Page) {
await page.goto("/doc/the-one-merger");
await visit(page, "The one merger");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Two kinds of cell");
@@ -184,7 +184,7 @@ test("a click, a Ctrl- and a middle click open beside; a Shift-click in place; a
});
test("a link and an article's link open beside by default, in place with Shift; twenty opens stay usable", async ({ page }) => {
await page.goto("/doc/fixed-points");
await visit(page, "Fixed points");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Recursion without names");
@@ -659,7 +659,7 @@ test("× and q close the pane they are on, whatever it shows, with what was open
await pane(page, "Bacteria").locator(".pane-ctl .pane-btn.close").click();
expect(await columns(page)).toEqual([["Library"], ["The one merger"], ["Two kinds of cell"], ["Complex cells"]]);
// A note that also links, opened as a pane of its own: q closes it, back to its words.
await page.goto("/doc/octopus-minds");
await visit(page, "Octopus minds");
await page.waitForSelector(".strip .pane");
await jump(page, "The common ancestor");
await keys(page, "l");
@@ -672,7 +672,7 @@ test("× and q close the pane they are on, whatever it shows, with what was open
});
test("q on an article opened from an article in a fork closes that article only (the owner's bug)", async ({ page }) => {
await page.goto("/doc/fixed-points");
await visit(page, "Fixed points");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Recursion without names");
@@ -692,7 +692,7 @@ test("q on an article opened from an article in a fork closes that article only
});
test("from a Wikipedia link, a node link and a link inside an article: forks, each marked where it was opened", async ({ page }) => {
await page.goto("/doc/fixed-points");
await visit(page, "Fixed points");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Recursion without names");
@@ -777,7 +777,7 @@ test("many forks: a reload brings the forest back", async ({ page }) => {
test("in the column a Shift open is a plain open, and the status line says why once", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto("/doc/fixed-points");
await visit(page, "Fixed points");
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await command(page, "/view column");
await jump(page, "Recursion without names");
+57 -3
View File
@@ -1,8 +1,9 @@
/**
* What the browser tests share: driving the page from the keyboard, reading the store the page
* exposes as globalThis.__ie, waiting for it to settle, and the links written into the shared
* library over the op API, as an outside agent would (every kind of target, a note that also links,
* a cross-document node link, two documents mentioning one article, a link and a note on the same
* exposes as globalThis.__ie, waiting for it to settle, going to a node's address by its titles, and
* the links written into the shared library over the op API, as an outside agent would (every kind
* of target, a note that also links, a node link from one top-level tree into another, two trees
* mentioning one article, a link and a note on the same
* words, links on the screenshot's cells; the articles are the mock
* Wikipedia's fixtures in server/wikiMock.ts).
*/
@@ -35,6 +36,59 @@ export const keys = async (page: Page, seq: string) => {
for (const k of seq.split(" ")) await page.keyboard.press(k);
};
/** The id of the section at these titles from the library root, asked of the server as an outside agent would (none: the root). */
export async function nodeAt(page: Page, ...path: string[]): Promise<string> {
const s: Snap = await (await page.request.get("/api/tree")).json();
return find(s, ...path);
}
/** Go to the address of the section at these titles from the library root (none: the library, `/`), and wait for the page. */
export async function openAt(page: Page, ...path: string[]) {
await page.goto(path.length ? `/n/${encodeURIComponent(await nodeAt(page, ...path))}` : "/");
await page.waitForSelector("article");
}
/** In the column, make the focused node the page, as z does (without a key, which would end a first visit's hint); in panes, nothing. */
const hoistHere = (page: Page) => state(page, (s) => void (!s.panes && s.setHoist(s.focus.node)));
/**
* The section at these titles as the page: in the column hoisted to it (as z does), with the
* library one step out; in panes, in its own pane beside the library's. What `/doc/<name>` used to open.
*/
export async function openPage(page: Page, ...path: string[]) {
await openAt(page, ...path);
await hoistHere(page);
}
/**
* Go somewhere: an address as it is (`/`, `/w/en/Octopus`), or a top-level section by its title,
* opened as the page (openPage). Does not wait for the page.
*/
export async function visit(page: Page, where: string) {
if (where.startsWith("/")) return void (await page.goto(where));
await page.goto(`/n/${encodeURIComponent(await nodeAt(page, where))}`);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await hoistHere(page);
}
/**
* A new top-level section with this text, typed from the keyboard on the library page (`a` on the
* root, its title, then `c` and its text); it is the page afterwards (hoisted, in the column) and
* has the focus.
*/
export async function addTop(page: Page, title: string, text: string) {
await page.goto("/");
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await page.keyboard.press("a");
await page.keyboard.type(title);
await page.keyboard.press("Enter");
if (!(await state(page, (s) => s.panes))) await page.keyboard.press("z");
await page.locator(".title, h1, h2", { hasText: title }).first().waitFor();
await page.keyboard.press("c");
await page.keyboard.type(text);
await page.keyboard.press("Escape");
}
/** / then a title then Enter: jump to a section. */
export const jump = async (page: Page, title: string) => {
await page.keyboard.press("/");
+8 -9
View File
@@ -4,7 +4,7 @@
* Latencies are measured in the page (keydown timestamp → the frame after the render).
*/
import { expect, test, type Page } from "@playwright/test";
import { command, focusedTitle, idle, jump, keys, settle, state, writeReport, type Sample } from "./helpers";
import { command, focusedTitle, idle, jump, keys, openPage, settle, state, writeReport, type Sample } from "./helpers";
const titlesUnder = (page: Page, title: string) =>
page.evaluate((t) => {
@@ -13,10 +13,9 @@ const titlesUnder = (page: Page, title: string) =>
return n.children.map((c: string) => s.snap.nodes[c]).filter((c: any) => c.kind === "section").map((c: any) => c.title) as string[];
}, title);
/** The first document, opened in the column (hoisted, with the library one step out). */
/** The first tree, opened in the column (hoisted, with the library one step out). */
async function open(page: Page) {
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
await openPage(page, "Infinispand");
await page.evaluate(() => document.fonts.ready);
}
@@ -205,8 +204,8 @@ test("history: every commit verifies, any commit can be viewed, and a revert is
await expect(page.locator(".verdict")).toContainText(/Verified: all \d+ hashed commits reproduce byte-for-byte/);
const total = await state(page, (s) => s.commits().length);
expect(total).toBeGreaterThan(11);
// Walk down to the oldest commits (the library's creation, then the first document's) and look
// at the document as it was when only three sections had been written.
// Walk down to the oldest commits (the library's creation, then the first tree's) and look
// at the tree as it was when only three sections had been written.
for (let i = 0; i < total + 5; i++) await page.keyboard.press("j");
await keys(page, "k k k k Enter");
await expect(page.locator(".banner")).toContainText("Read-only");
@@ -215,15 +214,15 @@ test("history: every commit verifies, any commit can be viewed, and a revert is
await keys(page, "a");
await expect(page.locator(".status .message")).toContainText("read-only");
await expect(page.locator(".title-editor")).toHaveCount(0);
// Revert to it: the document goes back, the rest of the library stays, and the revert is itself
// Revert to it: the node the reader is on (the tree's top) goes back, the rest of the library stays, and the revert is itself
// a commit that can be undone.
const others = await state(page, (s) => s.doc.snap().nodes[s.doc.snap().root].children.filter((c: string) => c !== s.currentDoc).map((c: string) => s.doc.shape(undefined, c)).join());
const others = await state(page, (s) => s.doc.snap().nodes[s.doc.snap().root].children.filter((c: string) => c !== s.activeNode).map((c: string) => s.doc.shape(undefined, c)).join());
expect(others).not.toBe("");
await keys(page, "r");
await expect(page.locator(".banner")).toHaveCount(0);
await expect(page.locator("article > .outline > .node")).toHaveCount(3);
expect(await state(page, (s) => s.commits()[0].tag)).toBe("revert");
expect(await state(page, (s) => s.doc.snap().nodes[s.doc.snap().root].children.filter((c: string) => c !== s.currentDoc).map((c: string) => s.doc.shape(undefined, c)).join())).toBe(others);
expect(await state(page, (s) => s.doc.snap().nodes[s.doc.snap().root].children.filter((c: string) => c !== s.activeNode).map((c: string) => s.doc.shape(undefined, c)).join())).toBe(others);
await keys(page, "v");
await expect(page.locator(".verdict")).toContainText("Verified");
await keys(page, "Escape u");
+23 -20
View File
@@ -5,7 +5,7 @@
* the address it would have gone to.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state, writeReport, type Sample } from "./helpers";
import { autoLayout, command, focusedTitle, jump, keys, seedLinks, selected, settle, state, visit, writeReport, type Sample } from "./helpers";
/** The panes' titles, left to right: a node's title, or W:article for a Wikipedia pane. */
const trail = (page: Page) =>
@@ -21,18 +21,18 @@ async function tabTo(page: Page, words: string) {
throw new Error(`Tab never reached “${words}”`);
}
async function column(page: Page, path = "/doc/fixed-points") {
async function column(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1440, height: 900 });
// After wide(), this page's layout follows the window, and 1440 px is wide enough for panes.
if (page.url().startsWith("http")) await page.evaluate(() => localStorage.setItem("ie:settings", JSON.stringify({ ...JSON.parse(localStorage.getItem("ie:settings") ?? "{}"), view: "column" })));
await page.goto(path);
await visit(page, path);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await page.evaluate(() => document.fonts.ready);
}
async function wide(page: Page, path = "/doc/fixed-points") {
async function wide(page: Page, path = "Fixed points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await page.goto(path);
await visit(page, path);
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
@@ -182,7 +182,7 @@ test("panes: Tab and Enter open an article in the next pane; its sections open a
});
test("a note that also links opens as one pane: its text above, the article in full beneath", async ({ page }) => {
await wide(page, "/doc/where-the-elements-come-from");
await wide(page, "Where the elements come from");
await inPane(page, "The triple-alpha process", "an excited state at almost exactly the energy");
await keys(page, "Enter");
const pane = panes(page).last();
@@ -221,14 +221,14 @@ test("a note that also links, clicked or entered, opens its article with the not
const words = "an excited state at almost exactly the energy";
const note = "It is called the Hoyle state";
// Panes, by click.
await wide(page, "/doc/where-the-elements-come-from");
await wide(page, "Where the elements come from");
await jump(page, "The triple-alpha process");
await keys(page, "l");
await panes(page).last().locator(".anchor", { hasText: words }).click();
await expect(panes(page).last()).toHaveClass(/note-pane/);
await expectCommentary(page, note, "Hoyle state", "excited, spin-0 resonant state");
// The column, by keyboard: Enter on the words opens the note as a page; h returns to the words.
await column(page, "/doc/where-the-elements-come-from");
await column(page, "Where the elements come from");
await jump(page, "The triple-alpha process");
await keys(page, "Enter i");
await tabTo(page, words);
@@ -251,11 +251,11 @@ test("a note that also links, clicked or entered, opens its article with the not
test("a note and a link on the same words open as that one page: the note on top, the linked article beneath", async ({ page }) => {
const words = "The camera-like eye";
const note = "The octopus eye has a lens";
await wide(page, "/doc/octopus-minds");
await wide(page, "Octopus minds");
await inPane(page, "The common ancestor", words);
await keys(page, "Enter");
await expectCommentary(page, note, "Cephalopod", "molluscan class Cephalopoda");
await column(page, "/doc/octopus-minds");
await column(page, "Octopus minds");
await jump(page, "The common ancestor");
await keys(page, "l");
await page.locator(".anchor", { hasText: words }).click();
@@ -264,8 +264,8 @@ test("a note and a link on the same words open as that one page: the note on top
expect(await selected(page)).toBe(words);
});
test("a link to a node in another document opens it, and Back returns; in panes it opens next and h returns", async ({ page }) => {
await column(page, "/doc/what-a-proof-is");
test("a link to a node in another tree opens it, and Back returns; in panes it opens next and h returns", async ({ page }) => {
await column(page, "What a proof is");
await jump(page, "Proofs as programs");
await keys(page, "Enter i");
await tabTo(page, "Several of the leading systems");
@@ -275,20 +275,23 @@ test("a link to a node in another document opens it, and Back returns; in panes
await expect(preview).toContainText("Recursion without names");
await keys(page, "Enter");
await expect.poll(() => focusedTitle(page)).toBe("Recursion without names");
await expect(page).toHaveURL(/\/doc\/fixed-points\//);
const recursion = await state(page, (s) => s.focus.node);
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(recursion)}$`));
await page.goBack();
await expect.poll(() => focusedTitle(page)).toBe("Proofs as programs");
// Panes: the node opens in the next pane, marked with its document; h comes back to the words.
await wide(page, "/doc/what-a-proof-is");
// Panes: the node opens in the next pane, marked with the titles above it; h comes back to the words.
await wide(page, "What a proof is");
await inPane(page, "Proofs as programs", "Several of the leading systems");
await keys(page, "Enter");
const last = panes(page).last();
await expect(last).toHaveClass(/jumped/);
await expect(last.locator(".pane-from")).toHaveText("Fixed points");
await expect(last.locator(".pane-from")).toHaveText("Library › Fixed points");
await expect(last.locator(".pane-head h2")).toHaveText("Recursion without names");
await keys(page, "h");
expect(await selected(page)).toBe("Several of the leading systems");
await expect(panes(page)).toHaveCount(4);
// The library, What a proof is, Proof assistants, Proofs as programs, and the node opened beside it
// (following the link out of the hoisted tree in the column un-hoisted the page to the library).
await expect(panes(page)).toHaveCount(5);
});
test("Linked from and Mentioned in list what links here, reachable by j and Enter", async ({ page }) => {
@@ -323,7 +326,7 @@ test("Linked from and Mentioned in list what links here, reachable by j and Ente
});
test("linking by hand: the picker links to the library, to Wikipedia and to an address; it retargets; /unlink and D remove", async ({ page }) => {
await column(page, "/doc/the-tides");
await column(page, "The tides");
await jump(page, "The tides");
const doc = await state(page, (s) => s.focus.node);
const linkCount = () => page.evaluate((d) => {
@@ -385,7 +388,7 @@ test("linking by hand: the picker links to the library, to Wikipedia and to an a
});
test("a disambiguation page lists its senses as rows; a missing article, an unreachable Wikipedia and a slow one say so plainly", async ({ page }) => {
await wide(page, "/doc/the-tides");
await wide(page, "The tides");
await jump(page, "The tides");
await keys(page, "i i");
await command(page, "/link w:Mercury");
@@ -474,7 +477,7 @@ test("a hostile article cannot run script or load anything from elsewhere, in a
let dialogs = 0;
page.on("dialog", (d) => (dialogs++, d.dismiss()));
for (const view of [wide, column]) {
await view(page, "/doc/the-tides");
await view(page, "The tides");
await jump(page, "The tides");
await keys(page, "i i");
await command(page, "/link w:Hostile article");
-352
View File
@@ -1,352 +0,0 @@
/**
* Documents in the library, from the keyboard: the menu (filter and open, create, rename,
* duplicate, delete, export and import), addresses that survive a reload and Back, a jump that
* crosses documents, and moving between documents without closing anything. These tests make
* their own documents and leave the first one alone: the other specs share it.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, settle, state, synced } from "./helpers";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { parseDoc } from "../src/core/format";
const FIXTURE = fileURLToPath(new URL("../tests/fixtures/menu-fixture.md", import.meta.url));
/** The titles in the document on screen. */
const titles = (page: Page) =>
state(page, (s) => {
const d = s.currentDoc;
const out: string[] = [];
const visit = (id: string) => (out.push(s.snap.nodes[id].title), s.snap.nodes[id].children.forEach(visit));
if (d) visit(d);
return out;
});
/** m, type to filter, Enter. */
const openByMenu = async (page: Page, filter: string) => {
await page.keyboard.press("m");
await expect(page.locator(".panel.docs .filter")).toBeFocused();
await page.keyboard.type(filter);
await page.keyboard.press("Enter");
};
/** m, then Esc to the list, where single keys act. */
const menuList = async (page: Page) => {
await page.keyboard.press("m");
await expect(page.locator(".panel.docs .filter")).toBeFocused();
await page.keyboard.press("Escape");
await expect(page.locator(".panel.docs .filter")).not.toBeFocused();
await expect.poll(() => state(page, (s) => `${s.mode}/${s.menu.focus}`)).toBe("docs/list");
};
async function open(page: Page, path = "/doc/infinispand") {
await page.goto(path);
await page.waitForSelector("article");
}
test.describe.configure({ mode: "serial" });
// Playwright turns on file-chooser interception only when something listens for it, and does so
// asynchronously: a waitForEvent("filechooser") made just before the key that opens the picker can
// lose that race, and then the picker opens unintercepted and no event ever comes (seen under load:
// the app had appended and clicked its file input). Listening from the start keeps it on throughout.
test.beforeEach(async ({ page }) => {
page.on("filechooser", () => {});
});
test.afterEach(({ page }) => settle(page));
test("the library is the first page: its documents are its sections, and opening one needs no closing step", async ({ page }) => {
await open(page, "/");
await expect(page.locator(".top h1")).toHaveText("Library");
const docs = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).length);
await expect(page.locator("article > .outline > .node")).toHaveCount(docs);
await expect(page.locator("article > .outline > .node.open")).toHaveCount(0);
await keys(page, "j Enter"); // the first document's row: it opens in place of the list
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await expect(page.locator(".crumbs")).toHaveText(/Library/);
await expect(page).toHaveURL(/\/doc\/infinispand$/);
await expect(page.locator(".docbar .doc-title .name")).toHaveText("Infinispand");
await keys(page, "h"); // stepping out of the document returns to the library, on its row
await expect(page.locator(".top h1")).toHaveText("Library");
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("Infinispand");
await keys(page, "j l"); // the next one
await expect(page.locator(".top h1")).toHaveText("A mind made of text");
// The library's own text is never stale and the library is not rewritten by anything.
expect(await state(page, (s) => s.snap.nodes[s.snap.root].seenUp)).toBe("");
});
test("m opens the menu, in library order, and the title in the top bar opens it too", async ({ page }) => {
await open(page);
await keys(page, "m");
const panel = page.locator(".panel.docs");
await expect(panel).toBeVisible();
await expect(panel.locator(".doc.current")).toContainText("Infinispand");
await expect(panel.locator(".doc.current")).toContainText(/open · (saved|saving…)/);
const listed = await panel.locator(".doc .title").allTextContents();
expect(listed).toEqual(await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c].title)));
await keys(page, "Escape Escape");
await expect(panel).toHaveCount(0);
await page.locator(".docbar .doc-title").click();
await expect(panel).toBeVisible();
await expect(page.locator(".docbar .save-state")).toHaveText("saved");
});
test("import a .md file, then export it and get the same document back", async ({ page }) => {
await open(page);
await menuList(page);
const chooser = page.waitForEvent("filechooser");
await keys(page, "i");
await (await chooser).setFiles(FIXTURE);
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
await expect(page).toHaveURL(/\/doc\/menu-fixture$/);
const shape = () => state(page, (s) => s.doc.shape(undefined, s.currentDoc));
const imported = await shape();
await menuList(page);
const download = page.waitForEvent("download");
await keys(page, "x");
const file = await (await download).path();
const text = readFileSync(file, "utf8");
expect(await (await download).suggestedFilename()).toBe("menu-fixture.md");
expect(parseDoc(text)).toEqual(parseDoc(readFileSync(FIXTURE, "utf8")));
// Importing the exported file gives a second document with the same shape.
await keys(page, "Escape");
const again = page.waitForEvent("filechooser");
await command(page, "/import");
await (await again).setFiles({ name: "menu-fixture.md", mimeType: "text/markdown", buffer: Buffer.from(text) });
// A second top with the same name is addressed by its id as well.
await expect(page).toHaveURL(/\/doc\/menu-fixture\/[^/]+$/);
expect(await shape()).toBe(imported);
expect(await state(page, (s) => [s.currentDoc, ...s.snap.nodes[s.currentDoc].children].filter((id: string) => s.snap.nodes[id].by !== "llm").length)).toBe(0);
// Both are on the server, as sections of the library.
await synced(page);
expect((await (await page.request.get("/api/docs")).json()).filter((d: any) => d.slug === "menu-fixture")).toHaveLength(2);
});
test("a file with a quote that is not in its text is refused, naming the section and the quote", async ({ page }) => {
await open(page);
const bad = readFileSync(FIXTURE, "utf8").replace('"a phrase worth a note"', '"words that are not there"');
await menuList(page);
const chooser = page.waitForEvent("filechooser");
await keys(page, "i");
await (await chooser).setFiles({ name: "broken.md", mimeType: "text/markdown", buffer: Buffer.from(bad) });
await expect(page.locator(".panel.docs .problems")).toContainText('broken.md:5: in “Menu fixture”: quote not found: "words that are not there"');
await expect(page.locator(".top h1")).toHaveText("Infinispand");
});
test("filter and open; the address names the document and the node, and survives a reload, Back and Forward", async ({ page }) => {
await open(page, "/");
await keys(page, "m");
await page.keyboard.type("menu fix");
await expect(page.locator(".panel.docs .doc")).toHaveCount(2);
await keys(page, "Escape j k Enter");
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
await expect(page.locator(".panel.docs")).toHaveCount(0);
await expect(page).toHaveTitle("Menu fixture");
await expect(page).toHaveURL(/\/doc\/menu-fixture$/);
// Into a section: the address follows the focus to the node.
await keys(page, "j");
const section = await state(page, (s) => s.focus.node);
await expect(page).toHaveURL(new RegExp(`/doc/menu-fixture/${encodeURIComponent(section)}$`));
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
expect(await state(page, (s) => s.focus.node)).toBe(section);
// A link to a document opens it; Back returns to the node; Back again to the library.
await open(page, "/doc/infinispand");
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await page.goBack();
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
await expect.poll(() => state(page, (s) => s.focus.node)).toBe(section);
await page.goForward();
await expect(page.locator(".top h1")).toHaveText("Infinispand");
// An address that names nothing says so and shows the library.
await open(page, "/doc/no-such-document");
await expect(page.locator(".top h1")).toHaveText("Library");
await expect(page.locator(".status .message")).toContainText("no-such-document");
});
test("the jump box searches every document, says which one each match is in, and goes there", async ({ page }) => {
await open(page);
await page.keyboard.press("/");
await page.keyboard.type("amphidromes");
const hit = page.locator(".jump li").first();
await expect(hit.locator(".t")).toHaveText("Amphidromes");
await expect(hit.locator(".in")).toHaveText("The tides");
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("The tides");
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("Amphidromes");
await expect(page).toHaveURL(/\/doc\/the-tides\/\d+%40\d+$/);
// Back to where the jump started.
await page.goBack();
await expect(page.locator(".top h1")).toHaveText("Infinispand");
// A document's own title opens it.
await jump(page, "Fixed points");
await expect(page.locator(".top h1")).toHaveText("Fixed points");
});
test("the library opens from this browser without the network, and catches up when it returns", async ({ page }) => {
await open(page, "/doc/menu-fixture");
await synced(page);
await page.route("**/api/**", (route) => route.abort());
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
await command(page, "/open tides");
await expect(page.locator(".top h1")).toHaveText("The tides");
await keys(page, "j r");
await page.keyboard.press("Control+a");
await page.keyboard.type("Renamed offline");
await page.keyboard.press("Enter");
await expect(page.locator(".docbar .save-state")).toHaveText(/offline|saving/);
await page.waitForTimeout(300); // the replica reaches IndexedDB a moment after the edit
await page.unroute("**/api/**");
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".docbar .save-state")).toHaveText("saved", { timeout: 15_000 });
expect(JSON.stringify(await (await page.request.get("/api/docs/the-tides/tree")).json())).toContain("Renamed offline");
});
test("create, rename and duplicate from the menu", async ({ page }) => {
await open(page);
await menuList(page);
await keys(page, "n");
await page.keyboard.type("Scratch pad");
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("Scratch pad");
await expect(page).toHaveURL(/\/doc\/scratch-pad$/);
await menuList(page);
await keys(page, "r");
await page.keyboard.press("Control+a");
await page.keyboard.type("Scratch pad, renamed");
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("Scratch pad, renamed");
await expect(page.locator(".panel.docs .doc.current .title")).toHaveText("Scratch pad, renamed");
await expect(page).toHaveURL(/\/doc\/scratch-pad-renamed$/); // the address follows the title; links go by node id
await synced(page);
const listed = await (await page.request.get("/api/docs/scratch-pad-renamed")).json();
expect(listed.title).toBe("Scratch pad, renamed");
await keys(page, "s");
await page.keyboard.press("Control+a");
await page.keyboard.type("Scratch copy");
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("Scratch copy");
await expect(page).toHaveURL(/\/doc\/scratch-copy$/);
// The copy sits after the original in the library, and is one commit in its history.
expect(await state(page, (s) => s.commits()[0].message)).toBe("Duplicate “Scratch pad, renamed” as “Scratch copy”");
const order = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c].title));
expect(order.indexOf("Scratch copy")).toBe(order.indexOf("Scratch pad, renamed") + 1);
});
test("delete asks first, and is an ordinary delete that u undoes", async ({ page }) => {
await open(page, "/doc/scratch-copy");
await keys(page, "m");
await page.keyboard.type("scratch copy");
await keys(page, "Escape D");
await expect(page.locator(".panel.docs .confirm")).toContainText("u brings it back");
await keys(page, "n");
await expect(page.locator(".panel.docs .confirm")).toHaveCount(0);
await keys(page, "D y");
await expect(page.locator(".status .message")).toContainText("Deleted “Scratch copy”");
await expect(page.locator(".top h1")).toHaveText("Library");
await synced(page);
expect((await page.request.get("/api/docs/scratch-copy")).status()).toBe(404);
await keys(page, "Escape u");
await expect.poll(() => state(page, (s) => s.snap.nodes[s.snap.root].children.map((c: string) => s.snap.nodes[c].title))).toContain("Scratch copy");
await synced(page);
expect((await page.request.get("/api/docs/scratch-copy")).status()).toBe(200);
});
test("a node moves from one document to another, and undo works wherever the last edit was", async ({ page }) => {
await open(page, "/doc/scratch-pad-renamed");
await keys(page, "a");
await page.keyboard.type("Only in the scratch pad");
await page.keyboard.press("Enter");
// Move straight on: the edit is the library's, and goes to the server from wherever the reader is.
await openByMenu(page, "menu fixture");
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
expect(await titles(page)).not.toContain("Only in the scratch pad");
await expect
.poll(async () => JSON.stringify(await (await page.request.get("/api/docs/scratch-pad-renamed/tree")).json()))
.toContain("Only in the scratch pad");
expect(JSON.stringify(await (await page.request.get("/api/docs/menu-fixture/tree")).json())).not.toContain("Only in the scratch pad");
// Undo is the library's too: u here takes back the edit made in the scratch pad.
await keys(page, "u");
await openByMenu(page, "scratch pad");
expect(await titles(page)).not.toContain("Only in the scratch pad");
await keys(page, "U");
expect(await titles(page)).toContain("Only in the scratch pad");
// An outside agent moves the section into another document with one ordinary move.
await synced(page);
const tree = await (await page.request.get("/api/tree")).json();
const node = Object.values<any>(tree.nodes).find((n) => n.title === "Only in the scratch pad");
const target = tree.nodes[tree.nodes[tree.root].children.find((c: string) => tree.nodes[c].title === "Menu fixture")];
const res = await page.request.post("/api/ops", { data: { author: "mover", message: "Move it across", ops: [{ op: "move", id: node.id, parent: target.id }] } });
expect(res.ok()).toBe(true);
await expect.poll(() => titles(page)).not.toContain("Only in the scratch pad");
await openByMenu(page, "menu fixture");
expect(await titles(page)).toContain("Only in the scratch pad");
// Its address still finds it, under its new document.
await page.reload();
await page.waitForSelector("article");
await jump(page, "Only in the scratch pad");
await expect(page).toHaveURL(new RegExp(`/doc/menu-fixture/${encodeURIComponent(node.id)}$`));
});
test("a note being written in one document lands there after the reader has moved to another", async ({ page }) => {
await open(page, "/doc/menu-fixture");
await keys(page, "i j e"); // select the document's second sentence and expand it
await expect.poll(() => state(page, (s) => s.pending.size)).toBe(1);
const where = await state(page, (s) => s.focus.node);
await openByMenu(page, "scratch pad");
await expect(page.locator(".top h1")).toHaveText("Scratch pad, renamed");
await idle(page);
await expect(page.locator(".pending, .writing")).toHaveCount(0);
const notes = await state(page, (s) => s.snap.nodes[s.snap.nodes[s.snap.root].children.find((c: string) => s.snap.nodes[c].title === "Menu fixture")].children.filter((c: string) => /mock/i.test(s.snap.nodes[c].body)).length);
expect(notes).toBe(1);
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).not.toBe(where);
});
test("the : commands do the same", async ({ page }) => {
await open(page);
await command(page, "/new Made by command");
await expect(page.locator(".top h1")).toHaveText("Made by command");
await command(page, "/rename Renamed by command");
await expect(page.locator(".top h1")).toHaveText("Renamed by command");
await command(page, "/open menu-fixture");
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
const download = page.waitForEvent("download");
await command(page, "/export");
expect(await (await download).suggestedFilename()).toBe("menu-fixture.md");
await command(page, "/open renamed-by-command");
await expect(page.locator(".top h1")).toHaveText("Renamed by command");
});
test("the menu works in panes and at phone width", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await open(page, "/doc/infinispand");
await expect(page.locator(".strip .pane")).toHaveCount(2); // the library, and the document
await openByMenu(page, "menu fixture");
await expect(page.locator(".strip .pane.root h1")).toHaveText("Library");
await expect(page.locator(".strip .pane.doc h1")).toHaveText("Menu fixture");
await keys(page, "l l");
await expect(page.locator(".strip .pane")).toHaveCount(3);
await openByMenu(page, "infinispand");
await expect(page.locator(".strip .pane")).toHaveCount(2); // the pane path is the other document's own
await expect(page.locator(".strip .pane.doc h1")).toHaveText("Infinispand");
await page.setViewportSize({ width: 390, height: 800 });
await keys(page, "m");
await expect(page.locator(".panel.docs .filter")).toBeFocused();
const box = (await page.locator(".panel.docs").boundingBox())!;
expect(box.x).toBeGreaterThanOrEqual(0);
expect(box.x + box.width).toBeLessThanOrEqual(390);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
await page.keyboard.type("scratch pad");
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("Scratch pad, renamed");
const bar = (await page.locator(".docbar").boundingBox())!;
expect(bar.x + bar.width).toBeLessThanOrEqual(390);
});
+14 -9
View File
@@ -1,11 +1,9 @@
/** The mouse, narrow screens, hover previews, hoisting, speculation, orphans, and an outside agent over HTTP. */
import { expect, test, type Page } from "@playwright/test";
import { idle, jump, keys, settle, state } from "./helpers";
import { idle, jump, keys, openPage, settle, state } from "./helpers";
async function open(page: Page) {
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
}
/** The first tree as the page (hoisted), with the library one step out. */
const open = (page: Page) => openPage(page, "Infinispand");
test.afterEach(({ page }) => settle(page));
@@ -60,20 +58,27 @@ test("on a narrow screen a margin note falls into the column", async ({ page })
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
});
test("hoisting makes one node the whole page; Esc steps out to its document, and from its top to the library", async ({ page }) => {
test("hoisting makes one node the whole page; Esc at its top steps out to its parent's page, and on up to the library", async ({ page }) => {
await open(page);
await jump(page, "Semantic conflicts");
await page.keyboard.press("z");
await expect(page.locator("h1")).toHaveText("Semantic conflicts");
await expect(page.locator(".crumbs")).toContainText("Versioning and merge");
await expect(page.locator(".crumbs")).toHaveText(/^Library › Infinispand › Versioning and merge ›/);
await expect(page.locator("article > .outline > .node")).toHaveCount(3);
await page.keyboard.press("Escape");
await expect(page.locator("h1")).toHaveText("Infinispand");
// The focus stays on the section it stepped out of, now a row; from the document's own top, out again.
await expect(page.locator("h1")).toHaveText("Versioning and merge");
// The focus stays on the section it stepped out of, now a row; from each page's own top, out again.
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("Semantic conflicts");
await page.keyboard.press("O"); // collapse everything: the focus goes to the top
await page.keyboard.press("Escape");
await expect(page.locator("h1")).toHaveText("Infinispand");
await page.keyboard.press("O");
await page.keyboard.press("Escape");
await expect(page.locator("h1")).toHaveText("Library");
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("Infinispand");
await expect(page).toHaveURL(/\/n\/[^/]+$/);
// On the root itself, the address is the library's.
await page.keyboard.press("O");
await expect(page).toHaveURL(/\/$/);
});
+7 -7
View File
@@ -6,13 +6,13 @@
* other spec uses, and undo what they write.
*/
import { expect, test, type Locator, type Page } from "@playwright/test";
import { autoLayout, command, idle, keys, settle, state } from "./helpers";
import { autoLayout, command, idle, keys, settle, state, visit } from "./helpers";
const DOC = "/doc/tuning-and-temperament";
const DOC = "Tuning and temperament";
const FIRST = "Two notes sound smooth together when their frequencies stand in a simple ratio such as 2 to 1 or 3 to 2.";
async function open(page: Page, path = DOC) {
await page.goto(path);
await visit(page, path);
await page.waitForSelector("article .outline, .strip .pane");
await page.evaluate(() => document.fonts.ready);
}
@@ -236,13 +236,13 @@ test("the menu's keys: ↑ ↓ Home End move, Enter runs, Esc closes and gives t
await expect(menu(page)).toBeVisible();
const focused = () => page.evaluate(() => document.activeElement?.querySelector(".lbl")?.textContent ?? document.activeElement?.textContent);
await keys(page, "ArrowDown");
expect(await focused()).toBe("Documents…");
await keys(page, "ArrowDown");
expect(await focused()).toBe("Jump to a section…");
await keys(page, "ArrowDown");
expect(await focused()).toBe("History and branches");
await keys(page, "ArrowUp ArrowUp");
expect(await focused()).toBe("Keys and help");
await keys(page, "Home");
expect(await focused()).toBe("Documents…");
expect(await focused()).toBe("Jump to a section…");
await keys(page, "End Enter");
await expect(menu(page)).toHaveCount(0);
await expect(page.locator(".help")).toBeVisible();
@@ -439,6 +439,6 @@ test.describe("on a phone", () => {
// The top bar's menu, a sheet too.
await page.locator(".docbar .tool[aria-haspopup]").tap();
await expect(page.locator(".menu.sheet")).toBeVisible();
await expect(item(page, "Documents…")).toHaveCount(1);
await expect(item(page, "Jump to a section…")).toHaveCount(1);
});
});
+383
View File
@@ -0,0 +1,383 @@
/**
* Everything is a node, from the keyboard: the library root is the first page and a node like any
* other, addresses name a node by its id, the jump box searches the whole library, and a node with
* everything under it is imported into, exported, copied and moved under any other node, wherever
* it is; history's f and r act on the node the reader is on. These tests make their own nodes
* (under “Scratch pad”) and leave the starter trees alone: the other specs share them.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, nodeAt, openAt, openPage, settle, state, synced } from "./helpers";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { parseDoc } from "../src/core/format";
const FIXTURE = fileURLToPath(new URL("../tests/fixtures/menu-fixture.md", import.meta.url));
/** 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 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. */
const parentOf = (page: Page, title: string) =>
page.evaluate((t) => {
const s = (globalThis as any).__ie;
const n = (Object.values(s.snap.nodes) as any[]).find((x) => x.title === t);
return n?.parent ? (s.snap.nodes[n.parent].title as string) : null;
}, title);
/** The titles of the sections under the (first) node with this title. */
const kids = (page: Page, title: string) =>
page.evaluate((t) => {
const s = (globalThis as any).__ie;
const n = (Object.values(s.snap.nodes) as any[]).find((x) => x.title === t);
return (n?.children ?? []).map((c: string) => s.snap.nodes[c]).filter((c: any) => c.kind === "section").map((c: any) => c.title) as string[];
}, title);
const status = (page: Page) => page.locator(".status .message");
/** After a load (Back and Forward too): the page has booted. */
const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready);
/** No reconciling after edits and no link scans: what these tests check is the history their own keys make. */
async function quiet(page: Page) {
await command(page, "/auto off");
await command(page, "/autolink off");
}
test.describe.configure({ mode: "serial" });
// Playwright turns on file-chooser interception only when something listens for it, and does so
// asynchronously: a waitForEvent("filechooser") made just before the key that opens the picker can
// lose that race, and then the picker opens unintercepted and no event ever comes (seen under load:
// the app had appended and clicked its file input). Listening from the start keeps it on throughout.
test.beforeEach(async ({ page }) => {
page.on("filechooser", () => {});
});
test.afterEach(({ page }) => settle(page));
test("the library root is the first page and a node like any other: its sections open in place, and standing on it is allowed", async ({ page }) => {
await openAt(page);
await expect(page.locator(".top h1")).toHaveText("Library");
await expect(page.locator(".top .byline")).toContainText(/^library · \d+ sections · \d+ nodes/);
await expect(page.locator(".docbar .lib-name")).toHaveText("Library");
const tops = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).length);
await expect(page.locator("article > .outline > .node")).toHaveCount(tops);
await expect(page.locator("article > .outline > .node.open")).toHaveCount(0);
// The first top-level node opens in place, as any section does: the library stays the page.
await keys(page, "j l");
await expect(page.locator(".top h1")).toHaveText("Library");
await expect(page.locator("article > .outline > .node.open > .row .title")).toHaveText("Infinispand");
// Its text is a prompt its sections cite: folded there too.
await expect(page.locator("article > .outline > .node.open > .content > .abstract.seed.folded")).toBeVisible();
const first = await state(page, (s) => s.focus.node);
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(first)}$`));
await expect(page).toHaveTitle("Infinispand");
// Back up onto the root itself: its address is /, and it is the node the keys act on.
await keys(page, "h k");
expect(await state(page, (s) => s.focus.node === s.snap.root)).toBe(true);
await expect(page).toHaveURL(/\/$/);
await expect(page).toHaveTitle("Library");
await keys(page, "D");
await expect(status(page)).toHaveText("The library itself cannot be deleted.");
await keys(page, "M");
await expect(status(page)).toContainText("The library root stays where it is");
await command(page, "/duplicate");
await expect(status(page)).toContainText("The library itself is not copied");
// Its own text is never stale, and nothing rewrites it.
expect(await state(page, (s) => s.snap.nodes[s.snap.root].seenUp)).toBe("");
// Its menu is a node's menu, without what it cannot do.
await page.locator(".top .byline .more").click();
const menu = page.locator(".menu");
await expect(menu).toContainText("Export as .md");
await expect(menu).toContainText("Import a .md file into it…");
await expect(menu).not.toContainText("Move under…");
await expect(menu).not.toContainText("Delete");
await keys(page, "Escape");
// z makes a node the page; Esc at its top steps back out to the library, on its row.
await keys(page, "j z");
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await expect(page.locator(".crumbs")).toHaveText(/^Library ›/);
await expect(page.locator(".top .byline")).toContainText(/^\d+ sections · \d+ nodes/);
await keys(page, "Escape");
await expect(page.locator(".top h1")).toHaveText("Library");
expect(await focusTitle(page)).toBe("Infinispand");
});
test("an address names a node by its id, and survives a reload, Back and Forward; an old document address shows the library", async ({ page }) => {
await openAt(page);
await jump(page, "Amphidromes");
const amph = await state(page, (s) => s.focus.node);
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(amph)}$`));
await page.reload();
await page.waitForSelector("article");
expect(await state(page, (s) => s.focus.node)).toBe(amph);
// A link to another node opens it; Back returns, Forward comes again.
await openAt(page, "Fixed points");
expect(await focusTitle(page)).toBe("Fixed points");
await page.goBack();
await ready(page);
await expect.poll(() => state(page, (s) => s.focus.node)).toBe(amph);
await page.goForward();
await ready(page);
await expect.poll(() => focusTitle(page)).toBe("Fixed points");
// 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.waitForSelector("article");
await expect(page.locator(".top h1")).toHaveText("Library");
await expect(status(page)).toContainText("/doc/the-tides");
await page.goto("/n/999%40999");
await page.waitForSelector("article");
await expect(page.locator(".top h1")).toHaveText("Library");
await expect(status(page)).toContainText("999@999");
});
test("the jump box searches the whole library, says where each match is, and goes there", async ({ page }) => {
await openPage(page, "Infinispand");
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await page.keyboard.press("/");
await page.keyboard.type("amphidromes");
const hit = page.locator(".jump li").first();
await expect(hit.locator(".t")).toHaveText("Amphidromes");
await expect(hit.locator(".in")).toHaveText("The tides");
await page.keyboard.press("Enter");
// 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");
expect(await focusTitle(page)).toBe("Amphidromes");
// Back to where the jump started.
await page.goBack();
await ready(page);
await expect.poll(() => focusTitle(page)).toBe("Infinispand");
// A top-level node is found like any other, and says it is in the library.
await page.keyboard.press("/");
await page.keyboard.type("Fixed points");
await expect(page.locator(".jump li").first().locator(".in")).toHaveText("Library");
await page.keyboard.press("Enter");
expect(await focusTitle(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 }) => {
// A place two levels down: Scratch pad › Inbox, made from the keyboard on the library page.
await openAt(page);
await quiet(page);
await keys(page, "a");
await page.keyboard.type("Scratch pad");
await page.keyboard.press("Enter");
await keys(page, "a");
await page.keyboard.type("Inbox");
await page.keyboard.press("Enter");
expect(await parentOf(page, "Inbox")).toBe("Scratch pad");
// :/import reads it into the node the reader is on, as its last child.
const chooser = page.waitForEvent("filechooser");
await command(page, "/import");
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.poll(() => focusTitle(page)).toBe("Menu fixture");
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.
const link = await state(page, (s) => {
const n = (Object.values(s.snap.nodes) as any[]).find((x) => x.kind === "note" && x.ref?.kind === "node" && x.anchors[0]?.text === "More text");
return { path: n.ref.path, to: s.snap.nodes[n.ref.id]?.title };
});
expect(link).toEqual({ path: ["Scratch pad", "Inbox", "Menu fixture", "First section"], to: "First section" });
// :/export saves it, from where it is, and the file is what was read in.
const download = page.waitForEvent("download");
await command(page, "/export");
expect(await (await download).suggestedFilename()).toBe("menu-fixture.md");
const text = readFileSync(await (await download).path(), "utf8");
expect(parseDoc(text)).toEqual(parseDoc(LINKED));
expect(text).toContain("^ \"More text\" link -> ./First section");
// :/duplicate copies it with everything under it, just after itself, as one commit; the copy has the focus.
await command(page, "/duplicate");
await expect(status(page)).toContainText("Saved a copy as “Menu fixture (copy)”");
expect(await focusTitle(page)).toBe("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 state(page, (s) => s.commits()[0].message)).toBe("Duplicate “Menu fixture” as “Menu fixture (copy)”");
// On the library root an import is a new top-level node.
await keys(page, "O");
expect(await state(page, (s) => s.focus.node === s.snap.root)).toBe(true);
const again = page.waitForEvent("filechooser");
await command(page, "/import");
await (await again).setFiles({ name: "exported.md", mimeType: "text/markdown", buffer: Buffer.from(text) });
await expect(status(page)).toHaveText("Imported exported.md as “Menu fixture”.");
expect(await state(page, (s) => [s.snap.nodes[s.focus.node].title, s.snap.nodes[s.focus.node].parent === s.snap.root])).toEqual(["Menu fixture", true]);
await keys(page, "D");
await expect(status(page)).toContainText("Deleted “Menu fixture”");
// A file with a quote that is not in its text is refused, naming the section and the quote.
const bad = readFileSync(FIXTURE, "utf8").replace('"a phrase worth a note"', '"words that are not there"');
await jump(page, "Inbox");
const broken = page.waitForEvent("filechooser");
await command(page, "/import");
await (await broken).setFiles({ name: "broken.md", mimeType: "text/markdown", buffer: Buffer.from(bad) });
await expect(status(page)).toContainText('Could not import broken.md: broken.md:5: in “Menu fixture”: quote not found: "words that are not there"');
expect(await kids(page, "Inbox")).toEqual(["Menu fixture", "Menu fixture (copy)"]);
});
test("Move under…: M picks any node in the library, or the root, and the node goes there with everything under it; u undoes", async ({ page }) => {
await openAt(page);
await quiet(page);
await jump(page, "Menu fixture (copy)");
await keys(page, "M");
const picker = page.locator(".jump.move");
await expect(picker.locator(".jump-head")).toContainText("Move “Menu fixture (copy)” and everything under it under…");
// Never the node itself or anything under it: its own sections are not offered, the original's are.
await page.keyboard.type("First section");
const offered = await picker.locator("li[data-hit]").evaluateAll((els) => els.map((e) => e.getAttribute("data-hit")));
const own = await state(page, (s) => {
const id = s.moving;
const out = [id];
const visit = (x: string) => s.snap.nodes[x].children.forEach((c: string) => (out.push(c), visit(c)));
visit(id);
return out;
});
expect(offered.length).toBeGreaterThan(0);
for (const id of offered) expect(own).not.toContain(id);
await page.keyboard.press("Control+a");
await page.keyboard.type("scratch pad");
await expect(picker.locator("li").first().locator(".t")).toHaveText("Scratch pad");
await page.keyboard.press("Enter");
await expect(picker).toHaveCount(0);
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Scratch pad");
expect(await focusTitle(page)).toBe("Menu fixture (copy)");
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 keys(page, "u");
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Inbox");
// Esc puts the picker away and moves nothing.
await keys(page, "M");
await expect(picker).toBeVisible();
await keys(page, "Escape");
await expect(picker).toHaveCount(0);
expect(await state(page, (s) => s.mode)).toBe("normal");
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Inbox");
// From the menu, and to the top of the library: with nothing typed, the root is offered first.
await page.locator(".node.focused > .row .more").click();
await page.locator(".menu .mi", { has: page.locator('.lbl:text-is("Move under…")') }).click();
await expect(picker).toBeVisible();
await expect(picker.locator("li").first().locator(".p")).toHaveText("the library root");
await page.keyboard.press("Enter");
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Library");
// And back under the original's place, for what follows.
await keys(page, "M");
await page.keyboard.type("inbox");
await page.keyboard.press("Enter");
expect(await parentOf(page, "Menu fixture (copy)")).toBe("Inbox");
await synced(page);
});
test("history: f shows only what touched the node the reader is on and what is under it; r reverts only that", async ({ page }) => {
await openAt(page);
await quiet(page);
await jump(page, "Inbox");
await keys(page, "a");
await page.keyboard.type("Child to revert");
await page.keyboard.press("Enter");
// An edit outside Inbox: its parent renamed.
await jump(page, "Scratch pad");
await keys(page, "r");
await page.keyboard.press("Control+a");
await page.keyboard.type("Scratch pad, renamed");
await page.keyboard.press("Enter");
await jump(page, "Inbox");
await keys(page, "g f");
await expect(page.locator(".panel .panel-head")).toContainText("History · Inbox");
const messages = await state(page, (s) => s.panel().filter((i: any) => i.type === "commit").map((i: any) => i.commit.message) as string[]);
expect(messages[0]).toBe("Rename “Child to revert”");
expect(messages).not.toContain("Rename “Scratch pad, renamed”");
expect(messages.some((m) => m.startsWith("Import"))).toBe(true);
// r on the commit before the child was added: Inbox goes back, its renamed parent stays as it is.
const target = await state(page, (s) => s.panel().findIndex((i: any) => i.type === "commit" && i.commit.message === "Add section") + 1);
while ((await state(page, (s) => s.historyIndex)) < target) await page.keyboard.press("j");
await keys(page, "r");
await expect(status(page)).toContainText("Reverted “Inbox” and what is under it");
expect(await kids(page, "Inbox")).toEqual(["Menu fixture", "Menu fixture (copy)"]);
expect(await parentOf(page, "Inbox")).toBe("Scratch pad, renamed");
expect(await state(page, (s) => s.commits()[0].tag)).toBe("revert");
// f again: everything. On the library root there is nothing to narrow to.
await keys(page, "f");
await expect(page.locator(".panel .panel-head")).toContainText("History · the library");
await keys(page, "Escape O g f");
await expect(status(page)).toContainText("On the library root history shows everything");
await keys(page, "Escape");
});
test("the library opens from this browser without the network, and catches up when it returns", async ({ page }) => {
await openPage(page, "The tides");
await synced(page);
const tides = await nodeAt(page, "The tides");
await page.route("**/api/**", (route) => route.abort());
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".top h1")).toHaveText("The tides");
await keys(page, "j r");
await page.keyboard.press("Control+a");
await page.keyboard.type("Renamed offline");
await page.keyboard.press("Enter");
await expect(page.locator(".docbar .save-state")).toHaveText(/offline|saving/);
await page.waitForTimeout(300); // the replica reaches IndexedDB a moment after the edit
await page.unroute("**/api/**");
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".docbar .save-state")).toHaveText("saved", { timeout: 15_000 });
expect(JSON.stringify(await (await page.request.get(`/api/nodes/${encodeURIComponent(tides)}/tree`)).json())).toContain("Renamed offline");
});
test("a note being written in one place lands there after the reader has gone elsewhere, and undo works wherever the last edit was", async ({ page }) => {
await openAt(page);
await quiet(page);
await jump(page, "Inbox");
await keys(page, "l j"); // Inbox open, and its first section: Menu fixture
expect(await focusTitle(page)).toBe("Menu fixture");
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 jump(page, "Fixed points");
await idle(page);
await expect(page.locator(".pending, .writing")).toHaveCount(0);
const notes = await state(page, (s) => s.snap.nodes[(Object.values(s.snap.nodes) as any[]).find((x) => x.title === "Menu fixture").id].children.filter((c: string) => /mock/i.test(s.snap.nodes[c].body)).length);
expect(notes).toBe(1);
// Undo is the library's: u here takes back the last edit, made under Inbox.
await jump(page, "Inbox");
await keys(page, "a");
await page.keyboard.type("Only in the inbox");
await page.keyboard.press("Enter");
await jump(page, "Fixed points");
await keys(page, "u");
expect(await kids(page, "Inbox")).not.toContain("Only in the inbox");
await keys(page, "U");
expect(await kids(page, "Inbox")).toContain("Only in the inbox");
});
test("an outside agent reads, exports and imports into any node over HTTP; /api/docs is gone", async ({ page, request }) => {
await openAt(page);
await synced(page);
const inbox = await nodeAt(page, "Scratch pad, renamed", "Inbox");
const tree = await (await request.get(`/api/nodes/${encodeURIComponent(inbox)}/tree`)).json();
expect(tree.root).toBe(inbox);
expect(Object.values<any>(tree.nodes).map((n) => n.title)).toContain("Menu fixture");
const res = await request.get(`/api/nodes/${encodeURIComponent(inbox)}/export`);
expect(res.headers()["content-disposition"]).toContain('filename="inbox.md"');
expect(await res.text()).toMatch(/^# Inbox\n/);
const made = await request.post(`/api/nodes/${encodeURIComponent(inbox)}/import?name=agent.md`, { data: "# From an agent\n\nIts text.\n" });
expect(made.status()).toBe(201);
await expect.poll(() => kids(page, "Inbox")).toContain("From an agent");
const refused = await request.post(`/api/nodes/${encodeURIComponent(inbox)}/import?name=bad.md`, { data: readFileSync(FIXTURE, "utf8").replace('"a phrase worth a note"', '"nowhere"') });
expect(refused.status()).toBe(422);
expect((await refused.json()).problems[0]).toContain("quote not found");
expect((await request.get("/api/docs")).status()).toBe(404);
expect((await request.get("/api/nodes/999%40999/tree")).status()).toBe(404);
});
test("in panes and at phone width: a node's address opens its pane, and the top bar fits", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await openAt(page, "Fixed points");
await expect(page.locator(".strip .pane")).toHaveCount(2); // the library, and the node's own pane
await expect(page.locator(".strip .pane.root h1")).toHaveText("Library");
await expect(page.locator(".strip .pane:not(.root) .pane-head h2")).toHaveText("Fixed points");
// Move under… works from a pane too, and the picker is the same.
await jump(page, "Only in the inbox");
await keys(page, "M");
await expect(page.locator(".jump.move")).toBeVisible();
await keys(page, "Escape");
await page.setViewportSize({ width: 390, height: 800 });
const bar = (await page.locator(".docbar").boundingBox())!;
expect(bar.x + bar.width).toBeLessThanOrEqual(390);
await expect(page.locator(".docbar .lib-name")).toBeVisible();
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
});
+19 -18
View File
@@ -1,11 +1,11 @@
/**
* The panes view, on a wide window: the path to the focus as a strip of panes side by side.
* Same production build, mock model and shared library as the other specs. The first pane is the
* library; most tests here are about the panes themselves, so they hoist to the first document
* library; most tests here are about the panes themselves, so they hoist to the first tree's top
* (z) and start from it, as the first pane.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, focusedTitle, idle, jump, keys, settle, state, writeReport, type Sample } from "./helpers";
import { autoLayout, command, focusedTitle, idle, jump, keys, openAt, settle, state, writeReport, type Sample } from "./helpers";
/** Each pane's title and box, left to right. */
const panes = (page: Page) =>
@@ -19,10 +19,10 @@ const paneTitles = async (page: Page) => (await panes(page)).map((p) => p.title)
const nodeId = (page: Page, title: string) => page.evaluate((t) => (Object.values((globalThis as any).__ie.snap.nodes) as any[]).find((n) => n.title === t).id as string, title);
async function open(page: Page) {
await page.goto("/doc/infinispand");
await openAt(page, "Infinispand");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
// The library pane and the document's; hoisting makes the document the first.
// The library pane and the tree's; hoisting makes the tree's top the first.
await expect(page.locator(".strip .pane")).toHaveCount(2);
await page.keyboard.press("z");
await expect(page.locator(".strip .pane")).toHaveCount(1);
@@ -34,34 +34,35 @@ test.describe.configure({ mode: "serial" });
test.beforeEach(({ page }) => autoLayout(page));
test.afterEach(({ page }) => settle(page));
test("the library is the first pane, and a document opens in the next; reload and Back keep the place", async ({ page }) => {
test("the library is the first pane, and any node of it opens in the next; reload and Back keep the place", async ({ page }) => {
await page.goto("/");
await page.waitForSelector(".strip .pane");
expect(await paneTitles(page)).toEqual(["Library"]);
await expect(page.locator(".pane.root .rows > .node")).toHaveCount(await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).length));
await keys(page, "j l"); // the first document's row, then open it
await keys(page, "j l"); // the first top-level node's row, then open it
expect(await paneTitles(page)).toEqual(["Library", "Infinispand"]);
await expect(page.locator(".pane.doc .abstract.seed.folded")).toBeVisible();
await keys(page, "j l"); // the next document: its pane opens beside the first one's, below it in the same column
// Its pane is headed like any other; its text, a prompt its sections cite, is folded.
await expect(page.locator(".pane:not(.root) .pane-head h2")).toHaveText("Infinispand");
await expect(page.locator(".pane:not(.root) .abstract.seed.folded")).toBeVisible();
await keys(page, "j l"); // the next one: its pane opens beside the first one's, below it in the same column
expect(await paneTitles(page)).toEqual(["Library", "Infinispand", "A mind made of text"]);
await keys(page, "l l"); // into its first section, and open that
const third = await paneTitles(page);
expect(third).toHaveLength(4);
await expect(page).toHaveURL(/\/doc\/a-mind-made-of-text\/\d+%40\d+$/);
const section = await state(page, (s) => s.focus.node);
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(section)}$`));
await page.reload();
await page.waitForSelector(".strip .pane");
expect(await paneTitles(page)).toEqual(third);
// Opening a document from the menu is a new page in the address bar's history; Back returns.
await page.keyboard.press("m");
await page.keyboard.type("tides");
await page.keyboard.press("Enter");
// From the menu a document opens in place of the one open, not beside it.
expect(await paneTitles(page)).toEqual(["Library", "Infinispand", "The tides"]);
await expect(page).toHaveURL(/\/doc\/the-tides$/);
// A jump is a new page in the address bar's history; Back returns, Forward comes again.
await jump(page, "Amphidromes");
const amphidromes = await nodeId(page, "Amphidromes");
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(amphidromes)}$`));
expect(await paneTitles(page)).toContain("The tides");
await page.goBack();
await expect.poll(() => paneTitles(page)).toEqual(third);
await expect.poll(() => state(page, (s) => s.focus.node)).toBe(section);
await page.goForward();
await expect.poll(() => paneTitles(page)).toEqual(["Library", "Infinispand", "The tides"]);
await expect.poll(() => state(page, (s) => s.focus.node)).toBe(amphidromes);
});
test("auto shows panes at 1920 px and on a laptop's 1366, one column on a phone or a narrow window; v and /view switch", async ({ page }) => {
+8 -8
View File
@@ -127,11 +127,11 @@ test("every pane of a crowded column shows at least its tab, above or below the
await library(page);
for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points", "What a proof is"]) await open(page, "Library", t);
// The one looked at near the top: those below it stack at the column's foot.
await pane(page, "Infinispand").locator(".top h1").dispatchEvent("click");
await pane(page, "Infinispand").locator(".pane-head h2").dispatchEvent("click");
await still(page);
for (const first of ["Infinispand", "What a proof is"]) {
if (first !== "Infinispand") {
await pane(page, first).locator(".top h1").dispatchEvent("click");
await pane(page, first).locator(".pane-head h2").dispatchEvent("click");
await still(page);
}
const shown = await page.evaluate(() => {
@@ -141,7 +141,7 @@ test("every pane of a crowded column shows at least its tab, above or below the
return ps.map((p, i) => {
const r = p.getBoundingClientRect();
const next = ps[i + 1]?.getBoundingClientRect().top ?? Infinity;
return { t: p.querySelector(".top h1")?.textContent?.trim(), shown: Math.min(next, c.bottom) - Math.max(r.top, c.top) };
return { t: p.querySelector(".pane-head h2, .top h1")?.textContent?.trim(), shown: Math.min(next, c.bottom) - Math.max(r.top, c.top) };
});
});
for (const s of shown) expect(s.shown, `${first} looked at: ${s.t}`).toBeGreaterThanOrEqual(TAB - 1);
@@ -189,7 +189,7 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
const top = Math.max(r.top, c.top);
const bottom = Math.min(r.bottom, next, c.bottom);
// A point on what shows of it, clear of the pin and x.
return { cut: bottom - top < Math.min(need, c.height) - 4, x: Math.max(r.left, c.left) + 14, y: top + Math.min(14, (bottom - top) / 2), colH: c.height, need, title: el.querySelector(".top h1")?.textContent?.trim() };
return { cut: bottom - top < Math.min(need, c.height) - 4, x: Math.max(r.left, c.left) + 14, y: top + Math.min(14, (bottom - top) / 2), colH: c.height, need, title: el.querySelector(".pane-head h2, .top h1")?.textContent?.trim() };
});
if (!info.cut && !across) continue;
await page.mouse.move(info.x, info.y);
@@ -217,14 +217,14 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
return peeked;
};
// Covered from below (the one looked at near the top) and from above (near the foot).
await pane(page, "Infinispand").locator(".top h1").dispatchEvent("click");
await pane(page, "Infinispand").locator(".pane-head h2").dispatchEvent("click");
await still(page);
expect(await sweep("top looked at", false)).toBeGreaterThan(0);
await pane(page, "Octopus minds").locator(".top h1").dispatchEvent("click");
await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click");
await still(page);
expect(await sweep("foot looked at", false)).toBeGreaterThan(0);
// Beside a pinned pane.
await pane(page, "The tides").locator(".top h1").dispatchEvent("click");
await pane(page, "The tides").locator(".pane-head h2").dispatchEvent("click");
await keys(page, "P");
await still(page);
expect(await sweep("beside a pinned one", false)).toBeGreaterThan(0);
@@ -243,7 +243,7 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
await library(page);
await open(page, "Library", "Infinispand");
await open(page, "Library", "Octopus minds");
await pane(page, "Octopus minds").locator(".top h1").dispatchEvent("click");
await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click");
await still(page);
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
expect(await sweep("by share", false)).toBeGreaterThan(0);
+2 -2
View File
@@ -5,7 +5,7 @@
* 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 { autoLayout, curveFaults, pixels, seedLinks, settle } from "./helpers";
import { autoLayout, curveFaults, pixels, seedLinks, settle, 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();
@@ -176,7 +176,7 @@ async function linked(browser: Browser, dpr: number) {
await ctx.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
const page = await ctx.newPage();
await autoLayout(page);
await page.goto("/doc/the-one-merger");
await visit(page, "The one merger");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
+2 -3
View File
@@ -4,7 +4,7 @@
* new tab, and Esc stops a run without keeping anything it did.
*/
import { expect, test, type Page } from "@playwright/test";
import { command, idle, jump, keys, settle, state } from "./helpers";
import { command, idle, jump, keys, openPage, settle, state } from "./helpers";
async function open(page: Page) {
@@ -13,8 +13,7 @@ async function open(page: Page) {
(globalThis as any).__opened = [];
window.open = ((url: string) => ((globalThis as any).__opened.push(String(url)), null)) as typeof window.open;
});
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
await openPage(page, "Infinispand");
}
test.describe.configure({ mode: "serial" });
+23 -16
View File
@@ -2,12 +2,12 @@
* Link discovery, keyboard only: links made automatically after an edit (and undone with u),
* suggestions shown in the text and taken or declined with y and n, review mode, the [[ completer,
* bare [[marks]] resolved on save, model-written text with its marks taken out and checked, the
* Related list, /linkdoc with progress and a cancel, the /autolink modes, and latency. Against the
* Related list, /linkhere and /linkall with progress and a cancel, the /autolink modes, and latency. Against the
* mock model, the mock Wikipedia (Octopus, Cephalopod, Fred Hoyle, Hoyle state, Carbon-12, Lambda
* calculus, …) and the hashed-words embedder (IE_EMBED=fake).
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, command, idle, jump, keys, selected, settle, state, writeReport } from "./helpers";
import { addTop, autoLayout, command, idle, jump, keys, selected, settle, state, visit, writeReport } from "./helpers";
const body = (page: Page) => state(page, (s) => s.snap.nodes[s.focus.node].body as string);
/** The links on the focused node: quote → target title (or node id). */
@@ -25,20 +25,13 @@ const suggestions = (page: Page) => state(page, (s) => s.links.forNode(s.focus.n
async function column(page: Page, path = "/") {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto(path);
await visit(page, path);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await page.evaluate(() => document.fonts.ready);
}
/** A new document with this text, typed from the keyboard; the focus is on it afterwards. */
async function newDoc(page: Page, title: string, text: string) {
await command(page, `/new ${title}`);
// In panes the library's pane has a heading too.
await expect(page.locator("h1", { hasText: title })).toBeVisible();
await keys(page, "c");
await page.keyboard.type(text);
await page.keyboard.press("Escape");
}
/** 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" });
@@ -188,8 +181,8 @@ test("the Related list sits under a node; a number links the selected words to t
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).not.toBe("Related here");
});
test("/linkdoc and /linkall look for links in the background, with progress in the status line and a cancel", async ({ page }) => {
await column(page, "/doc/fixed-points");
test("/linkhere and /linkall look for links in the background, with progress in the status line and a cancel", async ({ page }) => {
await column(page, "Fixed points");
await command(page, "/autolink suggest");
await command(page, "/linkall");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "running" && (globalThis as any).__ie.links.job.done > 0);
@@ -201,10 +194,24 @@ test("/linkdoc and /linkall look for links in the background, with progress in t
const job = await state(page, (s) => s.links.job);
expect(job.done).toBeLessThan(job.total);
await expect(page.locator(".status .job")).toHaveCount(0);
// A document job runs to the end, and what it found is waiting in the text.
await command(page, "/linkdoc");
// /linkall scanned the whole library; /linkhere scans the node the reader is on and everything under it.
const library = job.total;
const recursion = await state(page, (s) => s.focus.node);
await command(page, "/linkhere");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "done", undefined, { timeout: 30_000 });
await expect(page.locator(".status .message")).toContainText("Looked for links in Recursion without names");
const here = await state(page, (s) => s.links.job);
expect(here).toMatchObject({ scope: "node", node: recursion });
expect(here.total).toBeLessThan(library);
// On its top, the whole tree; on the library root, /linkhere is /linkall.
await keys(page, "Escape");
await jump(page, "Fixed points");
await command(page, "/linkhere");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "done", undefined, { timeout: 30_000 });
await expect(page.locator(".status .message")).toContainText("Looked for links in Fixed points");
const top = await state(page, (s) => s.links.job);
expect(top.total).toBeGreaterThan(here.total);
expect(top.total).toBeLessThan(library);
await page.waitForFunction(() => {
const s = (globalThis as any).__ie;
return s.links.under(Object.keys(s.snap.nodes), s.snap).length > 0;
+8 -15
View File
@@ -11,7 +11,7 @@
* 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 { command, idle, keys, selected, settle, state } from "./helpers";
import { addTop, command, idle, keys, selected, settle, state, visit } from "./helpers";
const SHOTS = process.env.IE_SHOTS;
@@ -38,14 +38,8 @@ async function column(page: Page) {
await page.evaluate(() => document.fonts.ready);
}
/** A new document with this text, typed from the keyboard; the focus is on it afterwards. */
async function newDoc(page: Page, title: string, text: string) {
await command(page, `/new ${title}`);
await expect(page.locator("h1", { hasText: title })).toBeVisible();
await keys(page, "c");
await page.keyboard.type(text);
await page.keyboard.press("Escape");
}
/** 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" });
@@ -148,12 +142,12 @@ test("a link removed in the text, by D or by the right-click menu, is declined a
await item.click();
expect(Object.keys(await linksHere(page))).toEqual(["Hoyle state"]);
expect(await nolink(page)).toEqual(["fred hoyle", "lambda calculus"]);
// An edit rescans the node; /linkdoc rescans the document: neither puts them back.
// An edit rescans the node; /linkhere rescans it and all under it: neither puts them back.
await keys(page, "Escape Escape c End");
await page.keyboard.type(" Again.");
await keys(page, "Escape");
await idle(page);
await command(page, "/linkdoc");
await command(page, "/linkhere");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "done", undefined, { timeout: 30_000 });
await idle(page);
expect(Object.keys(await linksHere(page))).toEqual(["Hoyle state"]);
@@ -187,8 +181,7 @@ test("when the model fails, nothing is linked unreviewed: everything is suggeste
test("a background job is reviewed as it goes, with the model's calls counted, and can be stopped; a finished one links what was approved", async ({ page }) => {
await column(page);
await page.goto("/doc/the-tides");
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await visit(page, "The tides");
await command(page, "/linkall");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "running" && (globalThis as any).__ie.links.job.done > 0);
expect(await state(page, (s) => s.links.job.review)).toMatchObject({ max: 50 });
@@ -196,9 +189,9 @@ test("a background job is reviewed as it goes, with the model's calls counted, a
await command(page, "/linkcancel");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "cancelled");
await expect(page.locator(".status .message")).toContainText("Stopped looking for links in the library");
// A document's job runs to the end: its approved links are made as one commit by the reviewer.
// A job on one tree (/linkhere on its top) runs to the end: its approved links are made as one commit by the reviewer.
const before = await state(page, (s) => s.commits()[0].id);
await command(page, "/linkdoc");
await command(page, "/linkhere");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "done", undefined, { timeout: 30_000 });
await expect(page.locator(".status .message")).toContainText("linked by the reviewer");
const job = await state(page, (s) => s.links.job);
+4 -4
View File
@@ -6,7 +6,7 @@
* store call to the painted frame. Runs last: it fills the shared library.
*/
import { expect, test, type Page } from "@playwright/test";
import { autoLayout, idle, state, synced, writeReport, type Sample } from "./helpers";
import { autoLayout, idle, state, synced, writeReport, type Sample, visit } from "./helpers";
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. */
@@ -91,7 +91,7 @@ test("a library of over 5,000 nodes in 100 more documents: keypress → paint an
await paced(page, "O");
const column = stats(await keySamples(page));
// A body edit inside a document deep in the library.
await page.goto("/doc/scale-document-97");
await visit(page, "Scale document 97");
await ready(page);
await paced(page, "j l j");
const columnEdit = stats(await editTimes(page, 15));
@@ -110,7 +110,7 @@ test("a library of over 5,000 nodes in 100 more documents: keypress → paint an
// ---- forks: four documents opened side by side from the library pane, each three panes deep (document, part, leaf) ----
// A fresh view: the panes opened above stay open (opens go beside), and would be restored here.
await page.evaluate(() => localStorage.clear());
await page.goto("/doc/scale-document-90");
await visit(page, "Scale document 90");
await ready(page);
await paced(page, "l l l l");
for (let d = 1; d < 4; d++) await paced(page, "h h j Enter l l l l");
@@ -126,7 +126,7 @@ test("a library of over 5,000 nodes in 100 more documents: keypress → paint an
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
for (let i = 0; i < 8; i++) await paced(page, "[ [ [ ] ] ]");
const forks = stats(await keySamples(page));
await page.goto("/doc/scale-document-98");
await visit(page, "Scale document 98");
await ready(page);
await paced(page, "l l j");
const panesEdit = stats(await editTimes(page, 15));