Fix issue #21: entity-entry sizing problem
This commit is contained in:
@@ -662,7 +662,11 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
|
||||
.entity-entry {
|
||||
width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 8px;
|
||||
/* These rows are divs (the note and folder rows are buttons) and there is no global box-sizing
|
||||
reset, so without border-box the padding and border add onto the 100% width and the entry
|
||||
sticks out of the sidebar. */
|
||||
width: 100%; min-width: 0; box-sizing: border-box; padding: 9px 10px; border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
background: transparent; color: var(--color-text); text-align: left; display: flex; flex-direction: column;
|
||||
gap: 3px; cursor: pointer;
|
||||
}
|
||||
@@ -670,8 +674,8 @@ onBeforeUnmount(() => {
|
||||
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
|
||||
/* The map currently anchored on the note container. */
|
||||
.entity-entry.anchored { border-color: var(--color-link); background: var(--color-background-soft); }
|
||||
.entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; }
|
||||
.entity-entry-name { font-weight: bold; }
|
||||
.entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
|
||||
.entity-entry-name { font-weight: bold; min-width: 0; word-break: break-word; }
|
||||
.entity-entry-sync {
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.04em;
|
||||
|
||||
88
tests/sidebar-entity-entry.test.js
Normal file
88
tests/sidebar-entity-entry.test.js
Normal 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");
|
||||
});
|
||||
Reference in New Issue
Block a user