Merge branch 'main' into own-carrier-egress
This commit is contained in:
commit
b8845413d3
10 changed files with 103 additions and 9 deletions
51
tests/focus-link.test.js
Normal file
51
tests/focus-link.test.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})";
|
||||
// Where a world point lands on screen, in whichever wrapped copy of the map is nearest the middle.
|
||||
const onScreen = (ev, x, y) => JSON.parse(ev(`JSON.stringify([-1,0,1].map(k=>toS(${x},${y},k)).sort((p,q)=>Math.abs(p[0]-CW/2)-Math.abs(q[0]-CW/2))[0])`));
|
||||
const ends = (ev, id) => JSON.parse(ev(`JSON.stringify((()=>{const l=S.links.find(x=>x.id==='${id}');return [CITY[l.a],CITY[l.b]].map(c=>[c.x,c.y]);})())`));
|
||||
const inBox = (p, b, why) => assert.ok(p[0] >= b[0] && p[0] <= b[2] && p[1] >= b[1] && p[1] <= b[3], `${why}: ${p} not in ${b}`);
|
||||
|
||||
test('Inspect on a congested link moves the map to that link', () => {
|
||||
const { ev, errors, dom } = load();
|
||||
ev(start);
|
||||
ev("S.links.push({id:'hot',a:'fra',b:'ams',kind:'wave',tier:0,km:400,mo:100,cut:0});R.load.hot=capOf(S.links.find(l=>l.id==='hot'))*0.95");
|
||||
ev("const C=CITY.syd;cam.x=C.x;cam.y=C.y;cam.z=0.8;UI.left='noc';UI.leftOpen=true;renderLeft()");
|
||||
ev("document.querySelector('#leftBody [data-act=selLink][data-args*=hot]').click()");
|
||||
assert.equal(ev('UI.sel.id'), 'hot');
|
||||
assert.ok(ev('cam.z') >= 1.2, 'a short link zooms in like a city does');
|
||||
const box = [0, 0, ev('CW'), ev('CH')];
|
||||
for (const [x, y] of ends(ev, 'hot')) inBox(onScreen(ev, x, y), box, 'both cities are on screen');
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('a long link zooms out to fit, and stays clear of a bottom sheet', () => {
|
||||
const { ev, errors, dom } = load();
|
||||
ev(start);
|
||||
ev("S.links.push({id:'far',a:'fra',b:'sin',kind:'wave',tier:0,km:10000,mo:100,cut:0})");
|
||||
// jsdom lays nothing out, so stand in for a phone's bottom sheet covering the lower 60% of the map.
|
||||
ev("$('panel').getBoundingClientRect=()=>({left:0,top:CH*0.4,width:CW,height:CH*0.6,right:CW,bottom:CH});cam.z=3");
|
||||
ev("ACT.selLink({id:'far'})");
|
||||
assert.ok(ev('cam.z') < 1.2, 'zoomed out for a long link');
|
||||
const box = [0, 0, ev('CW'), ev('CH*0.4')];
|
||||
for (const [x, y] of ends(ev, 'far')) inBox(onScreen(ev, x, y), box, 'both cities are above the sheet');
|
||||
// The drawn line, not just its ends, fits.
|
||||
for (const [x, y] of JSON.parse(ev("JSON.stringify(linkGeom(S.links.find(l=>l.id==='far')).pts)"))) inBox(onScreen(ev, x, y), box, 'the whole line is above the sheet');
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('a puzzle keeps its own framing when a link is opened', () => {
|
||||
const { ev, errors, dom } = load();
|
||||
ev("ACT.pzStart({id:'hello'})");
|
||||
ev("S.links.push({id:'pz',a:'nyc',b:'lon',kind:'wave',tier:0,km:5600,mo:100,cut:0})");
|
||||
const before = ev('JSON.stringify(cam)');
|
||||
ev("ACT.selLink({id:'pz'})");
|
||||
assert.equal(ev('UI.sel.id'), 'pz');
|
||||
assert.equal(ev('JSON.stringify(cam)'), before, 'the camera stays on the whole puzzle');
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
|
@ -635,3 +635,12 @@ test('#244 the PNI order counts the traffic the PNI list shows at that POP, not
|
|||
assert.equal(ev("S.pni.some(p=>p.city==='ham'&&p.net==='nfx')"), true, 'ordered once the traffic is really there');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#249 a city without a POP opens while the transit order is set to Already connected', t => {
|
||||
const { ev, dom, errors } = game(t, '');
|
||||
hire(ev); on(ev, 'transit', { x: 1.5, prov: 'have' });
|
||||
ev("selectCity('lon')");
|
||||
assert.match(dom.window.document.getElementById('panelBody').textContent, /London/);
|
||||
assert.equal(ev("opsProv('lon')&&opsProv('lon').id"), ev("cheapestTransit('lon')&&cheapestTransit('lon').id"), 'the quote uses the cheapest seller');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -118,3 +118,17 @@ test('balanced caches keep serving when either site fails', t => {
|
|||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('more boxes while demand outgrows them, balanced across sites (#248)', t => {
|
||||
const { ev, errors } = setup(t);
|
||||
ev("Object.assign(S.pops.fra,{site2:true,routers:2});S.caches=[{id:'a1',city:'fra',net:'cfl',site:'a'},{id:'b1',city:'fra',net:'cfl',site:'b'}];compute();R.demTo={cfl:NET.cfl.cache.min};R.cityDem.fra=450/NSH.cfl");
|
||||
const add = JSON.parse(ev("JSON.stringify(utilityCaches('fra').add)"));
|
||||
assert.deepEqual(add.map(x => x.net + '@' + x.site), ['cfl@a', 'cfl@b', 'cfl@a'], '450G needs five 100G boxes: three more, spread over both sites');
|
||||
ev("R.cityDem.fra=150/NSH.cfl");
|
||||
assert.equal(ev("utilityCaches('fra').add.length"), 0, 'two boxes already carry 150G');
|
||||
// Requesting them adds just what is missing.
|
||||
ev("R.cityDem.fra=350/NSH.cfl");
|
||||
ev("ACT.utilityCaches({city:'fra',quote:utilityCaches('fra').key})");
|
||||
assert.equal(ev("S.caches.filter(c=>c.net==='cfl').length"), 4);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue