test: failing repro

Refs #1664
This commit is contained in:
sam committed 2026-11-08 23:54:58 +11:00
1 parent 514219b6a5
commit f2d8c997ba
1 file changed
+198
+198
View File
@@ -0,0 +1,198 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import {
availableTabs,
stepsFor,
type EventsStep,
} from "../src/events/tab-selection.ts";
import {
loadEventCounts,
type EventsCountReaders,
type EventsCounts,
} from "../src/events/counts.ts";
/**
* The Events page's one navigation control, as the browser would render it.
*
* There is no DOM in this harness, so the page is read as source and the
* expressions the template binds are evaluated against real values from
* counts.ts and tab-selection.ts. That keeps the assertions about what an
* operator sees -- the label, the chip, the tooltip -- rather than about the
* shape of the markup, as far as the missing renderer allows.
*
* archie-core-xt6b (#1664, #1240): the page used to draw the Capture/Map/Bind
* chain twice, as a numbered `<ol>` strip and again as a `Tabs` list, both
* writing `?tab=`. The strip is gone; what survives is the tab list wearing
* the strip's words. The first two tests below hold that shape still -- one
* control set, one vocabulary -- so a second affordance cannot come back
* unnoticed. The last two cover the count the surviving control shows, which
* counts.ts says is blank rather than zero when its read failed.
*/
const pageSource = readFileSync(
new URL("../src/events/EventsPage.vue", import.meta.url),
"utf8",
);
/** The template half of the page: everything the browser renders. */
function templateOf(source: string): string {
const start = source.indexOf("\n<template>");
assert.ok(start >= 0, "EventsPage.vue has a template");
return source.slice(start);
}
const template = templateOf(pageSource);
/** The per-step control: its attributes and the markup between its tags. */
function stepControl(): { attributes: string; inner: string } {
const match = /<TabsTrigger\b([^>]*)>([\s\S]*?)<\/TabsTrigger/.exec(template);
assert.ok(match, "the Events page draws one TabsTrigger per step");
return { attributes: match[1], inner: match[2] };
}
/** One bound attribute of the step control, as the page writes it. */
function binding(name: string): string {
const match = new RegExp(`:${name}="([^"]*)"`).exec(stepControl().attributes);
assert.ok(match, `the step control binds :${name}`);
return match[1];
}
/** The interpolations inside the step control, in document order: the label
* first, then the count chip. */
function interpolations(): string[] {
return [...stepControl().inner.matchAll(/\{\{([\s\S]*?)\}\}/g)].map((m) => m[1]);
}
/** Runs a template expression the way Vue would for one step and one counts
* object, and returns what it renders as text. */
function render(
expression: string,
counts: EventsCounts,
step: EventsStep,
): string {
const evaluate = new Function(
"counts",
"step",
`return (${expression});`,
) as (c: EventsCounts, s: EventsStep) => unknown;
return String(evaluate(counts, step));
}
/** Readers standing in for api.captures / api.mappings / api.bindings. */
function readers(
overrides: Partial<EventsCountReaders> = {},
): EventsCountReaders {
return {
captures: async () => ({ captures: [{}, {}] }),
mappings: async () => ({ mappings: [{}] }),
bindings: async () => ({ bindings: [] }),
...overrides,
};
}
function stepOf(id: string): EventsStep {
const step = stepsFor(availableTabs(null)).find((s) => s.id === id);
assert.ok(step, `the chain has a ${id} step`);
return step;
}
test("Events draws the chain once, not as a strip above a second control set", () => {
assert.doesNotMatch(
template,
/<ol\b/,
"a numbered <ol> step strip is back above the tab list, so the chain is navigable twice",
);
assert.equal(
(template.match(/<TabsList\b/g) ?? []).length,
1,
"the page draws more than one tab list for the same three panels",
);
assert.equal(
(template.match(/v-for="step in steps"/g) ?? []).length,
1,
"the three steps are rendered by more than one loop",
);
assert.equal(
(template.match(/@update:model-value="show"/g) ?? []).length,
1,
"more than one control writes the ?tab= query parameter",
);
});
test("the chain is one vocabulary: distinct labels, each with a count hint", () => {
const steps = stepsFor(availableTabs(null));
assert.deepEqual(
steps.map((step) => step.id),
["inspector", "mappings", "bindings"],
"the steps no longer follow the ?tab= vocabulary",
);
assert.equal(
new Set(steps.map((step) => step.label)).size,
steps.length,
`two steps share a label: ${steps.map((step) => step.label).join(", ")}`,
);
for (const step of steps) {
assert.ok(step.label.trim(), `the ${step.id} step has no label`);
assert.ok(
step.hint.trim(),
`the ${step.id} step has no hint, so its tooltip cannot say what it counts`,
);
}
});
test("an unreadable count is blank in the chip and in the tooltip, never zero", async () => {
const counts = await loadEventCounts(
readers({
mappings: async () => {
throw new Error("offline");
},
}),
);
assert.equal(
counts.mappings,
undefined,
"precondition: a read that failed leaves its count undefined",
);
const step = stepOf("mappings");
const [, chipExpression] = interpolations();
assert.ok(chipExpression, "the step control shows a count chip");
const chip = render(chipExpression, counts, step);
const tooltip = render(binding("title"), counts, step);
assert.equal(chip, "", "the chip should render an unreadable count blank");
assert.equal(
tooltip.trim(),
step.hint,
`the tooltip reads ${JSON.stringify(tooltip)} for a count that could not be read; counts.ts says an unreadable count is blank, never zero, so the chip shows ${JSON.stringify(chip)} and the tooltip must not claim a number`,
);
assert.doesNotMatch(
tooltip,
/\d/,
`the tooltip shows a number for a count that was never read: ${JSON.stringify(tooltip)}`,
);
});
test("a count that was read still shows, including a zero", async () => {
const readable = await loadEventCounts(
readers({ mappings: async () => ({ mappings: [] }) }),
);
const mappingsStep = stepOf("mappings");
const [, chipExpression] = interpolations();
assert.ok(chipExpression);
assert.equal(render(chipExpression, readable, mappingsStep), "0");
assert.equal(
render(binding("title"), readable, mappingsStep),
`0 ${mappingsStep.hint}`,
"a read that answered with an empty list is a real zero and must still say so",
);
const step = stepOf("inspector");
assert.equal(
render(binding("title"), readable, step),
`2 ${step.hint}`,
"the tooltip drops the count it does have",
);
});