import test from 'node:test'; import assert from 'node:assert/strict'; import vm from 'node:vm'; import {readFileSync} from 'node:fs'; const source=readFileSync(new URL('./public/app.js',import.meta.url),'utf8'); const apply=source.slice(source.indexOf('function applyStation(user){'),source.indexOf("\ndocument.addEventListener('bpq-languagechange'")); for(const populated of [false,true]){ test(`station login succeeds with ${populated?'existing chat messages':'the initial chat placeholder'}`,()=>{ const elements=new Map(); const $=selector=>{ if(populated&&selector.startsWith('.chat-empty'))return null; if(!elements.has(selector))elements.set(selector,{firstChild:{},closest(){return this;}}); return elements.get(selector); }; const station={nodeCall:'TEST-7',call:'TEST',alias:'NODE',apps:[],features:{bbs:true,chat:true,winlink:true,monitor:true,radio:true,vara:true}}; const context=vm.createContext({$, $$:()=>[],station,document:{},BPQI18n:{t:s=>s},page:'home',navigate(){}}); vm.runInContext(apply,context); assert.doesNotThrow(()=>context.applyStation({name:'Sysop',call:'TEST'})); assert.equal($('.wl-account').textContent,'TEST@winlink.org'); if(!populated)assert.equal($('.chat-empty h2').textContent,'Chat BPQ'); }); }