Files
dragonroll/tests/item-entry-display.test.js
Gitea OpenCode Agent 0c6026aea8
Some checks failed
Test / test (push) Failing after 2s
Fix issue #53: Item modifications
2026-10-15 12:46:36 +00:00

70 lines
3.5 KiB
JavaScript

// Tests for Syndria98/dragonroll#53: the item row in the campaign sidebar dropped its "SYNCED"
// text badge and now leads with the item's own icon on the left of the entry.
//
// The repository root installs no dependencies, so these read the sidebar component the way
// tests/sidebar-entity-entry.test.js does — the checks are about the markup and style of the row.
//
// 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"
);
// The block that renders the item rows, from the items section down to its closing template. The
// items section is followed by the maps section (`v-else`), so the first `</template>` that leads
// there ends it; the inner `v-for` close is followed by another close, not by `v-else`.
const itemSection =
/<template v-else-if="activeSection === 'items'">([\s\S]*?)<\/template>\s*\n\s*<template v-else>/.exec(source)?.[1] ?? "";
// `selector` is inserted verbatim, so escape the `.` of a class combination. 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, "");
}
test("the item entry no longer shows the SYNCED text", () => {
assert.ok(itemSection, "expected to find the items section of the sidebar");
assert.doesNotMatch(itemSection, /campaigns\.synced/, "the item row must not render the synced text");
assert.doesNotMatch(itemSection, /entity-entry-sync/, "the item row must not render the synced badge");
});
test("the item entry shows the item's image on the left when it has one", () => {
// the icon renders only for an item that carries an image, resolved through the helper...
assert.match(
itemSection,
/<span v-if="row\.item\.image" class="entity-entry-image"[\s\S]*?<img :src="itemImageUrl\(row\.item\.image\)"/
);
// ...and on the left: it stands before the name in the row markup.
assert.ok(
itemSection.indexOf("entity-entry-image") < itemSection.indexOf("entity-entry-name"),
"the item image must stand to the left of the name"
);
});
test("the item entry lays the icon out beside the name", () => {
const title = ruleFor("entity-entry-title");
assert.ok(title, "expected a .entity-entry-title style rule");
assert.match(title, /display:\s*flex/, "the icon and the name sit side by side");
const image = ruleFor("entity-entry-image");
assert.ok(image, "expected a .entity-entry-image style rule");
assert.match(image, /overflow:\s*hidden/, "the icon is clipped to its box");
});
test("an item image resolves like the item window: uploads from /public, full URLs as they are", () => {
assert.match(source, /import Server, \{ getBaseUrl \} from ['"]~\/services\/Server['"]/);
const resolver = /function itemImageUrl\(image\)\s*\{[\s\S]*?\n\}/.exec(source)?.[0] ?? "";
assert.ok(resolver, "expected an itemImageUrl helper");
assert.match(resolver, /https\?:/, "a full http(s) URL loads as it is");
assert.match(resolver, /data:/, "a data URI loads as it is");
assert.match(resolver, /\$\{getBaseUrl\(\)\}\/public\//, "an uploaded filename resolves as a /public file");
});