// #196: the two city names at the top of a link panel (wave, dark fiber, virtual circuit, express, satellite circuit) open // that city's panel. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;"; const ends = ev => JSON.parse(ev("JSON.stringify([...document.querySelectorAll('#panel .ph h2 button[data-act=\"popGo\"]')].map(b=>[b.textContent,JSON.parse(b.dataset.args).city]))")); const click = (ev, i) => ev(`document.querySelectorAll('#panel .ph h2 button[data-act="popGo"]')[${i}].click()`); function setup(ev) { ev(start + "ACT.launchBB({city:'fra'});ACT.buildPop({city:'ams'});compute()"); ev("S.links.push({id:'w1',a:'fra',b:'ams',kind:'wave',tier:0,km:360,sub:false,mo:1,cut:0,day:0})"); ev("S.links.push({id:'df1',a:'fra',b:'ams',kind:'df',own:false,sys:'lite',ch:[],km:360,sub:false,mo:1,ready:0,cut:0,day:0})"); ev("S.links.push({id:'vx1',a:'fra',b:'ams',kind:'vxc',prov:Object.keys(FAB)[0],vt:0,km:360,sub:false,mo:1,cut:0,day:0});compute()"); } for (const [id, kind] of [['w1', 'wave'], ['df1', 'dark fiber'], ['vx1', 'virtual circuit']]) { test(`#196 a ${kind} panel links both of its cities, and a click opens the city`, () => { const { ev, errors } = load(); setup(ev); ev(`selectLink('${id}')`); assert.deepEqual(ends(ev), [['Frankfurt', 'fra'], ['Amsterdam', 'ams']]); assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Frankfurt ⇄ Amsterdam/); click(ev, 1); assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:ams', 'the far end is selected'); assert.equal(ev("cam.x"), ev("CITY.ams.x"), 'and the map moves to it'); assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Amsterdam/); ev(`selectLink('${id}')`); click(ev, 0); assert.equal(ev("UI.sel.id"), 'fra'); assert.deepEqual(errors, []); }); } test('#196 on a 390 px phone the city links sit in the bottom sheet header and still open the city', () => { const { ev, errors } = load(); setup(ev); ev("window.innerWidth=390;renderAll();selectLink('w1')"); assert.equal(ev("isPhone()"), true); assert.equal(ends(ev).length, 2); // The link styling: reads as heading text that wraps, not a button that pushes the header wider. assert.match(ev("document.querySelector('#panel .ph h2 button').className"), /\bclink\b/); click(ev, 0); assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:fra'); assert.deepEqual(errors, []); }); test('#196 a city the map does not show stays plain text', () => { const { ev, errors } = load(); setup(ev); ev("selectLink('w1')"); // cityOn() is false for an off-map city without a POP or IX port: no button to a panel that would not open. ev("CITY.ams.off=true;delete S.pops.ams;renderPanel()"); assert.deepEqual(ends(ev), [['Frankfurt', 'fra']]); assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Frankfurt ⇄ Amsterdam/); ev("delete CITY.ams.off"); assert.deepEqual(errors, []); }); test('#196 #329 an express and a satellite circuit name their cities as links too, and a circuit says when a border closed it', () => { const { ev, errors } = load(); const panel = () => ev("document.getElementById('panel').textContent"); ev(start + "ACT.launchBB({city:'fra'});for(const c of ['bru','par','doh','auh'])ACT.buildPop({city:c});for(const c of ['fra','bru','par'])S.pops[c].rgen=1;compute()"); ev("for(const [id,a,b] of [['s1','fra','bru'],['s2','bru','par']])S.links.push({id,a,b,kind:'df',own:true,sys:'roadm',ch:[],km:kmBetween(a,b),sub:false,cable:null,mo:100,trench:id,cut:0,day:0,ready:0,spares:false,pairs:1});compute()"); ev("ACT.xpBuild({a:'fra',b:'par',via:'s1,s2',o:'zr4'});compute();selectLink(S.links.find(l=>l.kind==='xp').id)"); assert.deepEqual(ends(ev), [['Frankfurt', 'fra'], ['Paris', 'par']], 'the express'); click(ev, 1); assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:par'); // A GEO circuit across the Gulf: fine today, dark with a reason once the border closes. ev("const id=Object.keys(SATS).find(k=>SATS[k].orb==='geo');S.links.push({id:'st1',a:'doh',b:'auh',kind:'sat',bird:id,g:SAT_ORB.geo.g[0],km:72000,mo:1000,cut:0,day:0,ready:0});compute();selectLink('st1')"); assert.deepEqual(ends(ev), [[ev('CITY.doh.name'), 'doh'], [ev('CITY.auh.name'), 'auh']], 'the satellite circuit'); assert.doesNotMatch(panel(), /Border closed/); ev('S.ev.gulf=S.day+10;compute();renderPanel()'); assert.match(panel(), /Border closed/); assert.match(panel(), /Qatar/); assert.deepEqual(errors, []); });