primordial-soup/test/player-colors.test.js

40 lines
1.2 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { COLORS } from "../engine/catalog.js";
import {
colors,
amoeba,
setPlayerColors,
displayColorName,
} from "../viewer/art.js";
import { food } from "../viewer/rich-text.js";
test("custom colours recolour amoebas and nutrients together without changing colony identities", () => {
const original = structuredClone(colors);
const identities = [...COLORS];
try {
setPlayerColors(["#123abc"]);
assert.equal(colors.green.body, "#123abc");
assert.match(amoeba("green"), /#123abc/);
assert.ok(food(0).includes(colors.green.shade));
assert.equal(displayColorName(0, "Green"), "Player 1");
assert.deepEqual(COLORS, identities);
setPlayerColors(["#123abc"], false);
assert.deepEqual(
colors,
original,
"accessibility mode restores the canonical palette",
);
setPlayerColors(["url(x)"]);
assert.deepEqual(colors, original);
setPlayerColors(["#ffffff"]);
setPlayerColors([]);
assert.deepEqual(
colors,
original,
"expired or cleared preferences restore all colours",
);
} finally {
setPlayerColors([]);
}
});