forked from unimatrix/web
11 lines
2.8 KiB
JavaScript
11 lines
2.8 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';
|
|
import {mountClanRebellions} from '../control-panel/public/cp-v2/cp-v2-rebellions.mjs';import {rebellionQuest} from '../node/rebellion-quest-policy.mjs';
|
|
class Element{constructor(tag){this.tagName=tag.toUpperCase();this.children=[];this.dataset={};this.attributes={};this.disabled=false;this.textContent='';}get childNodes(){return this.children;}append(...nodes){this.children.push(...nodes);}prepend(...nodes){this.children.unshift(...nodes);}replaceChildren(...nodes){this.children=nodes;}setAttribute(k,v){this.attributes[k]=v;}removeAttribute(k){delete this.attributes[k];}querySelectorAll(selector){return tree(this).filter(n=>selector==='button'&&n.tagName==='BUTTON');}addEventListener(type,fn){(this.listeners||={})[type]=fn;}contains(node){return tree(this).includes(node);}showModal(){this.open=true;}close(){this.open=false;this.listeners?.close?.();}focus(){}remove(){}}
|
|
const tree=n=>[n,...n.children.flatMap(tree)],settle=()=>new Promise(r=>setImmediate(r));
|
|
test('the existing Missions view displays available rebellion cards and sends the player to Decisions; cooldown decisions remain disabled',async()=>{
|
|
const before=globalThis.document;globalThis.document={createElement:t=>new Element(t),createTextNode:t=>{const e=new Element('text');e.textContent=t;return e;}};let dispose;
|
|
try{const definition=rebellionQuest('atreides'),choice={...definition,eligible:true,target:{sourceTermId:'term',homeBlockId:'home',defenderName:'House Aerdrecht',expiresAt:Date.now()+86400000}},host=new Element('main');let opened=0;const fetcher=async()=>Response.json({clanId:'clan',choices:[choice],quests:[],canDeclare:true});
|
|
dispose=mountClanRebellions(host,{embedded:true,view:'missions',fetcher,onDecisions:()=>opened++});await settle();assert.ok(tree(host).some(n=>n.textContent===definition.title));const card=tree(host).find(n=>n.className==='progression-dossier-card');assert.equal(card.dataset.channel,'shared');assert.ok(!tree(host).some(n=>n.textContent==='Open clan decisions'));card.onclick();const open=tree(host).find(n=>n.textContent==='Open clan decisions');assert.ok(open);open.onclick();assert.equal(opened,1);assert.ok(!tree(host).some(n=>n.textContent==='Declare open rebellion'));dispose();
|
|
dispose=mountClanRebellions(host,{embedded:true,view:'decisions',fetcher:async()=>Response.json({clanId:'clan',choices:[{...choice,eligible:false,cooldownUntil:Date.now()+86400000,reason:'This clan must wait 15 days after its previous rebellion key.'}],quests:[]})});await settle();tree(host).find(n=>n.className==='progression-dossier-card').onclick();assert.equal(tree(host).find(n=>n.textContent==='Declare open rebellion').disabled,true);
|
|
}finally{dispose?.();if(before===undefined)delete globalThis.document;else globalThis.document=before;}
|
|
});
|

Staff