forked from unimatrix/web
19 lines
2.5 KiB
JavaScript
19 lines
2.5 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';
|
|
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:hidden\}/);
|
|
});
|

Staff