web/website/tests/quest-categories.test.mjs
unimatrixgit d9f374defb
All checks were successful
DuneRealms Web CI / web (push) Successful in 4m48s
Group the current mission journal into illustrated story arcs
2026-12-05 07:36:47 +01:00

47 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import {fileURLToPath} from 'node:url';
import {QUEST_CATEGORIES,OTHER_CATEGORY,categoryFor,groupBranches,orderChapters,bannerUrl,iconUrl} from '../control-panel/public/cp-v2/cp-v2-quest-categories.mjs';
import {POL_QUEST_BRANCHES} from '../control-panel/public/cp-v2/cp-v2-pol-quest-catalogue.mjs';
import {MISSION_BRANCHES} from '../control-panel/public/cp-v2/cp-v2-progression-catalogue.mjs';
const known=[...new Set([...MISSION_BRANCHES.map(b=>b.id),'acquisitions','spice-harvesting',...POL_QUEST_BRANCHES.map(b=>b.id)])];
test('every known quest branch belongs to exactly one themed category',()=>{
const seen=new Map();
for(const c of QUEST_CATEGORIES)for(const b of c.branches){assert.ok(!seen.has(b),'branch twice: '+b);seen.set(b,c.id);}
for(const b of known)assert.notEqual(categoryFor(b),OTHER_CATEGORY,'unmapped branch '+b);
assert.equal(QUEST_CATEGORIES.length,13);
assert.equal(new Set(QUEST_CATEGORIES.map(c=>c.id)).size,13);
});
test('the website catalogue matches the in-game catalogue file',()=>{
const game=JSON.parse(fs.readFileSync(new URL('./fixtures/quest-categories.plugin.json',import.meta.url),'utf8')).categories;
assert.deepEqual(JSON.parse(JSON.stringify(QUEST_CATEGORIES)),game);
});
test('every category ships a banner and an icon',()=>{
for(const c of [...QUEST_CATEGORIES,OTHER_CATEGORY]){
for(const url of [bannerUrl(c),iconUrl(c)])assert.ok(fs.existsSync(fileURLToPath(url)),'missing '+url);
assert.match(c.accent,/^#[0-9a-f]{6}$/);assert.ok(c.title&&c.tagline);
}
});
test('branches regroup by category in catalogue order and unmapped ones are kept last',()=>{
const rows=[{id:'elytra',title:'E'},{id:'atreides',title:'A'},{id:'a',title:'Prologue'},{id:'ordos',title:'O'},{id:'brand-new',title:'N'}];
const groups=groupBranches(rows);
assert.deepEqual(groups.map(g=>g.category.id),['arrival','landsraad','wings','other']);
assert.deepEqual(groups[1].rows.map(r=>r.id),['atreides','ordos']);
assert.deepEqual(groups[3].rows.map(r=>r.id),['brand-new']);
assert.deepEqual(groupBranches([]),[]);
});
test('chapters follow prerequisites, stay stable and survive cycles',()=>{
const q=(id,requires=[])=>({id,requires});
assert.deepEqual(orderChapters([q('c',['b']),q('a'),q('b',['a'])]).map(r=>r.id),['a','b','c']);
assert.deepEqual(orderChapters([q('x'),q('y'),q('z')]).map(r=>r.id),['x','y','z']);
assert.deepEqual(orderChapters([q('p',['q']),q('q',['p'])]).map(r=>r.id).sort(),['p','q']);
assert.deepEqual(orderChapters([q('m',['missing'])]).map(r=>r.id),['m']);
assert.deepEqual(orderChapters([{id:'k',requires:[],requiresAny:['j']},{id:'j'}]).map(r=>r.id),['j','k']);
});
test('the category layer never changes quest data',()=>{
const rows=Object.freeze([Object.freeze({id:'a',requires:Object.freeze([]),reward:5})]);
assert.deepEqual(orderChapters(rows),rows);
});