Files
org_web/tests/princess-lima-v2-state.test.cjs
gitea-actions 563d4b63cc
All checks were successful
Build Org Website / build (push) Successful in 37s
Tune Princess Lima v2 boss balance and Sun Crystal aid
2026-07-30 15:36:59 +01:00

61 lines
2.8 KiB
JavaScript
Executable File

const test = require("node:test");
const assert = require("node:assert/strict");
const data = require("../assets/scripts/pages/princess-lima-v2-data.js");
const state = require("../assets/scripts/pages/princess-lima-v2-state.js");
const systems = require("../assets/scripts/pages/princess-lima-v2-systems.js");
test("fresh saves use the v2 key and complete accessibility defaults", () => {
const fresh = state.fresh("Aster", "azure");
assert.equal(state.STORAGE_KEY, "zxh_princess_lima_rpg_v2");
assert.equal(state.LEGACY_KEY, "zxh_princess_lima_rpg_v1");
assert.equal(fresh.settings.subtitles, true);
assert.equal(fresh.settings.blur, true);
assert.equal(fresh.settings.particles, true);
assert.equal(fresh.settings.screenShake, true);
});
test("loading imports legacy data once and leaves the legacy key untouched", () => {
const values = new Map([[state.LEGACY_KEY, JSON.stringify({
version: 1, player: { name: "Legacy", appearance: "ember" }, chapter: 2,
region: "forest", inventory: [], quests: {}, settings: {}
})]]);
const storage = { getItem: (key) => values.get(key) || null, setItem: (key, value) => values.set(key, value) };
const result = state.load(storage);
assert.equal(result.migrated, true);
assert.equal(result.state.player.name, "Legacy");
assert.ok(values.has(state.LEGACY_KEY));
assert.ok(values.has(state.STORAGE_KEY));
});
test("dialogue choices apply flags and quest effects", () => {
const fresh = state.fresh("Aster", "azure");
const result = systems.dialogueChoice("elder", "choice", 0, fresh);
assert.equal(result.next, "accept");
assert.equal(result.state.flags.promised_village, true);
assert.equal(result.state.quests.aftermath.status, "active");
});
test("quest completion applies rewards and world state transformations", () => {
let current = state.fresh("Aster", "azure");
current = state.startQuest(current, "village_defence");
current = state.progressQuest(current, "village_defence", 3);
assert.equal(current.quests.village_defence.status, "complete");
assert.equal(current.flags.village_resolved, true);
assert.equal(current.flags.village_defended, true);
assert.equal(current.chapter, 2);
assert.equal(current.inventory.some((item) => item.id === "buckler"), true);
});
test("normalization removes invalid IDs and clamps unsafe values", () => {
const candidate = state.fresh("Aster", "azure");
candidate.health = 999;
candidate.inventory.push({ id: "not-real", quantity: 99 });
candidate.region = "missing";
candidate.settings.effectsQuality = "impossible";
const normalized = state.normalize(candidate);
assert.equal(normalized.health, normalized.maxHealth);
assert.equal(normalized.region, "village");
assert.equal(normalized.inventory.some((entry) => !data.ITEMS[entry.id]), false);
assert.equal(normalized.settings.effectsQuality, "full");
});