Curves draw the rules they land in; tabs for folded and scrolled panes; peek on both axes
- A curve runs on along the rule under its pane's title (any kind of pane: section, page, article, article section) and draws it, the pane's own rule left out, so the two are one stroke, set on device pixels (the curves' layer measured from its whole pixel; a hairline is one device pixel). - The landing: the title's rule when it shows, else the tab's foot, whether the pane is folded down its column or scrolled past its title. A pane scrolled past its title shows its tab at its top (an observer on the rule, nothing per scroll or key). - A curve out of a folded pane whose source is out of sight leaves from the end of its tab's foot, solid, the foot drawn with it; the stacked pane's own top edge under it is left out. - Colours: the panes' and curves' colour came out as the neutral ink on every curve (a selector outweighed the colour's); the neutral is nearer the text's ink. Colour depends on the tree only. - A covered pane peeks out across and down at once, and stays out while the wheel scrolls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
66d25eea7f
commit
8f6afaecdd
6 files changed
+643
-94
No files matched your search
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* Fork colours and the lines they run along, in the panes view: every kind of pane's title rule is
|
||||
* drawn by the curve into it, in the pane's colour, as one stroke (measured in the pixels, at several
|
||||
* device pixel ratios); a pane folded or scrolled past its title shows its tab and the curve lands in
|
||||
* the tab's foot, and a curve out of a folded pane leaves from that foot; a pane's colour depends on
|
||||
* the forest only; a covered pane peeks out across and down at once, and the wheel scrolls it; the
|
||||
* selection bar sits at its pane's level. Same build, mock model and mock Wikipedia as the others.
|
||||
*/
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { autoLayout, pixels, seedLinks, settle, state } from "./helpers";
|
||||
|
||||
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
|
||||
const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
|
||||
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
async function still(page: Page) {
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
new Promise((r) => {
|
||||
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
|
||||
const x = at();
|
||||
setTimeout(() => r(at() === x), 250);
|
||||
}),
|
||||
);
|
||||
await frames(page);
|
||||
}
|
||||
/** Click a row (or words) in a pane, as the mouse would, wherever the pane is (a covered one too). */
|
||||
async function open(page: Page, inPane: string, text: string, sel = ".row") {
|
||||
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
|
||||
await still(page);
|
||||
}
|
||||
async function library(page: Page) {
|
||||
await autoLayout(page);
|
||||
await page.goto("/");
|
||||
await page.waitForSelector(".strip .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every curve, with where it ends and what it lands in: its stroke's colour (RGB), its pane's
|
||||
* colour (RGB of the pane's --hue), whether the pane's own rule is left to the curve, and the rule's
|
||||
* and the tab foot's place on screen.
|
||||
*/
|
||||
const lines = (page: Page) =>
|
||||
page.evaluate(() => {
|
||||
const cx = document.createElement("canvas").getContext("2d")!;
|
||||
const rgb = (c: string) => {
|
||||
cx.clearRect(0, 0, 1, 1);
|
||||
cx.fillStyle = "#000";
|
||||
cx.fillStyle = c;
|
||||
cx.fillRect(0, 0, 1, 1);
|
||||
return [...cx.getImageData(0, 0, 1, 1).data.slice(0, 3)];
|
||||
};
|
||||
const svg = document.querySelector<SVGSVGElement>(".curves")!.getBoundingClientRect();
|
||||
const box = { left: Math.round(svg.left), top: Math.round(svg.top) };
|
||||
return [...document.querySelectorAll<SVGPathElement>(".curves path:not(.foot)")].map((p) => {
|
||||
const pe = document.querySelector<HTMLElement>(`.pane[data-tid="${p.dataset.to}"]`)!;
|
||||
const a = p.getPointAtLength(0);
|
||||
const b = p.getPointAtLength(p.getTotalLength());
|
||||
const head = pe.querySelector<HTMLElement>(":scope > .pane-scroll > .pane-body > .pane-head, :scope > .pane-scroll > .pane-body > .top h1, :scope > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head");
|
||||
const hr = head?.getBoundingClientRect();
|
||||
const pr = pe.getBoundingClientRect();
|
||||
const from = document.querySelector<HTMLElement>(`.pane[data-tid="${p.dataset.from}"]`)!.getBoundingClientRect();
|
||||
return {
|
||||
from: Number(p.dataset.from),
|
||||
to: Number(p.dataset.to),
|
||||
cls: p.getAttribute("class") ?? "",
|
||||
hue: p.dataset.hue ?? null,
|
||||
paneHue: pe.dataset.hue ?? null,
|
||||
kind: pe.classList.contains("wiki-pane") ? (pe.querySelector(".wiki-head .wsub") ? "article section" : "article") : pe.querySelector(":scope > .pane-scroll > .pane-body > .top") ? "page" : "section",
|
||||
stroke: rgb(getComputedStyle(p).stroke),
|
||||
colour: rgb(getComputedStyle(pe).getPropertyValue("--hue")),
|
||||
ownRule: head ? rgb(getComputedStyle(head).borderBottomColor) : null,
|
||||
ownRuleAlpha: head ? getComputedStyle(head).borderBottomColor : null,
|
||||
ruled: pe.dataset.ruled ?? "",
|
||||
focused: !!head?.closest(".focused"),
|
||||
scrolled: pe.hasAttribute("data-scrolled"),
|
||||
folded: pe.hasAttribute("data-covered"),
|
||||
start: { x: a.x + box.left, y: a.y + box.top },
|
||||
end: { x: b.x + box.left, y: b.y + box.top },
|
||||
rule: hr && { left: hr.left, right: hr.right, y: hr.bottom - 0.5 },
|
||||
foot: { y: pr.top + 29.5, left: pr.left, right: pr.right },
|
||||
fromFoot: { y: from.top + 29.5, right: from.right },
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test.use({ viewport: { width: 1920, height: 1080 }, colorScheme: "dark" });
|
||||
test.describe.configure({ mode: "serial" });
|
||||
test.beforeAll(async ({ request }) => {
|
||||
await seedLinks(request);
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
await context.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
});
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
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 }) => {
|
||||
await library(page);
|
||||
for (const t of ["The tides", "Fixed points"]) await open(page, "Library", t);
|
||||
const seen = new Set<string>();
|
||||
const check = async () => {
|
||||
for (const l of await lines(page)) {
|
||||
if (!l.ruled.includes("head")) continue;
|
||||
seen.add(l.kind);
|
||||
expect(l.hue, `${l.kind} ${l.to}`).toBe(l.paneHue);
|
||||
expect(alike(l.stroke, l.colour), `${l.kind} ${l.to}: ${l.stroke} ${l.colour}`).toBe(true);
|
||||
// The curve runs on along the rule to its end, at its height; the pane's own rule is left out.
|
||||
expect(near(l.end.y, l.rule!.y), `${l.kind} y`).toBe(true);
|
||||
expect(near(l.end.x, l.rule!.right, 1.5), `${l.kind} x ${l.end.x} ${l.rule!.right}`).toBe(true);
|
||||
expect(l.ownRuleAlpha).toMatch(/rgba\(.*, 0\)|transparent/);
|
||||
}
|
||||
};
|
||||
await check();
|
||||
await open(page, "Fixed points", "Recursion without names");
|
||||
await check();
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
// The article's head holds the focus now (its rule is then the text's ink): put the focus back in the section.
|
||||
await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
await check();
|
||||
await open(page, "Fixed-point combinator", "Y combinator", ".wrow .row");
|
||||
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"]);
|
||||
// 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"));
|
||||
expect(await pane(page, "Fixed points").getAttribute("data-hue")).not.toBeNull();
|
||||
});
|
||||
|
||||
test("a pane's colour is a function of the forest: unchanged by focus, a source scrolled out of sight, folding to a tab, or which way its rule is drawn", async ({ page }) => {
|
||||
await library(page);
|
||||
for (const t of ["Infinispand", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "Infinispand", "Expansion by depth");
|
||||
await open(page, "Fixed points", "The idea itself");
|
||||
const colourOf = async () => Object.fromEntries((await lines(page)).map((l) => [l.to, { stroke: l.stroke, colour: l.colour, hue: l.paneHue }]));
|
||||
const before = await colourOf();
|
||||
const same = async (what: string) => {
|
||||
for (const l of await lines(page)) {
|
||||
if (!before[l.to]) continue;
|
||||
expect(l.paneHue, `${what}: ${l.to}`).toBe(before[l.to].hue);
|
||||
expect(alike(l.stroke, before[l.to].colour), `${what}: ${l.to} curve`).toBe(true);
|
||||
// A rule the pane draws itself (no curve lands in it) is in the same colour.
|
||||
if (!l.ruled.includes("head") && l.ownRule && !l.ownRuleAlpha!.startsWith("rgb(241")) expect(alike(l.ownRule, before[l.to].colour), `${what}: ${l.to} own rule ${l.ownRule}`).toBe(true);
|
||||
}
|
||||
};
|
||||
for (const l of await lines(page)) expect(alike(l.stroke, l.colour)).toBe(true);
|
||||
// Focus on the other fork.
|
||||
await pane(page, "Expansion by depth").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
await same("focus moved");
|
||||
// The source row scrolled out of its pane: the curve is held at the pane's edge, dotted, and the pane draws its own rule.
|
||||
const fixed = pane(page, "Fixed points").locator(".pane-scroll");
|
||||
await fixed.evaluate((el) => (el.scrollTop = el.scrollHeight));
|
||||
await still(page);
|
||||
const idea = await tid(page, "The idea itself");
|
||||
const lost = (await lines(page)).find((l) => l.to === idea)!;
|
||||
expect(lost.cls).toContain("lost");
|
||||
expect(lost.ruled).toBe("");
|
||||
await same("source scrolled out");
|
||||
await fixed.evaluate((el) => (el.scrollTop = 0));
|
||||
await still(page);
|
||||
await same("source back");
|
||||
// Folded to tabs in a short window, and back.
|
||||
await page.setViewportSize({ width: 1920, height: 520 });
|
||||
await still(page);
|
||||
await same("folded");
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await still(page);
|
||||
await same("unfolded");
|
||||
});
|
||||
|
||||
test("the join of a curve and the rule it runs into is one stroke, on device pixels, at ratios 1, 1.25, 1.5, 2 and zoom 90 and 110 %", async ({ browser, request }) => {
|
||||
void request;
|
||||
for (const dpr of [1, 1.25, 1.5, 2, 0.9, 1.1]) {
|
||||
const ctx = await browser.newContext({ viewport: { width: 1920, height: 760 }, deviceScaleFactor: dpr, colorScheme: "dark" });
|
||||
await ctx.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
const page = await ctx.newPage();
|
||||
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");
|
||||
await still(page);
|
||||
const ls = await lines(page);
|
||||
const shot = pixels(await page.screenshot());
|
||||
const wd = Math.max(1, Math.floor(dpr + 0.01));
|
||||
const bg = (x: number, y: number) => shot.px(Math.round(x * dpr), Math.round((y - 8) * dpr));
|
||||
/** The device rows the line covers at x, near y: [row, brightness above the ground]. */
|
||||
const column = (x: number, y: number) => {
|
||||
const g = bg(x, y);
|
||||
const out: [number, number][] = [];
|
||||
for (let r = Math.floor((y - 3) * dpr); r <= Math.ceil((y + 3) * dpr); r++) {
|
||||
const p = shot.px(Math.round(x * dpr), r);
|
||||
const d = p.reduce((s, v, i) => s + Math.abs(v - g[i]), 0);
|
||||
if (d > 9) out.push([r, Math.round(d / 3)]);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
/** The same rows, as bright but for a unit or two of rounding. */
|
||||
const sameLine = (a: [number, number][], b: [number, number][]) => a.length === b.length && a.every(([r, v], i) => r === b[i][0] && Math.abs(v - b[i][1]) <= 2);
|
||||
const joins = ls.filter((l) => l.ruled.includes("head"));
|
||||
expect(joins.length, `dpr ${dpr}`).toBeGreaterThan(0);
|
||||
for (const l of joins) {
|
||||
const x0 = Math.max(l.rule!.left, l.end.x - 400);
|
||||
// Just inside the rule and further along it: the same rows, the same colour, and as many rows as a hairline has.
|
||||
const a = column(l.rule!.left + 3, l.rule!.y);
|
||||
const b = column((x0 + l.end.x) / 2, l.rule!.y);
|
||||
expect(sameLine(a, b), `dpr ${dpr} rule of ${l.to}: ${JSON.stringify([a, b])}`).toBe(true);
|
||||
expect(a.length, `dpr ${dpr} rows ${JSON.stringify(a)}`).toBe(wd);
|
||||
}
|
||||
// Out of a folded pane's tab: its foot and the curve on from it are one line.
|
||||
const out = ls.find((l) => near(l.start.y, l.fromFoot.y, 1) && l.start.x >= l.fromFoot.right - 3);
|
||||
expect(out, `dpr ${dpr}: a curve out of a tab's foot`).toBeTruthy();
|
||||
const f = column(out!.start.x - 6, out!.start.y);
|
||||
const c = column(out!.start.x + 2, out!.start.y);
|
||||
expect(sameLine(f, c), `dpr ${dpr} foot: ${JSON.stringify([f, c])}`).toBe(true);
|
||||
expect(f.length).toBe(wd);
|
||||
await ctx.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("a pane folded or scrolled past its title shows its tab, and its curve lands in the tab's foot; with its title in sight, in the title's rule", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 760 });
|
||||
await 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 still(page);
|
||||
let ls = await lines(page);
|
||||
let checked = 0;
|
||||
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) {
|
||||
const id = await tid(page, t);
|
||||
const l = ls.find((x) => x.to === id && x.from !== id);
|
||||
// Below the column's foot, a curve stops there, dotted.
|
||||
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 r = p.getBoundingClientRect();
|
||||
const next = (p.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity;
|
||||
const covered = p.hasAttribute("data-covered") || p.hasAttribute("data-scrolled");
|
||||
return h.bottom > r.top + (covered ? 30 : 0) + 4 && h.bottom < Math.min(next, p.parentElement!.getBoundingClientRect().bottom);
|
||||
});
|
||||
const info = JSON.stringify({ end: l.end, rule: l.rule, foot: l.foot, ruled: l.ruled, folded: l.folded, cls: l.cls, visible });
|
||||
if (visible) expect(near(l.end.y, l.rule!.y), `${t} into its title's rule ${info}`).toBe(true);
|
||||
else expect(near(l.end.y, l.foot.y), `${t} into its tab's foot ${info}`).toBe(true);
|
||||
}
|
||||
expect(checked).toBeGreaterThan(1);
|
||||
// A curve out of a folded pane leaves from the right end of its tab's foot, solid.
|
||||
const force = await tid(page, "The force");
|
||||
await expect(pane(page, "The tides")).toHaveAttribute("data-covered", "");
|
||||
ls = await lines(page);
|
||||
const out = ls.find((l) => l.to === force)!;
|
||||
expect(out.cls).not.toContain("lost");
|
||||
expect(near(out.start.y, out.fromFoot.y)).toBe(true);
|
||||
expect(near(out.start.x, out.fromFoot.right, 1.5)).toBe(true);
|
||||
|
||||
// A plain pane scrolled past its title: its tab at its top, the curve into its foot; back up, into the rule again.
|
||||
const sc = pane(page, "The force").locator(".pane-scroll");
|
||||
await sc.evaluate((el) => (el.scrollTop = 300));
|
||||
await expect(pane(page, "The force")).toHaveAttribute("data-scrolled", "");
|
||||
await still(page);
|
||||
expect(await pane(page, "The force").locator(".tabline").evaluate((el) => getComputedStyle(el).opacity)).toBe("1");
|
||||
let l = (await lines(page)).find((x) => x.to === force)!;
|
||||
expect(near(l.end.y, l.foot.y), `scrolled: ${l.end.y} ${l.foot.y}`).toBe(true);
|
||||
expect(l.ruled).toContain("tab");
|
||||
await sc.evaluate((el) => (el.scrollTop = 0));
|
||||
await expect(pane(page, "The force")).not.toHaveAttribute("data-scrolled", "");
|
||||
await still(page);
|
||||
l = (await lines(page)).find((x) => x.to === force)!;
|
||||
expect(near(l.end.y, l.rule!.y)).toBe(true);
|
||||
});
|
||||
|
||||
test("a pane covered across and down peeks out whole on both axes; the wheel scrolls it and it stays out; the selection bar of a pane under it is covered", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 760 });
|
||||
await 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, "Fixed points", "Recursion without names");
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
await still(page);
|
||||
// The documents' column is covered to spines, and folded down: hover the spine of a folded pane in it.
|
||||
const col = pane(page, "The tides").locator("xpath=..");
|
||||
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
||||
const tides = pane(page, "The tides");
|
||||
await expect(tides).toHaveAttribute("data-covered", "");
|
||||
const tb = (await tides.boundingBox())!;
|
||||
const sp = { x: tb.x + 4, y: tb.y - 45, width: 20 };
|
||||
await page.mouse.move(sp.x + sp.width / 2, sp.y + 60);
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
const vp = page.viewportSize()!;
|
||||
const r = (await tides.boundingBox())!;
|
||||
const c = (await col.boundingBox())!;
|
||||
expect(r.width).toBeGreaterThan(600);
|
||||
expect(c.width).toBeGreaterThan(600);
|
||||
expect(r.y).toBeGreaterThanOrEqual(c.y - 1);
|
||||
expect(r.y + r.height).toBeLessThanOrEqual(Math.min(c.y + c.height, vp.height) + 1);
|
||||
// What is under the pointer is that pane, whole: the wheel scrolls its text, and it stays out.
|
||||
await page.mouse.move(r.x + r.width / 2, r.y + r.height / 2);
|
||||
await page.waitForTimeout(250);
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
const before = await tides.locator(".pane-scroll").evaluate((el) => el.scrollTop);
|
||||
await page.mouse.wheel(0, 240);
|
||||
await expect.poll(() => tides.locator(".pane-scroll").evaluate((el) => el.scrollTop)).toBeGreaterThan(before);
|
||||
await frames(page);
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
// Away: back.
|
||||
await page.mouse.move(vp.width - 10, vp.height / 2);
|
||||
await expect(col).not.toHaveAttribute("data-peek", "");
|
||||
|
||||
// The selection bar: shown in its pane; a pane peeking over it covers it.
|
||||
const rec = pane(page, "Recursion without names");
|
||||
// A couple of words at the start of its text, dragged over: the bar sits by them, near the pane's left.
|
||||
const para = (await rec.locator(".pane-body .para").first().boundingBox())!;
|
||||
await page.mouse.move(para.x + 2, para.y + 10);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(para.x + 30, para.y + 10, { steps: 4 });
|
||||
await page.mouse.move(para.x + 60, para.y + 10, { steps: 4 });
|
||||
await page.mouse.up();
|
||||
const bar = page.locator(".selbar");
|
||||
await expect(bar).toBeVisible();
|
||||
expect(await bar.evaluate((el) => !!el.closest(".pane"))).toBe(true);
|
||||
const b = (await bar.boundingBox())!;
|
||||
const at = { x: b.x + b.width / 2, y: b.y + b.height / 2 };
|
||||
expect(await page.evaluate(({ x, y }) => !!document.elementFromPoint(x, y)?.closest(".selbar"), at)).toBe(true);
|
||||
// Peek the documents' column (to the left, covered): it slides out over the pane with the bar.
|
||||
await page.mouse.move(sp.x + sp.width / 2, sp.y + 60);
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
const over = await page.evaluate(({ x, y }) => {
|
||||
const el = document.elementFromPoint(x, y);
|
||||
return { bar: !!el?.closest(".selbar"), peeked: !!el?.closest("[data-peek]") };
|
||||
}, at);
|
||||
const cb = (await col.boundingBox())!;
|
||||
expect(at.x).toBeLessThan(cb.x + cb.width);
|
||||
expect(over).toEqual({ bar: false, peeked: true });
|
||||
expect(await state(page, (s) => s.selectedText())).not.toBeNull();
|
||||
});
|
||||
+15
-12
@@ -301,11 +301,12 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
expect(start.y).toBeLessThan(link.y + link.height);
|
||||
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();
|
||||
// Each runs on into the rule under its pane's title: one line.
|
||||
// Each runs on into the rule under its pane's title and along it (drawing it): one line.
|
||||
for (const t of ["Eukaryote", "Simple cells", "Complex cells"]) {
|
||||
const end = edge("Two kinds of cell", t)[0].b;
|
||||
const r = (await pane(page, t).locator(".wiki-head, .pane-head").first().boundingBox())!;
|
||||
expect(Math.abs(end.x - r.x), t).toBeLessThan(2);
|
||||
expect(end.x, t).toBeGreaterThan(r.x + 100);
|
||||
expect(end.x, t).toBeLessThanOrEqual(r.x + r.width + 1);
|
||||
expect(Math.abs(end.y - (r.y + r.height - 0.5)), t).toBeLessThan(1.5);
|
||||
}
|
||||
await near('.wiki-pane .wiki-text a[data-wiki="Bacteria"]', edge("Eukaryote", "Bacteria")[0].a);
|
||||
@@ -334,8 +335,7 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
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);
|
||||
expect(now.x).toBeGreaterThan(r.x);
|
||||
// And they can be turned off, and on again.
|
||||
await page.keyboard.press(":");
|
||||
await page.keyboard.type("/curves off");
|
||||
@@ -347,7 +347,7 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
await expect.poll(async () => (await curves(page)).length).toBeGreaterThan(3);
|
||||
});
|
||||
|
||||
test("each fork has a colour, shared by its curve and the rule under its title; the first trail is plain ink; /colors off takes them away", async ({ page }) => {
|
||||
test("each fork has a colour, shared by its curve and the rule under its title; a trail keeps its colour, the top node has none; /colors off takes them away", async ({ page }) => {
|
||||
await cells(page);
|
||||
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);
|
||||
@@ -356,17 +356,20 @@ test("each fork has a colour, shared by its curve and the rule under its title;
|
||||
page.locator(`.curves path[data-to="${ids[to]}"]`).evaluate((el) => ({ stroke: getComputedStyle(el).stroke, hue: (el as SVGElement).dataset.hue }));
|
||||
const rule = (t: string) => pane(page, t).locator(".wiki-head, .pane-head").first().evaluate((el) => getComputedStyle(el).borderBottomColor);
|
||||
const hue = (t: string) => pane(page, t).getAttribute("data-hue");
|
||||
// Eukaryote went on from Two kinds of cell, Bacteria from it: the first trail, uncoloured. Simple and Complex cells are forks, each its own colour.
|
||||
for (const t of ["Two kinds of cell", "Eukaryote", "Bacteria"]) expect(await hue(t), t).toBeNull();
|
||||
expect((await curve("Eukaryote")).hue).toBeUndefined();
|
||||
expect(await hue("Simple cells")).not.toBeNull();
|
||||
// The library (the top node) has no colour; the trail down from it one, Eukaryote and Bacteria going on in it. Simple and Complex cells are forks, each its own colour.
|
||||
expect(await pane(page, "Library").getAttribute("data-hue")).toBeNull();
|
||||
for (const t of ["Eukaryote", "Bacteria"]) expect(await hue(t), t).toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Two kinds of cell")).not.toBeNull();
|
||||
expect((await curve("Eukaryote")).hue).toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Simple cells")).not.toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Complex cells")).not.toBe(await hue("Simple cells"));
|
||||
// A curve and its pane's title rule: one colour, off the focused branch (Simple cells) or on it (Complex cells), and the two forks' differ.
|
||||
// The curve draws the rule under its pane's title (the pane's own is left out): one stroke, in the pane's colour.
|
||||
for (const t of ["Simple cells", "Complex cells"]) {
|
||||
expect((await curve(t)).hue).toBe(await hue(t));
|
||||
expect((await curve(t)).stroke, t).toBe(await rule(t));
|
||||
expect(await pane(page, t).getAttribute("data-ruled")).toBe("head");
|
||||
expect(await rule(t)).toBe("rgba(0, 0, 0, 0)");
|
||||
}
|
||||
expect(await rule("Simple cells")).not.toBe(await rule("Complex cells"));
|
||||
expect((await curve("Simple cells")).stroke).not.toBe((await curve("Complex cells")).stroke);
|
||||
expect((await curve("Simple cells")).stroke).not.toBe((await curve("Eukaryote")).stroke);
|
||||
// The active pane's heavy ink rule is as it was.
|
||||
expect(await page.locator(".pane.active").evaluate((el) => getComputedStyle(el, "::after").height)).toBe("3px");
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Wikipedia's fixtures in server/wikiMock.ts).
|
||||
*/
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { inflateSync } from "node:zlib";
|
||||
import type { APIRequestContext, Page } from "@playwright/test";
|
||||
|
||||
/** A keypress → paint timing, as the page records it. */
|
||||
@@ -119,3 +120,40 @@ export async function seedLinks(request: APIRequestContext) {
|
||||
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()}`);
|
||||
}
|
||||
|
||||
/** A screenshot's pixels (a PNG of 8-bit RGB or RGBA, as Playwright writes them): px(x, y) is [r, g, b]. */
|
||||
export function pixels(buf: Buffer): { w: number; h: number; px: (x: number, y: number) => [number, number, number] } {
|
||||
let at = 8;
|
||||
let w = 0;
|
||||
let h = 0;
|
||||
let type = 6;
|
||||
const data: Buffer[] = [];
|
||||
while (at < buf.length) {
|
||||
const len = buf.readUInt32BE(at);
|
||||
const kind = buf.toString("ascii", at + 4, at + 8);
|
||||
const body = buf.subarray(at + 8, at + 8 + len);
|
||||
if (kind === "IHDR") {
|
||||
w = body.readUInt32BE(0);
|
||||
h = body.readUInt32BE(4);
|
||||
type = body[9];
|
||||
} else if (kind === "IDAT") data.push(body);
|
||||
at += 12 + len;
|
||||
}
|
||||
const bpp = type === 6 ? 4 : 3;
|
||||
const raw = inflateSync(Buffer.concat(data));
|
||||
const stride = w * bpp;
|
||||
const out = Buffer.alloc(h * stride);
|
||||
for (let y = 0; y < h; y++) {
|
||||
const f = raw[y * (stride + 1)];
|
||||
for (let i = 0; i < stride; i++) {
|
||||
const x = raw[y * (stride + 1) + 1 + i];
|
||||
const a = i >= bpp ? out[y * stride + i - bpp] : 0;
|
||||
const b = y ? out[(y - 1) * stride + i] : 0;
|
||||
const c = y && i >= bpp ? out[(y - 1) * stride + i - bpp] : 0;
|
||||
const p = a + b - c;
|
||||
const pr = Math.abs(p - a) <= Math.abs(p - b) && Math.abs(p - a) <= Math.abs(p - c) ? a : Math.abs(p - b) <= Math.abs(p - c) ? b : c;
|
||||
out[y * stride + i] = (x + [0, a, b, (a + b) >> 1, pr][f]) & 255;
|
||||
}
|
||||
}
|
||||
return { w, h, px: (x, y) => [out[y * stride + x * bpp], out[y * stride + x * bpp + 1], out[y * stride + x * bpp + 2]] };
|
||||
}
|
||||
Reference in new issue
Block a user