90 lines
4.8 KiB
JavaScript
90 lines
4.8 KiB
JavaScript
// Tests for Syndria98/dragonroll#63: the item rows in the campaign sidebar dropped the text
|
|
// listing category, rarity and quantity — the rarity colours the text of the entry instead
|
|
// (common white, uncommon green, rare blue, very rare purple, legendary orange) — and the
|
|
// quantity left the item surfaces altogether, since it only belongs to an actor's inventory.
|
|
//
|
|
// The repository root installs no dependencies, so these read the sources the way
|
|
// tests/item-entry-display.test.js does — the checks are about the markup and style.
|
|
//
|
|
// 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 sidebarSource = read("frontend", "app", "components", "partials", "ContentSidebar.vue");
|
|
const itemWindowSource = read("frontend", "app", "components", "windows", "ItemSheetWindow.vue");
|
|
const entryFormSource = read("frontend", "app", "components", "windows", "CreateCampaignEntryWindow.vue");
|
|
const sheetSource = read("frontend", "app", "components", "windows", "CharacterSheetWindow.vue");
|
|
const colorsSource = read("frontend", "app", "assets", "css", "colors.scss");
|
|
|
|
// The block that renders the item rows, as in tests/item-entry-display.test.js.
|
|
const itemSection =
|
|
/<template v-else-if="activeSection === 'items'">([\s\S]*?)<\/template>\s*\n\s*<template v-else>/.exec(sidebarSource)?.[1] ?? "";
|
|
|
|
const rarities = ["common", "uncommon", "rare", "very-rare", "legendary"];
|
|
|
|
// `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(sidebarSource)?.[0];
|
|
return rule?.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
}
|
|
|
|
test("the item entry no longer lists the category, rarity and quantity as text", () => {
|
|
assert.ok(itemSection, "expected to find the items section of the sidebar");
|
|
assert.doesNotMatch(itemSection, /entity-entry-meta/, "the item row must not render a meta line");
|
|
assert.doesNotMatch(itemSection, /campaigns\.item\.(categories|rarities|quantity)/, "the item row must not render item meta text");
|
|
assert.doesNotMatch(sidebarSource, /itemSummary/, "the removed summary helper must not be kept around");
|
|
});
|
|
|
|
test("the rarity of an item picks a class for the text of its entry", () => {
|
|
assert.match(
|
|
itemSection,
|
|
/<span class="entity-entry-name" :class="rarityClass\(row\.item\)"/,
|
|
"the item name must carry the class picked from its rarity"
|
|
);
|
|
const helper = /function rarityClass\(item\)\s*\{[\s\S]*?\n\}/.exec(sidebarSource)?.[0] ?? "";
|
|
assert.ok(helper, "expected a rarityClass helper");
|
|
for (const rarity of rarities) {
|
|
assert.ok(helper.includes(`'${rarity}'`), `rarityClass must know about '${rarity}'`);
|
|
}
|
|
});
|
|
|
|
test("each rarity colours the entry text with its own theme colour", () => {
|
|
for (const rarity of rarities) {
|
|
const rule = ruleFor(`entity-entry-name\\.rarity-${rarity}`);
|
|
assert.ok(rule, `expected a colour rule for .entity-entry-name.rarity-${rarity}`);
|
|
assert.match(rule, new RegExp(`color:\\s*var\\(--color-rarity-${rarity}\\)`));
|
|
}
|
|
});
|
|
|
|
test("both theme maps carry the rarity colours", () => {
|
|
for (const rarity of rarities) {
|
|
const declarations = colorsSource.match(new RegExp(`rarity-${rarity}:\\s*#[0-9a-fA-F]{6}`, "g")) || [];
|
|
assert.equal(declarations.length, 2, `expected rarity-${rarity} in both the dark and the light map`);
|
|
}
|
|
});
|
|
|
|
test("the quantity only shows in an actor's inventory", () => {
|
|
assert.doesNotMatch(itemWindowSource, /quantity/, "the item window must not list the quantity");
|
|
assert.doesNotMatch(entryFormSource, /quantity/, "the item create/edit form must not offer the quantity");
|
|
// the character sheet's inventory table keeps it.
|
|
assert.match(sheetSource, /campaigns\.character-sheet\.quantity/);
|
|
assert.match(sheetSource, /\{\{ item\.quantity \}\}/);
|
|
});
|
|
|
|
test("no locale keeps the removed item quantity strings", () => {
|
|
for (const locale of ["en", "es", "ca"]) {
|
|
const campaigns = JSON.parse(read("frontend", "i18n", "locales", locale, "campaigns.json"));
|
|
assert.ok(campaigns.item, `${locale} is missing the campaigns.item block`);
|
|
assert.equal(campaigns.item.quantity, undefined, `${locale} still has campaigns.item.quantity`);
|
|
assert.equal(campaigns.item["quantity-short"], undefined, `${locale} still has campaigns.item.quantity-short`);
|
|
// the character sheet's inventory keeps its own quantity column label
|
|
assert.ok(campaigns["character-sheet"]?.quantity, `${locale} is missing campaigns.character-sheet.quantity`);
|
|
}
|
|
});
|