Panes by column: a forest of panes, curves between them, close, pin and an active rule

The tree of forks becomes a forest: a pinned pane stays open when a pane it was
opened from closes, as an orphan in its own column. Close takes a pane and what
was opened from it, pinned panes excepted; pin and unpin; [ and ] move to the
pane above or below in a column.

The panes view is laid out by column: column d holds every pane at depth d and
divides its own height among them, a short pane taking only what its text needs;
when they do not fit, all but the focused branch's pane (and pinned ones) fold
into one-line tabs. A faint curve runs from the words, row or link each pane was
opened from to its title, the focused branch's in a stronger ink; curves through
one gutter take lanes side by side, ordered to cross least. Every pane has the
same hairline right and bottom. The active pane has a heavy rule across its top,
the rest of the focused branch a hairline. Each pane has a pin and a x at its top
right (the x also on its spine); q closes the active pane, whatever it shows
(it used to close a whole fork from wherever the fork began, which closed the
node an article was opened from); P pins it. /curves off hides the curves.

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-16 00:37:59 -05:00
1 parent 2f8ca98207
commit 3298cc430c
20 files changed
+1822 -783

No files matched your search

+2 -2
View File
@@ -7,12 +7,12 @@
import { expect, test, type Page } from "@playwright/test";
import { command, idle, jump, keys, seedLinks, selected, settle, state } from "./helpers";
const panes = (page: Page) => page.locator(".strip > .pane");
const panes = (page: Page) => page.locator(".strip .pane");
async function wide(page: Page, path = "/doc/fixed-points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await page.goto(path);
await page.waitForSelector(".strip > .pane");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
}
async function column(page: Page, path: string) {
+426 -160
View File
@@ -1,29 +1,41 @@
/**
* Forks in the panes view: a modified open (Shift+Enter, Shift-, Ctrl- or middle-click) opens its
* pane beside what is to the right instead of replacing it, and the space right of the pane
* divides into rows, one per fork. Same build, mock model, mock Wikipedia and shared library as
* the other specs; the documents are hoisted to (z) as in panes.spec.ts.
* Forks in the panes view, laid out by column: a modified open (Shift+Enter, Shift-, Ctrl- or
* middle-click) opens its pane below what is in the next column instead of replacing it; column d
* holds every pane at depth d and divides its own height among them, folding all but one into tabs
* when they do not fit. Curves run from where each pane was opened to its title; panes close (q, ×)
* and pin (P, pin). Same build, mock model, mock Wikipedia and shared library as the other specs;
* the documents are hoisted to (z) as in panes.spec.ts.
*/
import { expect, test, type Page } from "@playwright/test";
import { focusedTitle, jump, keys, seedLinks, selected, settle, state } from "./helpers";
/** The 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) =>
state(page, (s) => {
const name = (p: any) => (p.kind === "node" ? s.snap.nodes[p.id]?.title || s.snap.nodes[p.id]?.anchors[0]?.text : `W:${p.title}${p.sec ? `#${p.sec}` : ""}`);
const go = (n: any): unknown => (n.kids.length ? [name(n.ref), n.kids.map((k: any, j: number) => (j === n.pick ? ["*", go(k)] : go(k)))] : name(n.ref));
return go(s.tree);
return go(s.forest.trees[0]);
});
/** The focused branch, by title. */
const trail = (page: Page) => state(page, (s) => s.trail.map((p: any) => (p.kind === "node" ? s.snap.nodes[p.id]?.title || s.snap.nodes[p.id]?.anchors[0]?.text : `W:${p.title}${p.sec ? `#${p.sec}` : ""}`)));
/** The rows right of the first pane with forks, each as the titles of its panes, left to right. */
const forkRows = (page: Page) =>
/** The columns on screen, left to right, each as its panes' titles top to bottom. */
const columns = (page: Page) =>
page.evaluate(() =>
[...document.querySelectorAll(".strip .forks")][0]
? [...document.querySelector(".strip .forks")!.children].map((row) =>
[...row.querySelectorAll(".pane")].map((p) => p.querySelector(".wiki-head h2, .pane-head h2, .top h1")?.textContent?.trim() ?? ""),
)
: [],
[...document.querySelectorAll(".strip > .col")].map((c) =>
[...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. */
const boxes = (page: Page) =>
page.evaluate(() =>
Object.fromEntries(
[...document.querySelectorAll<HTMLElement>(".strip .pane")].map((p) => {
const r = p.getBoundingClientRect();
return [p.querySelector(".wiki-head h2, .pane-head h2, .top h1")?.textContent?.trim() ?? "", { x: r.x, y: r.y, w: r.width, h: r.height, tab: p.hasAttribute("data-tab") }];
}),
),
);
/** A section's child sections, by title. */
const childTitles = (page: Page, title: string) =>
@@ -32,14 +44,39 @@ const childTitles = (page: Page, title: string) =>
const n = (Object.values(s.snap.nodes) as any[]).find((x) => x.title === t);
return n.children.filter((c: string) => s.snap.nodes[c].kind === "section").map((c: string) => s.snap.nodes[c].title) as string[];
}, title);
/** The curves drawn: from which pane to which (ids in the forest), their classes, and their ends on screen. */
const curves = (page: Page) =>
page.evaluate(() => {
const svg = document.querySelector<SVGSVGElement>(".curves")!;
const box = svg.getBoundingClientRect();
return [...svg.querySelectorAll("path")].map((p) => {
const a = p.getPointAtLength(0);
const b = p.getPointAtLength(p.getTotalLength());
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 has stopped scrolling sideways (it scrolls smoothly to follow the focus), and the curves have been drawn after. */
async function still(page: Page) {
await page.waitForFunction(
() =>
new Promise((r) => {
const el = document.querySelector(".strip")!;
const x = el.scrollLeft;
setTimeout(() => r(el.scrollLeft === x), 300);
}),
);
await nextFrames(page);
}
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.waitForSelector(".strip > .pane");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await expect(page.locator(".strip > .pane")).toHaveCount(2);
await expect(page.locator(".strip .pane")).toHaveCount(2);
await page.keyboard.press("z");
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
}
/** Tab through the focused text's marked spans until the selection is these words. */
@@ -51,13 +88,23 @@ async function tabTo(page: Page, words: string) {
throw new Error(`Tab never reached “${words}”`);
}
/** Whether an element's box is inside the strip's visible box. */
const inView = (page: Page, sel: string) =>
page.evaluate((sel) => {
const strip = document.querySelector<HTMLElement>(".strip")!.getBoundingClientRect();
const r = document.querySelector(sel)!.getBoundingClientRect();
return r.top >= strip.top - 1 && r.bottom <= strip.bottom + 1;
}, sel);
/** 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-eukaryotic-cell");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Two kinds of cell");
await keys(page, "Enter");
await tabTo(page, "Eukaryotes");
await keys(page, "Enter");
await expect(pane(page, "Eukaryote").locator(".wiki-text a[data-wiki]").first()).toBeVisible();
await pane(page, "Eukaryote").locator('.wiki-text a[data-wiki="Bacteria"]').first().click();
await expect(pane(page, "Bacteria").locator(".wiki-text").first()).toBeVisible();
await page.locator(".pane .row", { hasText: "Simple cells" }).first().click({ modifiers: ["Shift"] });
await page.locator(".pane .row", { hasText: "Complex cells" }).first().click({ modifiers: ["Shift"] });
await expect.poll(() => columns(page)).toEqual([["Library"], ["The one merger"], ["Two kinds of cell"], ["Eukaryote", "Simple cells", "Complex cells"], ["Bacteria"]]);
await still(page);
}
test.use({ viewport: { width: 1920, height: 1080 } });
test.describe.configure({ mode: "serial" });
@@ -70,39 +117,35 @@ test.beforeEach(async ({ context }) => {
});
test.afterEach(({ page }) => settle(page));
test("Shift+Enter on a section row opens a fork beside the pane to the right; Enter still replaces, and focuses a fork already open", async ({ page }) => {
test("Shift+Enter on a section row opens a fork below in the next column; Enter still replaces, and focuses a fork already open", async ({ page }) => {
await open(page);
await keys(page, "l l l"); // Expansion by depth showing; the focus on its first row
// Nothing to the right yet: a fork is a plain open, and a plain trail is drawn as before.
// Nothing to the right yet: a fork is a plain open, and a plain trail is one pane per column.
await keys(page, "Shift+Enter");
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", [["*", "Levels of a node"]]]]]]);
await expect(page.locator(".strip:not(.forked) > .pane")).toHaveCount(3);
await expect(page.locator(".forks")).toHaveCount(0);
expect(await columns(page)).toEqual([["Infinispand"], ["Expansion by depth"], ["Levels of a node"]]);
await keys(page, "j Shift+Enter");
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Pre-generated depth"]]);
expect(await columns(page)).toEqual([["Infinispand"], ["Expansion by depth"], ["Levels of a node", "Pre-generated depth"]]);
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Pre-generated depth"]);
// The rows divide the height; both start in the column next to the pane they came from.
const [a, b, parent] = await Promise.all([
page.locator(".forks > .fork").nth(0).locator(".pane").boundingBox(),
page.locator(".forks > .fork").nth(1).locator(".pane").boundingBox(),
page.locator('.pane[data-pane-index="1"]').boundingBox(),
]);
expect(a!.x).toBeCloseTo(b!.x, 0);
expect(b!.y).toBeGreaterThanOrEqual(a!.y + a!.height - 1);
expect(a!.x).toBeGreaterThan(parent!.x);
expect(a!.height).toBeGreaterThan(300);
// They share the column's height, one above the other, beside the pane they came from.
const b = await boxes(page);
const [a, c, parent] = [b["Levels of a node"], b["Pre-generated depth"], b["Expansion by depth"]];
expect(a.x).toBeCloseTo(c.x, 0);
expect(c.y).toBeCloseTo(a.y + a.h, 0);
expect(a.x).toBeGreaterThan(parent.x);
const strip = await page.locator(".strip").evaluate((el) => el.clientHeight);
expect(Math.abs(a.h + c.h - strip)).toBeLessThan(2);
// The pane they came from marks both, the focused one as before and the other lightly.
await expect(page.locator('.pane[data-pane-index="1"] .node.showing > .row')).toHaveText([/Pre-generated depth/]);
await expect(page.locator('.pane[data-pane-index="1"] .node.forked > .row')).toHaveText([/Levels of a node/]);
await expect(pane(page, "Expansion by depth").locator(".node.showing > .row")).toHaveText([/Pre-generated depth/]);
await expect(pane(page, "Expansion by depth").locator(".node.forked > .row")).toHaveText([/Levels of a node/]);
// A plain Enter replaces only the focused fork.
await keys(page, "j Enter");
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
expect(await columns(page)).toEqual([["Infinispand"], ["Expansion by depth"], ["Levels of a node", "Generation on demand"]]);
// Enter (or Shift+Enter) on the row of a fork already open focuses that fork: no second copy.
await keys(page, "k k Enter");
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
expect(await columns(page)).toEqual([["Infinispand"], ["Expansion by depth"], ["Levels of a node", "Generation on demand"]]);
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
await keys(page, "j j Shift+Enter");
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand"]);
});
@@ -120,26 +163,325 @@ test("Shift-, Ctrl- and middle-click fork from section rows; a click in another
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Borrowed from Gwern", [kids[0], kids[1], ["*", kids[2]]]]]]]);
// A Shift-click selected no text on the way.
expect(await page.evaluate(() => window.getSelection()?.isCollapsed ?? true)).toBe(true);
// A click anywhere in the first fork's pane focuses that fork.
await page.locator(".forks > .fork").nth(0).locator(".pane-head").click();
// A click on the first fork's heading focuses that fork, and makes that pane the active one.
await pane(page, kids[0]).locator(".pane-head").click();
expect(await trail(page)).toEqual(["Infinispand", "Borrowed from Gwern", kids[0]]);
expect(await focusedTitle(page)).toBe(kids[0]);
await expect(page.locator(".forks > .fork.on")).toHaveCount(1);
expect(await page.locator(".forks > .fork").nth(0).getAttribute("class")).toContain("on");
// A plain click on a row replaces the focused fork, and a Shift-click on the focused row whose pane shows does not close it.
await row("Display forms").click({ modifiers: ["Shift"] }); // the first pane forks too: a stack right of it
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
await expect(page.locator(".strip > .forks > .fork").nth(0).locator(".forks > .fork")).toHaveCount(3);
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[0]);
// The first pane forks too: its forks share the next column, and the panes opened from each the one after.
await row("Display forms").click({ modifiers: ["Shift"] });
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
expect(await columns(page)).toEqual([["Infinispand"], ["Borrowed from Gwern", "Display forms"], kids.slice(0, 3)]);
await row("Display forms").click({ modifiers: ["Shift"] });
expect((await columns(page))[1]).toEqual(["Borrowed from Gwern", "Display forms"]);
await row("Editing and regeneration").click();
expect(await trail(page)).toEqual(["Infinispand", "Editing and regeneration"]);
await expect(page.locator(".strip > .forks > .fork").nth(1).locator(".pane-head h2")).toHaveText("Editing and regeneration");
expect((await columns(page))[1]).toEqual(["Borrowed from Gwern", "Editing and regeneration"]);
});
test("the owner's screenshot: the lone pane in the next column fills its height; the shared column gives short panes what they need", async ({ page }) => {
await cells(page);
const b = await boxes(page);
const strip = await page.locator(".strip").evaluate((el) => el.clientHeight);
// Bacteria, alone in its column, is as tall as the strip.
expect(Math.abs(b["Bacteria"].h - strip)).toBeLessThan(1);
expect(b["Bacteria"].y).toBeCloseTo(b["Eukaryote"].y, 0);
// The three forks share their column's height, top to bottom, with nothing left over.
const col = ["Eukaryote", "Simple cells", "Complex cells"].map((t) => b[t]);
expect(Math.abs(col.reduce((h, x) => h + x.h, 0) - strip)).toBeLessThan(2);
for (let i = 1; i < 3; i++) expect(col[i].y).toBeCloseTo(col[i - 1].y + col[i - 1].h, 0);
for (const t of ["Eukaryote", "Simple cells", "Complex cells"]) expect(await pane(page, t).getAttribute("data-tab")).toBeNull();
});
test("every pane has the same hairline on its right and bottom, shared with its neighbours: none missing, none doubled", async ({ page }) => {
await cells(page);
const edges = await page.evaluate(() =>
[...document.querySelectorAll<HTMLElement>(".strip .pane")].map((p) => {
const cs = getComputedStyle(p);
const last = p === p.parentElement!.lastElementChild;
return { title: p.querySelector("h1, h2")?.textContent, right: cs.borderRightWidth, bottom: cs.borderBottomWidth, top: cs.borderTopWidth, left: cs.borderLeftWidth, rightColor: cs.borderRightColor, bottomColor: cs.borderBottomColor, last, flush: document.querySelector(".strip")!.hasAttribute("data-flush") };
}),
);
const color = edges[0].rightColor;
for (const e of edges) {
expect(e.right, `${e.title} right`).toBe("1px");
expect(e.bottom, `${e.title} bottom`).toBe("1px");
expect(e.rightColor).toBe(color);
// Between panes there is one line: the upper or left pane's, never both.
expect(e.top).toBe("0px");
expect(e.left).toBe("0px");
// The last pane of a column meets the status line, which draws that line, unless a scrollbar runs between them.
if (!e.last || !e.flush) expect(e.bottomColor).toBe(color);
}
// In the shared column each pane's box ends where the next begins: the line between them is the upper one's bottom edge.
const b = await boxes(page);
expect(b["Simple cells"].y).toBeCloseTo(b["Eukaryote"].y + b["Eukaryote"].h, 0);
// An article's tinted ground meets the plain one at the same line.
const tint = await pane(page, "Eukaryote").evaluate((el) => getComputedStyle(el).backgroundColor);
expect(tint).not.toBe(await pane(page, "Simple cells").evaluate((el) => getComputedStyle(el).backgroundColor));
expect(await pane(page, "Eukaryote").evaluate((el) => getComputedStyle(el).borderBottomColor)).toBe(color);
});
test("a curve per open edge, from where each pane was opened to its title; it follows a pane's scroll and the strip's, and the focused branch's is drawn differently", async ({ page }) => {
await cells(page);
// Library and The one merger are covered to spines, so the curves into and out of them are not drawn.
const ids: Record<string, number> = {};
for (const t of ["Two kinds of cell", "Eukaryote", "Simple cells", "Complex cells", "Bacteria"]) ids[t] = await tid(page, t);
let cs = await curves(page);
const edge = (from: string, to: string) => cs.filter((c) => c.from === ids[from] && c.to === ids[to]);
for (const [f, t] of [["Two kinds of cell", "Eukaryote"], ["Two kinds of cell", "Simple cells"], ["Two kinds of cell", "Complex cells"], ["Eukaryote", "Bacteria"]]) expect(edge(f, t), `${f} → ${t}`).toHaveLength(1);
expect(cs.filter((c) => c.to === ids["Two kinds of cell"])).toHaveLength(0);
// Ends: near the link words, the row, and the child's title.
const near = async (sel: string, p: { x: number; y: number }, slack = 16) => {
const r = (await page.locator(sel).first().boundingBox())!;
expect(p.x).toBeGreaterThan(r.x - slack);
expect(p.x).toBeLessThan(r.x + r.width + slack);
expect(p.y).toBeGreaterThan(r.y - slack);
expect(p.y).toBeLessThan(r.y + r.height + slack);
};
const kinds = pane(page, "Two kinds of cell");
const nearIn = async (loc: ReturnType<Page["locator"]>, p: { x: number; y: number }, slack = 16) => {
const r = (await loc.first().boundingBox())!;
expect(p.x).toBeGreaterThan(r.x - slack);
expect(p.x).toBeLessThan(r.x + r.width + slack);
expect(p.y).toBeGreaterThan(r.y - slack);
expect(p.y).toBeLessThan(r.y + r.height + slack);
};
await nearIn(kinds.locator(".lnk", { hasText: "Eukaryotes" }), edge("Two kinds of cell", "Eukaryote")[0].a);
await nearIn(kinds.locator(".node.forked > .row", { hasText: "Simple cells" }), edge("Two kinds of cell", "Simple cells")[0].a);
const title = (t: string) => pane(page, t).locator(".wiki-head h2, .pane-head h2").first();
for (const t of ["Eukaryote", "Simple cells", "Complex cells"]) {
const end = edge("Two kinds of cell", t)[0].b;
const r = (await title(t).boundingBox())!;
expect(end.x).toBeLessThanOrEqual(r.x + 2);
expect(end.x, t).toBeGreaterThan(r.x - 30);
expect(end.y).toBeGreaterThan(r.y - 4);
expect(end.y).toBeLessThan(r.y + r.height + 4);
}
await near('.wiki-pane .wiki-text a[data-wiki="Bacteria"]', edge("Eukaryote", "Bacteria")[0].a);
// The focused branch (Two kinds of cell → Complex cells) in its own ink; the others not.
expect(edge("Two kinds of cell", "Complex cells")[0].cls).toContain("on");
expect(edge("Two kinds of cell", "Simple cells")[0].cls).not.toContain("on");
expect(await page.locator(".curves path.on").first().evaluate((el) => getComputedStyle(el).stroke)).not.toBe(await page.locator(".curves path:not(.on)").first().evaluate((el) => getComputedStyle(el).stroke));
// Scroll Eukaryote's text: the curve out of it moves with its link.
const before = edge("Eukaryote", "Bacteria")[0].a;
await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 40));
await nextFrames(page);
cs = await curves(page);
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.
await pane(page, "Eukaryote").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 400));
await nextFrames(page);
cs = await curves(page);
expect(edge("Eukaryote", "Bacteria")[0].cls).toContain("lost");
const top = (await pane(page, "Eukaryote").locator(".pane-scroll").boundingBox())!.y;
expect(Math.abs(edge("Eukaryote", "Bacteria")[0].a.y - top)).toBeLessThan(6);
// Scroll the strip: the curves move with the panes.
const was = edge("Two kinds of cell", "Simple cells")[0].b;
await page.locator(".strip").evaluate((el) => (el.scrollLeft += el.scrollLeft >= 200 ? -200 : 200));
await still(page);
cs = await curves(page);
const now = edge("Two kinds of cell", "Simple cells")[0].b;
const r = (await title("Simple cells").boundingBox())!;
expect(Math.abs(now.x - was.x)).toBeGreaterThan(20);
expect(now.x).toBeGreaterThan(r.x - 30);
expect(now.x).toBeLessThanOrEqual(r.x + 2);
// And they can be turned off, and on again.
await page.keyboard.press(":");
await page.keyboard.type("/curves off");
await page.keyboard.press("Enter");
await expect(page.locator(".curves path")).toHaveCount(0);
await page.keyboard.press(":");
await page.keyboard.type("/curves on");
await page.keyboard.press("Enter");
await expect.poll(async () => (await curves(page)).length).toBeGreaterThan(3);
});
test("exactly one pane is active, under a heavy rule; the rest of the focused branch under a hairline", async ({ page }) => {
await cells(page);
const marks = () =>
page.evaluate(() =>
[...document.querySelectorAll<HTMLElement>(".strip .pane")].map((p) => ({
title: p.querySelector("h1, h2")?.textContent?.trim(),
active: p.classList.contains("active"),
rule: getComputedStyle(p, "::after").height,
})),
);
let m = await marks();
expect(m.filter((x) => x.active).map((x) => x.title)).toEqual([await state(page, (s) => s.snap.nodes[s.trail[s.paneAt].id].title)]);
expect(m.find((x) => x.active)!.rule).toBe("3px");
expect(m.filter((x) => x.rule === "3px")).toHaveLength(1);
// The other panes on the focused branch: a hairline; off it, nothing.
expect(m.find((x) => x.title === "Complex cells")!.rule).toBe("1px");
expect(m.find((x) => x.title === "Simple cells")!.rule).toBe("0px");
// Into an article: it is the active pane now, and still the only one.
await pane(page, "Bacteria").locator(".wiki-head").click();
m = await marks();
expect(m.filter((x) => x.active).map((x) => x.title)).toEqual(["Bacteria"]);
expect(m.filter((x) => x.rule === "3px").map((x) => x.title)).toEqual(["Bacteria"]);
});
/** Five sections of the first pane, opened side by side: five panes in column 1. */
async function five(page: Page) {
await open(page);
await keys(page, "j Shift+Enter j Shift+Enter j Shift+Enter j Shift+Enter j Shift+Enter");
const kids = (await childTitles(page, "Infinispand")).slice(0, 5);
expect((await columns(page))[1]).toEqual(kids);
return kids;
}
test("a column with more panes than fit folds all but the focused one into tabs; moving the focus there, or a click on a tab, opens it", async ({ page }) => {
const kids = await five(page);
const strip = await page.locator(".strip").evaluate((el) => el.clientHeight);
let b = await boxes(page);
// The focused fork (the last) takes the height less a tab's for each of the others; the others are tabs, in order, above it.
expect(kids.slice(0, 4).every((t) => b[t].tab)).toBe(true);
expect(b[kids[4]].tab).toBe(false);
expect(Math.abs(b[kids[4]].h - (strip - 4 * 30))).toBeLessThan(2);
for (let i = 1; i < 5; i++) expect(b[kids[i]].y).toBeCloseTo(b[kids[i - 1]].y + b[kids[i - 1]].h, 0);
await expect(pane(page, kids[0]).locator(".tabline .tabtitle")).toHaveText(kids[0]);
await expect(pane(page, kids[0]).locator(".tabline")).toBeVisible();
await expect(pane(page, kids[0]).locator(".pane-ctl .pane-btn.close")).toBeVisible();
// l steps into the focused fork's pane; [ moves up the column: that tab opens, the one left folds.
await keys(page, "l");
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[4]);
const where = await focusedTitle(page);
await keys(page, "[");
expect(await trail(page)).toEqual(["Infinispand", kids[3]]);
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[3]);
b = await boxes(page);
expect(b[kids[3]].tab).toBe(false);
expect(b[kids[4]].tab).toBe(true);
// ] comes back down, to where the focus was.
await keys(page, "]");
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[4]);
expect(await focusedTitle(page)).toBe(where);
await keys(page, "]");
await expect(page.locator(".status .message")).toContainText("No pane below");
// A click on a tab opens that pane and makes it the active one.
await pane(page, kids[1]).locator(".tabline").click();
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[1]);
b = await boxes(page);
expect(b[kids[1]].tab).toBe(false);
expect(b[kids[4]].tab).toBe(true);
});
test("a pinned pane does not fold in its column, outlives a closed parent as an orphan in its column, and is not covered to a spine", async ({ page }) => {
const kids = await five(page);
// Pin the second fork, by its button: it opens beside the focused one and stays open as the focus moves up and down the column.
await pane(page, kids[1]).locator(".pane-ctl .pane-btn.pin").click();
await expect(pane(page, kids[1])).toHaveClass(/pinned/);
let b = await boxes(page);
expect(b[kids[1]].tab).toBe(false);
expect(b[kids[1]].h).toBeGreaterThan(200);
await keys(page, "l [ [");
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[2]);
b = await boxes(page);
expect(b[kids[1]].tab).toBe(false);
expect(b[kids[4]].tab).toBe(true);
// The pin is kept across a reload.
await page.reload();
await page.waitForSelector(".strip .pane");
await expect(pane(page, kids[1])).toHaveClass(/pinned/);
// Pin a pane opened from the first fork, then close that fork with its ×: the pinned pane stays where it was, an orphan, with no curve into it.
await pane(page, kids[0]).locator(".tabline").click();
const grand = (await childTitles(page, kids[0]))[0];
await keys(page, "l l l P");
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(grand);
await expect(page.locator(".pane.active")).toHaveClass(/pinned/);
const orphan = await tid(page, grand);
await pane(page, kids[0]).locator(".pane-ctl .pane-btn.close").click();
expect((await columns(page))[1]).not.toContain(kids[0]);
expect((await columns(page))[2]).toEqual([grand]);
await expect(pane(page, grand).locator(".orphan-note")).toBeVisible();
expect(await state(page, (s) => s.forest.trees.length)).toBe(2);
await nextFrames(page);
expect((await curves(page)).filter((c) => c.to === orphan)).toHaveLength(0);
// Its own × closes it.
await pane(page, grand).locator(".pane-ctl .pane-btn.close").click();
expect(await columns(page)).toHaveLength(2);
});
test("a pinned column is not covered to a spine as the strip scrolls; later columns slide past it", async ({ page }) => {
await page.setViewportSize({ width: 1600, height: 1000 });
await open(page);
await keys(page, "l l l j j l l l");
await expect.poll(async () => (await columns(page)).length).toBe(4);
const covered = () => page.evaluate(() => [...document.querySelectorAll(".strip > .col")].map((c) => c.hasAttribute("data-covered")));
// Unpinned, column 1 is covered once the strip has scrolled to the last.
await page.locator(".strip").evaluate((el) => (el.scrollLeft = el.scrollWidth));
await expect.poll(async () => (await covered())[1]).toBe(true);
await pane(page, "Expansion by depth").locator(".spine-title").click();
await keys(page, "P");
await expect(pane(page, "Expansion by depth")).toHaveClass(/pinned/);
await page.locator(".strip").evaluate((el) => (el.scrollLeft = el.scrollWidth));
await still(page);
expect((await covered())[1]).toBe(false);
const col1 = (await pane(page, "Expansion by depth").boundingBox())!;
const col2x = await page.evaluate(() => document.querySelectorAll(".strip > .col")[2].getBoundingClientRect().x);
expect(col1.x).toBeGreaterThanOrEqual(0);
expect(col2x).toBeGreaterThanOrEqual(col1.x + col1.width - 1);
// The last column can still be scrolled fully into view.
const last = (await pane(page, "Deepening a leaf").boundingBox())!;
expect(last.x + last.width).toBeLessThanOrEqual(1600 + 1);
await keys(page, "P");
await expect(pane(page, "Expansion by depth")).not.toHaveClass(/pinned/);
});
test("× and q close the pane they are on, whatever it shows, with what was opened from it; pinned panes under it stay", async ({ page }) => {
// A node: × on a fork that is not focused closes it alone.
await cells(page);
await pane(page, "Simple cells").locator(".pane-ctl .pane-btn.close").click();
expect((await columns(page))[3]).toEqual(["Eukaryote", "Complex cells"]);
// An article opened from an article: q closes it only, and the focus goes back to its link.
await pane(page, "Bacteria").locator(".wiki-head").click();
await keys(page, "q");
expect(await columns(page)).toEqual([["Library"], ["The one merger"], ["Two kinds of cell"], ["Eukaryote", "Complex cells"]]);
await expect(page.locator(".pane.active .wiki-head h2")).toHaveText("Eukaryote");
// Pinned panes under a closed pane stay: open Bacteria again, pin it, close Eukaryote.
await pane(page, "Eukaryote").locator('.wiki-text a[data-wiki="Bacteria"]').first().click();
await keys(page, "P");
await pane(page, "Eukaryote").locator(".pane-ctl .pane-btn.close").click();
expect(await columns(page)).toEqual([["Library"], ["The one merger"], ["Two kinds of cell"], ["Complex cells"], ["Bacteria"]]);
await expect(pane(page, "Bacteria").locator(".orphan-note")).toBeVisible();
// Its own × closes the orphan.
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 page.waitForSelector(".strip .pane");
await jump(page, "The common ancestor");
await keys(page, "l");
await page.locator(".pane .anchor", { hasText: "The camera-like eye" }).click();
await expect(page.locator(".pane.note-pane")).toHaveCount(1);
await expect(page.locator(".pane.active")).toHaveClass(/note-pane/);
await keys(page, "q");
await expect(page.locator(".pane.note-pane")).toHaveCount(0);
expect(await selected(page)).toBe("The camera-like eye");
});
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 page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Recursion without names");
// A fork beside it from the document's pane: Recursion without names starts a fork.
await keys(page, "k Enter j Shift+Enter");
expect((await trail(page)).at(-1)).toBe("Recursion without names");
await tabTo(page, "fixed-point combinator");
await keys(page, "Enter");
await expect(page.locator(".wiki-pane .wiki-head h2", { hasText: "Fixed-point combinator" })).toHaveCount(1);
await page.locator('.wiki-pane .wiki-text a[data-wiki="Haskell Curry"]').first().click();
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator", "W:Haskell Curry"]);
await keys(page, "q");
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator"]);
await keys(page, "q");
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names"]);
expect(await selected(page)).toBe("fixed-point combinator");
});
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 page.waitForSelector(".strip > .pane");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Recursion without names");
await tabTo(page, "fixed-point combinator");
@@ -149,115 +491,28 @@ test("from a Wikipedia link, a node link and a link inside an article: forks, ea
expect(await selected(page)).toBe("fixed-point combinator");
await tabTo(page, "Y combinator");
await keys(page, "Shift+Enter");
expect(await forkRows(page)).toEqual([["Fixed-point combinator"], ["How Y works"]]);
expect((await columns(page))[3]).toEqual(["Fixed-point combinator", "How Y works"]);
// In the text it came from, both links are marked, the focused fork's more strongly.
const from = page.locator('.pane[data-pane-index="2"]');
await expect(from.locator(".lnk.forked.picked")).toHaveText("Y combinator");
await expect(from.locator(".lnk.forked:not(.picked)")).toHaveText("fixed-point combinator");
// [ goes up to the article's row; its sections open as rows, as before.
// Into How Y works, then [ goes up the column to the article; its sections open as rows, as before.
await pane(page, "How Y works").locator(".pane-head").click();
await keys(page, "[");
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator"]);
expect(await state(page, (s) => s.aux)).toMatchObject({ kind: "wiki", host: "p3", row: { t: "head" } });
await expect(from.locator(".lnk.forked.picked")).toHaveText("fixed-point combinator");
await expect(page.locator(".wiki-pane .wrow").first()).toBeVisible();
await keys(page, "j j l");
expect((await trail(page)).at(-1)).toBe("W:Fixed-point combinator#2");
// A Shift-click on a link in the article's text forks beside that section.
const art = page.locator(".forks > .fork").nth(0).locator(".wiki-pane").first();
const art = pane(page, "Fixed-point combinator");
await art.locator('.wiki-text a[data-wiki="Haskell Curry"]').click({ modifiers: ["Shift"] });
const article = ["W:Fixed-point combinator", ["W:Fixed-point combinator#2", ["*", "W:Haskell Curry"]]];
const recursion = ["Recursion without names", [["*", article], "How Y works"]];
expect(await tree(page)).toEqual(["Library", [["*", ["Fixed points", [["*", recursion]]]]]]);
await expect(art.locator(".wrow.forked > .row .title")).toHaveText("Y combinator");
await expect(art.locator('.wiki-text a.forked.picked[data-wiki="Haskell Curry"]')).toHaveCount(1);
// And Shift+Enter on a link selected by Tab in the article's text: a third fork of the article.
await keys(page, "h");
for (let i = 0; i < 6 && (await state(page, (s) => s.aux?.host)) !== "p3"; i++) await keys(page, "h");
await keys(page, "k k k");
await tabTo(page, "lambda calculus");
await keys(page, "Shift+Enter");
await expect(page.locator(".wiki-pane .wiki-head h2", { hasText: "Lambda calculus" })).toHaveCount(1);
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator", "W:Lambda calculus"]);
const stack = page.locator(".forks > .fork").nth(0).locator(".forks > .fork");
await expect(stack).toHaveCount(3);
});
test("three forks of one pane, one forked again: [ and ] move between them, q closes a fork, and the last but one leaves a plain trail", async ({ page }) => {
await open(page);
await keys(page, "l l l Shift+Enter j Shift+Enter j Shift+Enter");
await keys(page, "l Shift+Enter j Shift+Enter"); // into Generation on demand, and fork from it too
expect(await tree(page)).toEqual([
"Infinispand",
[["*", ["Expansion by depth", ["Levels of a node", "Pre-generated depth", ["*", ["Generation on demand", ["Deepening a leaf", ["*", "Expanding a selection"]]]]]]]],
]);
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(3);
await expect(page.locator(".strip > .forks > .fork").nth(2).locator(".forks > .fork")).toHaveCount(2);
await keys(page, "]");
await expect(page.locator(".status .message")).toContainText("No fork below");
// Up, row by row, in the order they are drawn: the nearest fork first.
await keys(page, "[");
expect((await trail(page)).at(-1)).toBe("Deepening a leaf");
expect(await focusedTitle(page)).toBe("Deepening a leaf");
await keys(page, "[");
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Pre-generated depth"]);
expect(await focusedTitle(page)).toBe("Pre-generated depth");
await keys(page, "[");
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
await keys(page, "[");
await expect(page.locator(".status .message")).toContainText("No fork above");
// Down again; back in a fork, the focus is where it was left.
await keys(page, "] ]");
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand", "Deepening a leaf"]);
expect(await focusedTitle(page)).toBe("Deepening a leaf");
// q at the end of a fork closes that fork; the other stays, as a plain trail.
await keys(page, "q");
expect(await tree(page)).toEqual([
"Infinispand",
[["*", ["Expansion by depth", ["Levels of a node", "Pre-generated depth", ["*", ["Generation on demand", [["*", "Expanding a selection"]]]]]]]],
]);
// In a fork with panes right of the one being read, q closes those, as it always has.
await keys(page, "h");
expect(await focusedTitle(page)).toBe("Generation on demand");
await keys(page, "q");
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand"]);
// With nothing right of it, the whole fork.
await keys(page, "q");
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", ["Levels of a node", ["*", "Pre-generated depth"]]]]]]);
await keys(page, "[ q");
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", [["*", "Pre-generated depth"]]]]]]);
await expect(page.locator(".forks")).toHaveCount(0);
await expect(page.locator(".strip:not(.forked) > .pane")).toHaveCount(3);
await keys(page, "]");
await expect(page.locator(".status .message")).toContainText("No forks open");
});
test("many forks: the rows scroll down with the focused one in view; a reload brings the tree back", async ({ page }) => {
await open(page);
await keys(page, "j Shift+Enter");
for (let i = 0; i < 5; i++) await keys(page, "j Shift+Enter");
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(6);
const strip = page.locator(".strip");
expect(await strip.evaluate((el) => el.scrollHeight > el.clientHeight + 100)).toBe(true);
// Each row is a third of the strip's height; the last, focused, is in view, and the first pane stays at the top.
const h = await strip.evaluate((el) => el.clientHeight);
const rowH = (await page.locator(".forks > .fork").nth(2).boundingBox())!.height;
expect(Math.abs(rowH - Math.floor(h / 3))).toBeLessThanOrEqual(2);
await expect.poll(() => inView(page, ".forks > .fork.on")).toBe(true);
await expect.poll(() => strip.evaluate((el) => el.scrollTop)).toBeGreaterThan(100);
const first = await page.locator(".strip > .pane").first().boundingBox();
const sbox = (await strip.boundingBox())!;
expect(Math.abs(first!.y - sbox.y)).toBeLessThanOrEqual(1);
// Up to the first fork: the strip scrolls back.
await keys(page, "[ [ [ [ [");
await expect.poll(() => inView(page, ".forks > .fork.on")).toBe(true);
await expect.poll(() => strip.evaluate((el) => el.scrollTop)).toBeLessThan(5);
const before = await tree(page);
const was = await trail(page);
await page.reload();
await page.waitForSelector(".strip > .pane");
expect(await tree(page)).toEqual(before);
expect(await trail(page)).toEqual(was);
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(6);
expect((await columns(page))[4]).toHaveLength(2);
});
test("a fork whose node is deleted closes, and the others stay", async ({ page, request }) => {
@@ -271,30 +526,41 @@ test("a fork whose node is deleted closes, and the others stay", async ({ page,
const kids = await childTitles(page, "Expansion by depth");
for (let i = 1; i < kids.indexOf("A section to delete"); i++) await keys(page, "j");
await keys(page, "j Shift+Enter");
expect(await forkRows(page)).toEqual([["Levels of a node"], ["A section to delete"]]);
await keys(page, "[");
expect((await columns(page))[2]).toEqual(["Levels of a node", "A section to delete"]);
await page.locator(".pane .row", { hasText: "Levels of a node" }).first().click();
const id = await state(page, (s) => (Object.values(s.snap.nodes) as any[]).find((n) => n.title === "A section to delete").id);
const res = await request.post("/api/ops", { data: { author: "another", message: "Delete it", ops: [{ op: "delete", id }] } });
expect(res.ok()).toBe(true);
// The fork that was not focused goes; the focused one stays, now a plain trail.
await expect.poll(() => page.locator(".forks").count()).toBe(0);
await expect.poll(async () => (await columns(page))[2]).toEqual(["Levels of a node"]);
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
});
test("a window too short for rows shows only the focused branch, and says which fork it is and how to switch", async ({ page }) => {
test("a window too short to share a column folds it at once: the focused pane open, the others tabs", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 480 });
await open(page);
await keys(page, "l l l Shift+Enter j Shift+Enter");
await expect(page.locator(".forks")).toHaveCount(0);
await expect(page.locator(".strip > .pane")).toHaveCount(3);
await expect(page.locator(".fork-note")).toContainText("fork 2 of 2");
await keys(page, "[");
await expect(page.locator(".fork-note")).toContainText("fork 1 of 2");
expect((await trail(page)).at(-1)).toBe("Levels of a node");
// With room again, the rows come back.
let b = await boxes(page);
expect(b["Levels of a node"].tab).toBe(true);
expect(b["Pre-generated depth"].tab).toBe(false);
// With room again, they share the column.
await page.setViewportSize({ width: 1920, height: 1080 });
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
await expect(page.locator(".fork-note")).toHaveCount(0);
await expect.poll(async () => (await boxes(page))["Levels of a node"].tab).toBe(false);
b = await boxes(page);
expect(b["Pre-generated depth"].tab).toBe(false);
});
test("many forks: a reload brings the forest back", async ({ page }) => {
await open(page);
await keys(page, "j Shift+Enter");
for (let i = 0; i < 5; i++) await keys(page, "j Shift+Enter");
expect((await columns(page))[1]).toHaveLength(6);
const before = await tree(page);
const was = await trail(page);
await page.reload();
await page.waitForSelector(".strip .pane");
expect(await tree(page)).toEqual(before);
expect(await trail(page)).toEqual(was);
expect((await columns(page))[1]).toHaveLength(6);
});
test("in the column a modified open is a plain open, and the status line says why once", async ({ page }) => {
+4 -1
View File
@@ -3,7 +3,7 @@
* 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
* words; the articles are the mock
* words, links on the screenshot's cells; the articles are the mock
* Wikipedia's fixtures in server/wikiMock.ts).
*/
import { writeFileSync } from "node:fs";
@@ -88,6 +88,7 @@ export async function seedLinks(request: APIRequestContext) {
const separate = find(s, "octopus-minds", "A separate experiment");
const ancestor = find(s, "octopus-minds", "A separate experiment", "The common ancestor");
const programs = find(s, "what-a-proof-is", "Proof assistants", "Proofs as programs");
const kinds = find(s, "the-eukaryotic-cell", "Two kinds of cell");
const ops = [
{ op: "create", parent: recursion, kind: "note", quote: "fixed-point combinator", ref: W("Fixed-point combinator") },
{ op: "update", id: noteOn(s, recursion, "lambda calculus"), ref: W("Lambda calculus") },
@@ -101,6 +102,8 @@ export async function seedLinks(request: APIRequestContext) {
{ op: "create", parent: ancestor, kind: "note", quote: "The camera-like eye", ref: W("Cephalopod") },
{ op: "create", parent: programs, kind: "note", quote: "a function turning proofs", ref: W("Lambda calculus") },
{ op: "create", parent: programs, kind: "note", quote: "Several of the leading systems", ref: { kind: "node", id: recursion, doc: "fixed-points", path: ["Recursion without names"] } },
{ op: "create", parent: kinds, kind: "note", quote: "Eukaryotes", ref: W("Eukaryote") },
{ op: "create", parent: kinds, kind: "note", quote: "Bacteria", ref: W("Bacteria") },
];
const res = await request.post("/api/ops", { data: { author: "linker", message: "Seed links for the link tests", ops } });
if (!res.ok()) throw new Error(`seeding links failed: ${res.status()} ${await res.text()}`);
+3 -3
View File
@@ -10,7 +10,7 @@ import { command, focusedTitle, jump, keys, seedLinks, selected, settle, state,
/** The panes' titles, left to right: a node's title, or W:article for a Wikipedia pane. */
const trail = (page: Page) =>
state(page, (s) => s.trail.map((p: any) => (p.kind === "node" ? s.snap.nodes[p.id].title || s.snap.nodes[p.id].anchors[0]?.text : `W:${p.title}${p.sec ? `#${p.sec}` : ""}`)));
const panes = (page: Page) => page.locator(".strip > .pane");
const panes = (page: Page) => page.locator(".strip .pane");
/** Tab through the focused section's marked spans until the selection is these words. */
async function tabTo(page: Page, words: string) {
@@ -30,7 +30,7 @@ async function column(page: Page, path = "/doc/fixed-points") {
async function wide(page: Page, path = "/doc/fixed-points") {
await page.setViewportSize({ width: 1920, height: 1080 });
await page.goto(path);
await page.waitForSelector(".strip > .pane");
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. */
@@ -174,7 +174,7 @@ test("panes: Tab and Enter open an article in the next pane; its sections open a
for (let i = 0; i < 4 && (await state(page, (s) => s.selectedText())) !== "Alonzo Church"; i++) await keys(page, "Tab");
await keys(page, "Enter");
await expect(panes(page).last().locator(".wiki-head h2")).toHaveText("Alonzo Church");
const spine = page.locator(".wiki-pane[data-covered] .spine").first();
const spine = page.locator(".col[data-covered] .wiki-pane .spine").first();
await expect(spine.locator(".wmark")).toHaveText("W");
expect(await spine.evaluate((el) => getComputedStyle(el).backgroundColor)).not.toBe(await page.locator(".pane.root .spine").evaluate((el) => getComputedStyle(el).backgroundColor));
});
+3 -3
View File
@@ -325,14 +325,14 @@ test("the : commands do the same", async ({ page }) => {
test("the menu works in panes and at phone width", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await open(page, "/doc/infinite-expand");
await expect(page.locator(".strip > .pane")).toHaveCount(2); // the library, and the document
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 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")).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 });
+37 -29
View File
@@ -10,9 +10,9 @@ import { command, focusedTitle, idle, jump, keys, settle, state, writeReport, ty
/** Each pane's title and box, left to right. */
const panes = (page: Page) =>
page.evaluate(() =>
[...document.querySelectorAll<HTMLElement>(".strip > .pane")].map((p) => {
[...document.querySelectorAll<HTMLElement>(".strip .pane")].map((p) => {
const r = p.getBoundingClientRect();
return { title: p.querySelector(".pane-head h2, .top h1")?.textContent ?? "", left: r.left, right: r.right, width: r.width, covered: p.hasAttribute("data-covered") };
return { title: p.querySelector(".pane-head h2, .top h1")?.textContent ?? "", left: r.left, right: r.right, width: r.width, covered: !!p.closest(".col")?.hasAttribute("data-covered") };
}),
);
const paneTitles = async (page: Page) => (await panes(page)).map((p) => p.title);
@@ -20,12 +20,12 @@ const nodeId = (page: Page, title: string) => page.evaluate((t) => (Object.value
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.waitForSelector(".strip > .pane");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
// The library pane and the document's; hoisting makes the document the first.
await expect(page.locator(".strip > .pane")).toHaveCount(2);
await expect(page.locator(".strip .pane")).toHaveCount(2);
await page.keyboard.press("z");
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
}
test.use({ viewport: { width: 1920, height: 1080 } });
@@ -35,7 +35,7 @@ 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 }) => {
await page.goto("/");
await page.waitForSelector(".strip > .pane");
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
@@ -48,7 +48,7 @@ test("the library is the first pane, and a document opens in the next; reload an
expect(third).toHaveLength(3);
await expect(page).toHaveURL(/\/doc\/a-mind-made-of-text\/\d+%40\d+$/);
await page.reload();
await page.waitForSelector(".strip > .pane");
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");
@@ -64,27 +64,27 @@ test("the library is the first pane, and a document opens in the next; reload an
test("auto shows panes at 1920 px and one column at 1440; v and /view switch", async ({ page }) => {
await open(page);
await expect(page.locator(".app.view-panes .strip > .pane")).toHaveCount(1);
await expect(page.locator(".app.view-panes .strip .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane.root h1")).toHaveText("Infinispand");
await page.setViewportSize({ width: 1440, height: 900 });
await expect(page.locator(".strip")).toHaveCount(0);
await expect(page.locator("article > .outline > .node").first()).toBeVisible();
await page.setViewportSize({ width: 1920, height: 1080 });
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
await keys(page, "v");
await expect(page.locator(".strip")).toHaveCount(0);
await expect(page.locator(".status .message")).toContainText("one column");
await keys(page, "v");
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
await expect(page.locator(".status .message")).toContainText("panes");
await command(page, "/view column");
await expect(page.locator(".strip")).toHaveCount(0);
expect(await state(page, (s) => s.settings.view)).toBe("column");
await command(page, "/view auto");
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
// The setting is remembered.
await page.reload();
await page.waitForSelector(".strip > .pane");
await page.waitForSelector(".strip .pane");
expect(await page.evaluate(() => JSON.parse(localStorage.getItem("ie:settings")!).view)).toBe("auto");
});
@@ -92,7 +92,7 @@ test("opening three levels deep gives four panes left to right; h moves back lef
await open(page);
// l: first child · l: open it · l: its first child · j j · l open · l first child · l open
await keys(page, "l l l j j l l l");
await expect(page.locator(".strip > .pane")).toHaveCount(4);
await expect(page.locator(".strip .pane")).toHaveCount(4);
const ps = await panes(page);
expect(ps.map((p) => p.title)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand", "Deepening a leaf"]);
for (let i = 1; i < ps.length; i++) expect(ps[i].left).toBeGreaterThan(ps[i - 1].left);
@@ -100,7 +100,7 @@ test("opening three levels deep gives four panes left to right; h moves back lef
await expect(page.locator(".pane .node.showing > .row")).toHaveText(["Expansion by depth", "Generation on demand", "Deepening a leaf"].map((t) => new RegExp(t)));
// Moving back left closes nothing: the trail stays as it was.
await keys(page, "h");
await expect(page.locator(".strip > .pane")).toHaveCount(4);
await expect(page.locator(".strip .pane")).toHaveCount(4);
expect(await focusedTitle(page)).toBe("Generation on demand");
await keys(page, "h");
expect(await focusedTitle(page)).toBe("Expansion by depth");
@@ -108,13 +108,21 @@ test("opening three levels deep gives four panes left to right; h moves back lef
// And forward again along the same trail.
await keys(page, "l");
expect(await focusedTitle(page)).toBe("Levels of a node");
await expect(page.locator(".strip > .pane")).toHaveCount(4);
// q closes the panes right of the one being read; again, that one.
await keys(page, "h q");
await expect(page.locator(".strip .pane")).toHaveCount(4);
// q closes the active pane (the one holding the focus, under the heavy rule) and every pane opened from it; the focus goes back to the row it was opened from.
await keys(page, "j j l");
expect(await focusedTitle(page)).toBe("Deepening a leaf");
await expect(page.locator(".pane.active .pane-head h2")).toHaveText("Generation on demand");
await keys(page, "q");
expect(await paneTitles(page)).toEqual(["Infinispand", "Expansion by depth"]);
expect(await focusedTitle(page)).toBe("Generation on demand");
await keys(page, "q");
expect(await paneTitles(page)).toEqual(["Infinispand"]);
expect(await focusedTitle(page)).toBe("Expansion by depth");
// The first pane stays.
await keys(page, "q");
expect(await paneTitles(page)).toEqual(["Infinispand"]);
await expect(page.locator(".status .message")).toContainText("first pane stays");
});
test("j and k move among siblings, and the strip follows", async ({ page }) => {
@@ -122,7 +130,7 @@ test("j and k move among siblings, and the strip follows", async ({ page }) => {
await keys(page, "j"); // from the top: its first child
expect(await focusedTitle(page)).toBe("Expansion by depth");
await jump(page, "Levels of a node");
await expect(page.locator(".strip > .pane")).toHaveCount(2);
await expect(page.locator(".strip .pane")).toHaveCount(2);
await keys(page, "j");
expect(await focusedTitle(page)).toBe("Pre-generated depth");
await keys(page, "l"); // open it: its pane appears
@@ -146,7 +154,7 @@ test("a pre-generated note opened in a pane is set inside the pane", async ({ pa
await open(page);
await jump(page, "Expansion by depth");
await keys(page, "l Tab Enter");
const pane = page.locator(".strip > .pane").nth(1);
const pane = page.locator(".strip .pane").nth(1);
const note = pane.locator(".sidenote").first();
await expect(note).toBeVisible();
const [n, p, body] = await Promise.all([note.boundingBox(), pane.boundingBox(), pane.locator(".pane-head").boundingBox()]);
@@ -180,7 +188,7 @@ test("in panes everything is reachable with the mouse: rows, headings, marked sp
await page.locator(".pane .row", { hasText: "Borrowed from Gwern" }).click();
await page.locator(".pane .row", { hasText: "Typography" }).click();
// Dragging across a pane's text makes that range the focus.
const para = page.locator(".strip > .pane").last().locator(".para").first();
const para = page.locator(".strip .pane").last().locator(".para").first();
const box = (await para.boundingBox())!;
await page.mouse.move(box.x + 6, box.y + 12);
await page.mouse.down();
@@ -196,7 +204,7 @@ test("in panes everything is reachable with the mouse: rows, headings, marked sp
test("past the viewport, earlier panes become spines; a click on one brings it back", async ({ page }) => {
await open(page);
await keys(page, "l l l j j l l l");
await expect(page.locator(".strip > .pane")).toHaveCount(4);
await expect(page.locator(".strip .pane")).toHaveCount(4);
// The focused pane, and its parent with the marked row, end up fully in view.
await expect.poll(async () => {
const ps = await panes(page);
@@ -205,26 +213,26 @@ test("past the viewport, earlier panes become spines; a click on one brings it b
const strip = page.locator(".strip");
expect(await strip.evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(true);
// The root has slid under the rest and shows as a spine, its title set vertically.
const spine = page.locator('.pane[data-covered] .spine').first();
const spine = page.locator('.col[data-covered] .spine').first();
await expect(spine).toHaveText("Infinispand");
await expect.poll(() => spine.evaluate((el) => getComputedStyle(el).opacity)).toBe("1");
expect(await spine.locator("span").evaluate((el) => getComputedStyle(el).writingMode)).toBe("vertical-rl");
expect(await spine.locator(".spine-title").evaluate((el) => getComputedStyle(el).writingMode)).toBe("vertical-rl");
const box = (await spine.boundingBox())!;
expect(box.x).toBeGreaterThanOrEqual(0);
expect(box.width).toBeLessThan(60);
await spine.click();
expect(await focusedTitle(page)).toBe("Infinispand");
// The trail stays; the strip slides back to show the first pane whole.
await expect(page.locator(".strip > .pane")).toHaveCount(4);
await expect(page.locator(".strip .pane")).toHaveCount(4);
await expect.poll(async () => (await panes(page))[0].left).toBe(0);
await expect(page.locator(".pane[data-covered]")).toHaveCount(0);
await expect(page.locator(".col[data-covered]")).toHaveCount(0);
});
test("generation in a pane: a note on a sentence streams in; a leaf gets sections as rows", async ({ page }) => {
await open(page);
await jump(page, "Why it ends");
await keys(page, "l i j e");
const last = page.locator(".strip > .pane").last();
const last = page.locator(".strip .pane").last();
await expect(last.locator(".pane-head h2")).toHaveText("Why it ends");
await expect(last.locator(".sidenote.pending")).toBeVisible();
await idle(page);
@@ -236,7 +244,7 @@ test("generation in a pane: a note on a sentence streams in; a leaf gets section
const pane = page.locator(`.pane[data-pane="${await nodeId(page, "Downward: rendered children")}"]`);
await expect(pane.locator(".rows .row")).toHaveText([/First part of Downward: rendered children/, /Second part of Downward: rendered children/]);
await keys(page, "l l"); // into the new section, and open it: a fifth pane
await expect(page.locator(".strip > .pane")).toHaveCount(5);
await expect(page.locator(".strip .pane")).toHaveCount(5);
expect((await paneTitles(page)).at(-1)).toBe("First part of Downward: rendered children");
});
@@ -249,7 +257,7 @@ test("editing in a pane: c, type, Esc", async ({ page }) => {
await page.keyboard.press("Control+a");
await page.keyboard.type("Rewritten in a pane.");
await page.keyboard.press("Escape");
await expect(page.locator(".strip > .pane").last().locator(".body").first()).toHaveText("Rewritten in a pane.");
await expect(page.locator(".strip .pane").last().locator(".body").first()).toHaveText("Rewritten in a pane.");
expect(await state(page, (s) => s.snap.nodes[s.focus.node].body)).toBe("Rewritten in a pane.");
// r renames at the head of the pane.
await keys(page, "r");
@@ -292,7 +300,7 @@ test("keypress → paint stays within the 50 ms budget in panes", async ({ page
test("only the strip scrolls sideways, and nothing hides behind the status line", async ({ page }) => {
await open(page);
await keys(page, "l l l j j l l l");
await expect(page.locator(".strip > .pane")).toHaveCount(4);
await expect(page.locator(".strip .pane")).toHaveCount(4);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth && document.body.scrollWidth <= window.innerWidth)).toBe(true);
expect(await page.evaluate(() => (window.scrollX, document.scrollingElement!.scrollLeft))).toBe(0);
expect(await page.locator(".strip").evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(true);
+2 -2
View File
@@ -245,11 +245,11 @@ test("Tab then Enter on an article that is still loading go to its first link on
await keys(page, "Tab");
expect(await selected(page)).toBe("Hoyle state");
await keys(page, "Enter");
await expect(page.locator(".strip > .pane").last().locator(".wiki-wait")).toBeVisible();
await expect(page.locator(".strip .pane").last().locator(".wiki-wait")).toBeVisible();
await keys(page, "Tab Enter");
await expect(page.locator(".status .message")).toContainText("still loading");
// When it arrives, the Tab goes to its first link and the Enter opens that.
await expect(page.locator(".strip > .pane").last().locator(".wiki-head h2")).toHaveText("Carbon-12", { timeout: 10_000 });
await expect(page.locator(".strip .pane").last().locator(".wiki-head h2")).toHaveText("Carbon-12", { timeout: 10_000 });
});
test("keypress → paint stays within a frame while suggestions are on screen and scans run after edits", async ({ page }) => {
+1 -1
View File
@@ -100,7 +100,7 @@ test("a library of over 5,000 nodes in 100 more documents: keypress → paint an
await page.setViewportSize({ width: 1920, height: 1080 });
await page.goto("/");
await ready(page);
await expect(page.locator(".strip > .pane")).toHaveCount(1);
await expect(page.locator(".strip .pane")).toHaveCount(1);
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
for (let i = 0; i < 40; i++) await paced(page, "j");
for (let i = 0; i < 6; i++) await paced(page, "l l l j l i j Escape h h h j");