66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import { richText, renderRichText } from "../viewer/rich-text.js";
|
||
|
||
test("tutorials and journal use the board's nutrient colours and quantities", () => {
|
||
for (const [text, label] of [
|
||
["You #1 feeds and leaves two green nutrients.", "2 green nutrients"],
|
||
["Eat three coral cubes.", "3 coral nutrients"],
|
||
["Maya leaves two red nutrients.", "2 coral nutrients"],
|
||
["Nina leaves two yellow nutrients.", "2 gold nutrients"],
|
||
]) {
|
||
assert.ok(richText(text).includes(`aria-label="${label}"`));
|
||
}
|
||
});
|
||
|
||
test("resource references support written quantities, negative amounts and injuries", () => {
|
||
const html = richText(
|
||
"Two injuries, an injury, 2 mutation sensitivity, −1 BP, two evolution points and 1 EP.",
|
||
);
|
||
for (const label of [
|
||
"2 injuries",
|
||
"1 injury",
|
||
"2 mutation sensitivity",
|
||
"-1 biological points",
|
||
"2 evolution points",
|
||
"1 evolution point",
|
||
]) {
|
||
assert.ok(html.includes(`aria-label="${label}"`));
|
||
}
|
||
});
|
||
|
||
test("rich journal text escapes player input and keeps full gene names", () => {
|
||
const html = richText(
|
||
'<img src=x onerror="alert(1)"> buys Movement II for 5 BP.',
|
||
);
|
||
assert.ok(!html.includes("<img"));
|
||
assert.ok(html.includes("<img"));
|
||
assert.ok(html.includes(">Movement II</span>"));
|
||
assert.ok(!html.includes(">Movement I</span>"));
|
||
assert.equal(richText("Nothing happened."), "Nothing happened.");
|
||
});
|
||
|
||
test("translates a whole gene effect before substituting resource pictograms", () => {
|
||
const sentence =
|
||
"After a failed attack or defense, you may make a second attempt for free. Replaces Speed; it does not keep Speed's extra swim.";
|
||
const translated =
|
||
"Après un échec, réessayez gratuitement. Remplace Vitesse sans conserver sa seconde nage.";
|
||
const t = (text) =>
|
||
({ [sentence]: translated, Speed: "Vitesse" })[text] ?? text;
|
||
const html = renderRichText(sentence, t);
|
||
assert.ok(html.startsWith("Après un échec, réessayez gratuitement."));
|
||
assert.ok(html.includes(">Vitesse</span>"));
|
||
assert.ok(!html.includes("After a failed"));
|
||
const cost = renderRichText(
|
||
"Swimming still costs 1 BP.",
|
||
(text) =>
|
||
({
|
||
"Swimming still costs 1 BP.": "Coût de la nage : 1 PB.",
|
||
"1 BP": "1 PB",
|
||
"1 biological point": "1 point biologique",
|
||
})[text] ?? text,
|
||
);
|
||
assert.ok(cost.startsWith("Coût de la nage :"));
|
||
assert.ok(cost.includes('aria-label="1 point biologique"'));
|
||
assert.ok(cost.includes('class="resource-amount bp-amount"'));
|
||
});
|