Fix issue #21: entity-entry sizing problem

This commit is contained in:
Gitea OpenCode Agent
2026-10-14 14:52:18 +00:00
parent 9d9738b2b4
commit b0acd689bb
2 changed files with 95 additions and 3 deletions

View File

@@ -0,0 +1,88 @@
// Tests for the entity-entry sizing problem of Syndria98/dragonroll#21: the actor / item / map rows
// in the campaign sidebar were wider than the sidebar itself, so their hover border and the anchored
// state of a map poked outside of it.
//
// The repository root installs no dependencies, so the checks read the sidebar component the same way
// `tests/map-viewer.test.js` reads its window: the rules are about the box of the elements themselves.
//
// Run with `npm test` from the repository root, or `node --test tests/`.
const { test } = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const source = fs.readFileSync(
path.join(__dirname, "..", "frontend", "app", "components", "partials", "ContentSidebar.vue"),
"utf8"
);
// `selector` is inserted verbatim, so escape the `.` of a class combination (`entity-entry\\.anchored`).
// A trailing `\.entity-entry\s*\{` cannot match `.entity-entry:hover` or `.entity-entry-name`, so the
// plain rule is always the one that comes back. Comments are dropped: they explain a rule, they are
// not part of it.
function ruleFor(selector) {
const rule = new RegExp(`\\.${selector}\\s*\\{([^}]*)\\}`).exec(source)?.[0];
return rule?.replace(/\/\*[\s\S]*?\*\//g, "");
}
function declaration(rule, property) {
return new RegExp(`${property}:\\s*([^;]*)`).exec(rule)?.[1].trim();
}
test("the sidebar list the entity entries live in is border-box sized", () => {
const wrap = ruleFor("sidebar-list-drop-wrap");
assert.ok(wrap, "expected a .sidebar-list-drop-wrap style rule");
// Its fixed width already includes the padding the entries sit in; the entries' 100% resolves
// against that padded content box.
assert.match(wrap, /box-sizing:\s*border-box/);
assert.match(wrap, /padding:/);
});
test("every section renders its entries inside the sidebar list", () => {
const list = /class="sidebar-list-drop-wrap"[\s\S]*?\n {12}<\/div>\n {8}<\/aside>/.exec(source);
assert.ok(list, "expected the sidebar list wrapper to be followed by the closing aside");
// actors, items and maps all use the same row
const rendered = list[0].match(/class="entity-entry"/g) || [];
assert.ok(rendered.length >= 3, `expected every section to render entity entries, found ${rendered.length}`);
});
test("an entity entry measures its padding and border inside the sidebar width", () => {
const entry = ruleFor("entity-entry");
assert.ok(entry, "expected a .entity-entry style rule");
const width = declaration(entry, "width");
const padding = declaration(entry, "padding");
const border = declaration(entry, "border");
assert.ok(width, "the entry must fill the sidebar list");
assert.ok(padding && border, "the entry has inner padding and a border to fit");
// These rows are divs and the app ships no global box-sizing reset, so with the default
// content-box the padding and the border were added on top of the 100% width and the box — border
// and all — overflowed the sidebar.
assert.equal(
declaration(entry, "box-sizing"),
"border-box",
"an entry sized at 100% with padding and a border needs box-sizing: border-box"
);
});
test("the hovered and anchored states keep the entry the same size", () => {
const entry = ruleFor("entity-entry");
// The resting border is transparent instead of `none`, so showing it on hover or when a map is
// anchored only recolours it and never grows the row.
assert.match(declaration(entry, "border"), /transparent/);
for (const selector of ["entity-entry:hover", "entity-entry\\.anchored"]) {
const rule = ruleFor(selector);
assert.ok(rule, `expected a .${selector} style rule`);
assert.doesNotMatch(rule, /border(-width)?\s*:\s*[^;]*\d+px/, `.${selector} must not widen the border`);
assert.match(rule, /border-color:/, `.${selector} is a state that shows the border`);
}
});
test("a long entry name wraps instead of pushing the entry out of the sidebar", () => {
const name = ruleFor("entity-entry-name");
assert.ok(name, "expected a .entity-entry-name style rule");
assert.match(name, /(word-break|overflow-wrap):/, "an unbreakable name has to wrap inside the entry");
});