web/website/tests/client-clans.test.mjs
unimatrixgit 9e833a4db9
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m26s
Restore scrolling for directly opened organisation control panels
2026-11-29 21:05:16 +01:00

28 lines
3.3 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {clientClanRows} from '../control-panel/public/cp-v2/cp-v2-client-clans.mjs';
import {jarvisApplicationDocument} from '../control-panel/jarvis-application-shell.mjs';
import {readFile} from 'node:fs/promises';
import {runInNewContext} from 'node:vm';
const clan=(id,name=id)=>({id:'clan:'+id,kind:'clan',name});
test('client register includes every descendant, excludes the parent and unrelated clans, and preserves direct allegiance',()=>{
const network={nodes:[clan('parent'),clan('other'),...Array.from({length:14},(_,i)=>clan('child'+i)),clan('grandchild')],edges:[...Array.from({length:14},(_,i)=>({from:'clan:parent',to:'clan:child'+i})),{from:'clan:child0',to:'clan:grandchild'}]};
const rows=clientClanRows(network,'parent');assert.equal(rows.length,15);assert.equal(rows.filter(r=>r.direct).length,14);assert.equal(rows.find(r=>r.id==='clan:grandchild').parentName,'child0');assert.equal(rows.find(r=>r.id==='clan:grandchild').depth,2);assert.equal(rows.some(r=>['clan:parent','clan:other'].includes(r.id)),false);
assert.deepEqual(clientClanRows(network,'other'),[]);
});
test('confirmed graph traversal tolerates duplicate edges, cannot loop, and does not assume all intermediates are clans',()=>{
const network={nodes:[clan('parent'),{id:'company:mid',kind:'company',name:'Company'},clan('child')],edges:[{from:'clan:parent',to:'company:mid'},{from:'company:mid',to:'clan:child'},{from:'company:mid',to:'clan:child'},{from:'clan:child',to:'clan:parent'}]};
const rows=clientClanRows(network,'parent');assert.equal(rows.length,1);assert.equal(rows[0].parentName,'Company');assert.equal(rows[0].direct,false);assert.throws(()=>clientClanRows(network,'missing'));assert.throws(()=>clientClanRows({},'parent'));
});
test('standalone application shell opts into its own document scrolling and retains the existing embedded clan shell',async()=>{
const source=await readFile(new URL('../control-panel/public/cp-v2/index.html',import.meta.url),'utf8'),html=jarvisApplicationDocument(source),css=await readFile(new URL('../control-panel/public/cp-v2/cp-v2-jarvis.css',import.meta.url),'utf8');
assert.match(html,/class="clan-cp-shell jarvis-standalone-shell"/);assert.match(html,/href="\/v2\/cp-v2-jarvis.css"/);assert.doesNotMatch(html,/cp-v2-clan-size.mjs/);assert.match(css,/html:has\(body\.jarvis-standalone-shell\)\{[^}]*overflow-y:auto/);
const clanCSS=await readFile(new URL('../control-panel/public/cp-v2/cp-v2-clan-shell.css',import.meta.url),'utf8');assert.match(clanCSS,/html:has\(body\.clan-cp-shell\)\{overflow:auto\}/);assert.match(clanCSS,/html\.dune-embedded:has\(body\.clan-cp-shell\)\{overflow:hidden\}/);
});
test('clan sizing marks only embedded documents so direct CP pages retain native page scrolling',async()=>{
const source=await readFile(new URL('../control-panel/public/cp-v2/cp-v2-clan-size.mjs',import.meta.url),'utf8');
for(const embedded of [false,true]){
const added=[],window={addEventListener(){}},parent=embedded?{}:window;
runInNewContext(source,{window,parent,URL,document:{referrer:'https://clans.dunerealms.com/',documentElement:{classList:{add:name=>added.push(name)}},body:{}},requestAnimationFrame(){},ResizeObserver:class{observe(){}}});
assert.deepEqual(added,embedded?['dune-embedded']:[]);
}
});