Files
archie/ui/test/config-row.test.js
T
sam fb7fba4232 fix(webui): rebuild the Configuration page layout so values stop colliding
The page had three compounding layout faults, all visible on a wide
screen and all still present after the earlier spacing pass:

  1. .cfg-row used justify-content: space-between on a full-width card,
     so the label sat at the far left and its value at the far right with
     roughly a thousand pixels between them. Reading one pair meant
     tracking across the viewport. The earlier "tighten KV row spacing"
     change reduced vertical padding only, which is why the complaint it
     was meant to answer survived it.
  2. .cfg-value had no min-width: 0, so a long value could not shrink
     inside its flex parent. It overflowed into the Edit button, which is
     why 400 rendered as "40" and 100000000 was clipped mid-number.
  3. The locked-row reason was a flex sibling of that overflowing value,
     so it ran onto the end of the path with no separation, rendering
     ".../archie/work" and "pins the daemon's working layout" as one
     unbroken string.

Replace the flex row with a three-column grid: label, value, actions.
Label and value are adjacent and left-aligned so the eye travels a fixed
short distance at any viewport width; the value column is minmax(0, 1fr)
so it can actually shrink, truncating with an ellipsis and keeping the
full text in a title attribute; actions occupy a reserved column that
nothing can overlap. Secondary text (locked reason, override marker,
validation error) gets its own grid row instead of sharing the value
line. Narrow viewports stack label over value rather than truncating
both to a few characters.

Extract the row renderer into settings/config-row.js. settings.js
imports its own stylesheet, which the node test shim cannot parse, so
the rendering logic was untestable where it sat; this mirrors
tasks/task-row.js. Seven tests now cover the two collision bugs
structurally, asserting on per-child text rather than the row's
flattened string so a future layout change cannot pass by merging the
fields back into one node.

Also stop sharing .cfg-rows with the Workflows "Start work" form. A
class owned by the Configuration page meant restyling Configuration
could silently restyle that form; it is now .wf-form, owned by the
feature that uses it.
2026-08-10 03:00:56 +10:00

95 lines
3.9 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import "./shim.js";
import { row, valueText, parseEdit } from "../src/settings/config-row.js";
// Walks a rendered row and returns the concatenated text of each direct
// child, so a test can assert on the row's *structure* rather than on a
// flattened string. The bugs this file guards against were all cases of
// two fields rendering as one visual run.
function cells(rowEl) {
return rowEl.childNodes.map((child) => text(child));
}
function text(node) {
return node.textContent ?? "";
}
function classOf(node) {
return node.className || "";
}
test("a locked row keeps its reason in a separate element from the value", () => {
// Regression: the reason used to sit beside an overflowing value and
// render as "/home/sam/.local/share/archie/workpins the daemon's
// working layout". Assert on the cell count and per-cell text, never on
// the row's flattened text, so a future layout change cannot pass by
// merging them back into one node.
const rowEl = row("Work directory", "/home/sam/.local/share/archie/work", {
key: "work_dir",
locked: { work_dir: "pins the daemon's working layout; cannot be changed at runtime" },
});
const parts = cells(rowEl);
assert.equal(parts.length, 3, "expected label, value and note as separate children");
assert.equal(parts[0], "Work directory");
assert.equal(parts[1], "/home/sam/.local/share/archie/work");
assert.equal(parts[2], "pins the daemon's working layout; cannot be changed at runtime");
assert.ok(classOf(rowEl).includes("is-locked"));
});
test("a locked row offers no edit control", () => {
const rowEl = row("State path prefix", "/home/sam/.local/share/archie/archie.db", {
key: "db_path",
locked: { db_path: "required for bootstrap" },
});
assert.equal(rowEl.childNodes.filter((c) => classOf(c).includes("kv-actions")).length, 0);
});
test("an editable row separates value from its actions", () => {
// Regression: the value overflowed into the action column, so "400"
// rendered as "40" with Edit sitting on top of the last digit. Assert
// the value and the actions are distinct children.
const rowEl = row("Max diff size (lines)", 400, { key: "diff_cap_lines", type: "int", raw: 400 });
const parts = cells(rowEl);
assert.equal(parts.length, 3);
assert.equal(parts[1], "400", "the value must not be merged with the action label");
assert.equal(parts[2], "Edit");
});
test("an overridden row shows the marker and a reset alongside edit", () => {
const rowEl = row("Max steps", 90, {
key: "budgets.max_steps",
type: "int",
raw: 90,
overridden: ["budgets.max_steps"],
});
const actions = rowEl.childNodes.find((c) => classOf(c).includes("kv-actions"));
assert.deepEqual(actions.childNodes.map(text), ["overridden", "Edit", "Reset"]);
});
test("the full value is recoverable from the title when the column truncates", () => {
const long = "go vet ./... → go build ./... → go test ./... -count=1";
const rowEl = row("Quality gate", long);
const value = rowEl.childNodes.find((c) => classOf(c).includes("kv-value"));
assert.equal(value.attrs.title, long);
});
test("zero and false are real values, not missing ones", () => {
// `value ?? "—"` handled these, but a `value || "—"` refactor would
// silently turn a configured 0 into "not set". Pin the distinction.
assert.equal(valueText(0), "0");
assert.equal(valueText(false), "false");
assert.equal(valueText(""), "—");
assert.equal(valueText(null), "—");
assert.equal(valueText(undefined), "—");
});
test("int edits reject a non-numeric entry before the round trip", () => {
assert.equal(parseEdit("int", "12").value, 12);
assert.ok(parseEdit("int", "twelve").error);
assert.equal(parseEdit("bool", "true").value, true);
assert.equal(parseEdit("bool", "false").value, false);
assert.equal(parseEdit("string", "1h0m0s").value, "1h0m0s");
});