Serve story artwork and replace letter branches with named arcs

This commit is contained in:
unimatrixgit 2026-12-05 08:31:16 +01:00
commit 1fdf4dc720
3 changed files with 88 additions and 18 deletions

View file

@ -48,3 +48,16 @@ test('current journal groups categories without hiding unknown branches or chang
assert.equal(all.filter(e=>e.textContent==='Claim reward').length,1);assert.equal(all.filter(e=>e.className==='quest-category-hero').length,1);
}finally{globalThis.document=before;}
});
test('one named story arc combines former letter branches once in prerequisite order',()=>{
const before=globalThis.document;globalThis.document={createElement:tag=>new Element(tag),querySelector:()=>null,head:new Element('head')};
try{
const mission=(id,branch,requires=[])=>({id,title:'Mission '+id,branch,requires,state:'active',progress:0,target:1});
const journal=buildJournal({branches:[{id:'e',title:'E'},{id:'f',title:'F'},{id:'g',title:'G'}],quests:[mission('third','g',['second']),mission('first','e'),mission('second','f',['first'])]}),root=new Element('main'),calls=[];
renderMissionJournal(root,{journal,selected:'first',tracked:'second'},{onSelect:id=>calls.push(id),onTrack:()=>{},onAct:()=>{},onSteps:()=>{}});
const all=descendants(root),headings=all.filter(e=>e.tagName==='summary');assert.equal(headings.length,1);assert.equal(headings[0].children.find(e=>e.tagName==='span').textContent,'A Place in the Realm');
const picks=all.filter(e=>e.className==='mj-mission');assert.deepEqual(picks.map(e=>e.children[0].textContent),['Mission first','Mission second','Mission third']);
assert.equal(new Set(picks.map(e=>e.children[0].textContent)).size,3);picks[1].onclick();assert.deepEqual(calls,['second']);
assert.ok(!all.some(e=>['E','F','G'].includes(e.textContent)));
}finally{globalThis.document=before;}
});

View file

@ -30,7 +30,7 @@ test('mission branches and directory persist through decisions/history and stay
const right=new Node(),left=new Node(),banner=new Node(),shell=new Node();right.parentElement=shell;right.querySelector=()=>banner;shell.querySelector=s=>s==='#sidebar'?left:right;
globalThis.document={createElement:()=>new Node(),querySelector:()=>null};globalThis.location={hash:'#quests/quests'};globalThis.history={replaceState(){}};
const host={closest:()=>({parentElement:shell})},requests=[],selected=[];
const data=kind=>({state:'active',branches:[{id:kind,title:kind}],quests:[{branch:kind}],player:{}});
const data=kind=>{const branch=kind==='personal'?'a':'fremen';return {state:'active',branches:[{id:branch,title:kind==='personal'?'A':'Fremen'}],quests:[{branch}],player:{}};};
let sidebar;
try{
sidebar=createProgressionSidebar(host,{onBranch:id=>selected.push(id),fetcher:async path=>{requests.push(path);return Response.json(path==='/api/progression/pol'?data('pol'):path==='/api/progression'?data('personal'):{});}});
@ -38,8 +38,8 @@ test('mission branches and directory persist through decisions/history and stay
const directory=left.children.find(n=>n.attributes['aria-label']==='Mission branches');
assert.equal(directory.hidden,false);assert.equal(banner.hidden,false);
sidebar.setNavigation('personal','history');sidebar.showBranches(true);assert.equal(directory.hidden,false);
branchButtons(directory)[0].onclick();assert.deepEqual(selected,['personal']);
sidebar.setNavigation('pol','decisions');assert.equal(branchButtons(directory)[0].children[1].textContent,'pol');
branchButtons(directory)[0].onclick();assert.deepEqual(selected,['category:arrival']);
sidebar.setNavigation('pol','decisions');assert.equal(branchButtons(directory)[0].children[1].textContent,'Sons of the Sand');
assert.equal(requests.filter(p=>p==='/api/progression').length,1);
}finally{sidebar?.dispose();for(const [key,value]of Object.entries(before)){if(value===undefined)delete globalThis[key];else globalThis[key]=value;}}
});

View file

@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFile} from 'node:fs/promises';
import {createPanel} from '../control-panel/server.mjs';
import {LocalD1} from './d1-adapter.mjs';
import {QUEST_CATEGORIES,OTHER_CATEGORY} from '../control-panel/public/cp-v2/cp-v2-quest-categories.mjs';
test('real CP routes serve all authored arc PNGs with correct GET and HEAD semantics',async()=>{
const db=new LocalD1(),app=createPanel(db),origin='https://cp.dunerealms.com';
try{
for(const category of [...QUEST_CATEGORIES,OTHER_CATEGORY])for(const kind of ['icon','banner']){
const name=category.id+'-'+kind+'.png',url=origin+'/v2/art/quests/'+name;
const response=await app(new Request(url));assert.equal(response.status,200,name);assert.equal(response.headers.get('content-type'),'image/png');assert.equal(response.headers.get('x-content-type-options'),'nosniff');
assert.deepEqual(Buffer.from(await response.arrayBuffer()),await readFile(new URL('../control-panel/public/cp-v2/art/quests/'+name,import.meta.url)));
const head=await app(new Request(url,{method:'HEAD'}));assert.equal(head.status,200);assert.equal(head.headers.get('content-type'),'image/png');assert.equal(await head.text(),'');
}
assert.equal((await app(new Request(origin+'/cp-v2/art/quests/arrival-icon.png'))).status,200);
const post=await app(new Request(origin+'/v2/art/quests/arrival-icon.png',{method:'POST'}));assert.equal(post.status,405);
for(const path of ['/v2/art/quests/unknown-icon.png','/v2/art/quests/arrival-icon.png.js','/v2/art/quests/arrival%2Ficon.png','/v2/art/quests/../../server.mjs'])assert.equal((await app(new Request(origin+path))).status,404,path);
}finally{db.close();}
});