Fix issue #91: Make character column always visible
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 21:56:49 +00:00
parent 98aa3be078
commit 30e23b643c
4 changed files with 265 additions and 145 deletions

View File

@@ -0,0 +1,111 @@
// Tests for Syndria98/dragonroll#91: the column that opens the character sheet — the portrait with
// the armor class, the speed, the bonuses and both pools under it — stays on screen whoever's tab is
// open, instead of being the ability scores tab's own content and disappearing when the sheet moves
// to the inventory, the traits or the spells.
//
// The window is a `.vue` file and the repository root installs no dependencies for the frontend, so
// the template and the styles are read out of the source the way tests/character-sheet-tabs.test.js
// and tests/character-sheet-portrait-column.test.js read them.
//
// 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 read = (...parts) => fs.readFileSync(path.join(__dirname, "..", ...parts), "utf8");
const sheetSource = read("frontend", "app", "components", "windows", "CharacterSheetWindow.vue");
const template = /<template>([\s\S]*)<\/template>/.exec(sheetSource)?.[1] ?? "";
const TAB_KEYS = ["abilities", "inventory", "traits", "spells"];
const COLUMN = '<div class="character-column">';
function tabBody(key) {
const block = new RegExp(`<main v-show="activeTab === '${key}'"[\\s\\S]*?</main>`).exec(template)?.[0];
assert.ok(block, `expected a body for the ${key} tab`);
return block;
}
// The column, taken whole: it stands ahead of the tab bodies, which are its siblings.
function characterColumn() {
const start = template.indexOf(COLUMN);
const end = template.indexOf('<main v-show="activeTab');
assert.ok(start !== -1 && end > start, "expected the character column ahead of the tab bodies");
return template.slice(start, end);
}
// The classes wrapping a tag, worked out by walking the blocks of the template in order the way a
// browser nests them, so a tab cannot hide the column by wrapping it.
function ancestorsOf(needle) {
const at = template.indexOf(needle);
assert.ok(at !== -1, `expected ${needle} in the template`);
const stack = [];
for (const match of template.matchAll(/<(\/?)(div|main|section|header|nav)\b([^>]*)>/g)) {
if (match.index > at) break;
const [, closed, , attrs] = match;
if (closed) stack.pop();
else if (!attrs.trimEnd().endsWith("/")) {
const classes = /\bclass="([^"]*)"/.exec(attrs);
stack.push(classes ? classes[1].trim().split(/\s+/) : []);
}
}
return stack.slice(0, -1).map((classes) => classes.join(" "));
}
test("the character column belongs to no tab", () => {
const column = characterColumn();
assert.ok(column.includes('class="sheet-portrait"'), "the portrait is part of the column");
assert.ok(column.includes('class="sheet-panel vitals-panel"'), "and so is the panel of readouts and bars");
// Nothing toggles the column: no tab decides whether it shows.
assert.doesNotMatch(column, /v-show=/, "the column never hides behind a tab");
for (const key of TAB_KEYS) {
const body = tabBody(key);
assert.doesNotMatch(body, /class="character-column"/, `the ${key} tab does not own the column`);
assert.doesNotMatch(body, /sheet-portrait|vitals-panel/, `the ${key} tab does not hold the column's contents`);
}
});
test("the column and the tab that is open stand beside each other", () => {
const columnWrappers = ancestorsOf(COLUMN);
assert.equal(columnWrappers.at(-1), "sheet-layout", "the column stands in the sheet's own layout");
for (const key of TAB_KEYS) {
assert.deepEqual(
ancestorsOf(`<main v-show="activeTab === '${key}'"`),
columnWrappers,
`the ${key} tab is a sibling of the column, so it is never wrapped around it`
);
}
const layout = /\.sheet-layout\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
assert.match(layout, /display:\s*grid/, "the layout puts the column and the open tab side by side");
assert.match(
layout,
/grid-template-columns:\s*minmax\(200px,\s*34%\)\s+minmax\(0,\s*1fr\)/,
"the character keeps its own column and the tab has all the room left"
);
const columnRule = /\.character-column\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
assert.match(columnRule, /grid-column:\s*1/, "the character stands in the first column");
const bodyRule = /\.sheet-tab-body\s*\{[^}]*\}/.exec(sheetSource)?.[0] ?? "";
assert.match(bodyRule, /grid-column:\s*2/, "the open tab takes the space beside it");
assert.match(bodyRule, /grid-row:\s*1/, "and on the same row, so switching a tab leaves the column where it was");
});
test("a narrow window stacks the column over the tab instead of hiding it", () => {
const narrow = /@media \(max-width: 760px\)\s*\{([\s\S]*?)\n\}/.exec(sheetSource)?.[1] ?? "";
assert.match(narrow, /\.sheet-layout\s*\{[^}]*grid-template-columns:\s*1fr/, "the two columns become one");
assert.match(
narrow,
/\.character-column,\s*\.sheet-tab-body\s*\{[^}]*grid-column:\s*1 \/ -1;[^}]*grid-row:\s*auto/,
"the column goes over the tab, it does not go away with it"
);
});
test("what stays on screen is what the sheet is read for", () => {
const column = characterColumn();
for (const key of ["armor-class", "speed", "proficiency-bonus", "initiative", "hit-points", "hit-dice"]) {
assert.ok(column.includes(`campaigns.character-sheet.${key}`), `the ${key} stays visible from any tab`);
}
});

View File

@@ -43,7 +43,7 @@ const normalizeActor = fromSource(script, /function normalizeActor\(actor\) \{[\
const barPercent = fromSource(script, /function barPercent\(current, max\) \{[\s\S]*?\n\}/);
const barPool = fromSource(actorRouteSource, /function barPool\(existing, value\) \{[\s\S]*?\n\}/);
// The column that opens the abilities tab: the portrait with everything under it.
// The column that stands beside every tab: the portrait with everything under it.
function portraitColumn() {
const start = template.indexOf('<div class="character-column">');
const end = template.indexOf('<section class="sheet-panel abilities-panel">');

View File

@@ -53,7 +53,6 @@ function tabBody(key) {
test("every tab shows only its own content and hides the others", () => {
const abilities = tabBody("abilities");
assert.match(abilities, /class="sheet-portrait"/, "the portrait stays with ability scores");
assert.match(abilities, /class="sheet-panel abilities-panel"/);
assert.match(abilities, /class="sheet-panel proficiencies-panel"/, "the proficiencies ride with the ability scores");
for (const other of ["inventory-panel", "traits-panel", "spells-panel"]) {
@@ -63,7 +62,12 @@ test("every tab shows only its own content and hides the others", () => {
for (const [key, panel] of [["inventory", "inventory-panel"], ["traits", "traits-panel"], ["spells", "spells-panel"]]) {
const body = tabBody(key);
assert.ok(body.includes(panel), `the ${key} tab shows the ${panel}`);
assert.doesNotMatch(body, /class="sheet-portrait"/);
}
// #91 took the character column out of the tabs: it stands beside every one of them, so no tab
// body holds the portrait (see tests/character-sheet-persistent-column.test.js).
for (const key of ["abilities", "inventory", "traits", "spells"]) {
assert.doesNotMatch(tabBody(key), /class="sheet-portrait"/, `the portrait is not the ${key} tab's to hide`);
}
// the panels are toggled, not unmounted, so editing on one tab and flipping away keeps the draft