Merge branch 'main' into main
This commit is contained in:
commit
39063acce7
38 changed files with 596 additions and 145 deletions
56
tests/any-home-city.test.js
Normal file
56
tests/any-home-city.test.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const choose = (ev, v) => ev(`(()=>{const s=document.getElementById('homeSel');s.value=${JSON.stringify(v)};s.dispatchEvent(new Event('change',{bubbles:true}));})()`);
|
||||
const onTiles = ev => JSON.parse(ev("JSON.stringify([...document.querySelectorAll('.starts .start.on')].map(b=>b.dataset.city||'own'))"));
|
||||
|
||||
test('the title screen offers five homes and a sixth tile for any city, grouped by continent', () => {
|
||||
const { ev, errors } = load();
|
||||
assert.equal(ev('S'), null, 'before any game exists');
|
||||
assert.equal(ev("document.querySelectorAll('.starts .start').length"), 6);
|
||||
const opts = JSON.parse(ev("JSON.stringify([...document.querySelectorAll('#homeSel option')].map(o=>o.value).filter(Boolean))"));
|
||||
assert.ok(opts.length > 150, `lots of cities (${opts.length})`);
|
||||
assert.ok(opts.every(c => ev(`homeOk('${c}')`)), 'only cities that work as a home');
|
||||
assert.ok(!opts.some(c => ev(`!!CITY['${c}'].cn||!!CITY['${c}'].off`)), 'no hidden or Chinese cities');
|
||||
assert.ok(!opts.includes('stg'), 'no city without transit to buy');
|
||||
assert.ok(ev("document.querySelectorAll('#homeSel optgroup').length") >= 5, 'grouped by continent');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('picking any city starts the network there, and the tiles follow the choice', () => {
|
||||
const { ev, errors } = load();
|
||||
choose(ev, 'lis');
|
||||
assert.equal(ev('UI.startCity'), 'lis');
|
||||
assert.deepEqual(onTiles(ev), ['own'], 'the sixth tile lights up');
|
||||
assert.equal(ev("document.getElementById('homeWhat').textContent"), 'Lisbon · ' + ev("REG[CITY.lis.reg]"), 'and names the city in full');
|
||||
ev("document.querySelector('.start[data-city=nyc]').click()");
|
||||
assert.deepEqual(onTiles(ev), ['nyc'], 'a suggested tile takes over again');
|
||||
assert.equal(ev("document.getElementById('homeSel').value"), '', 'and the dropdown resets');
|
||||
assert.match(ev("document.getElementById('homeWhat').textContent"), /more cities/);
|
||||
choose(ev, 'akl');
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
|
||||
assert.equal(ev('S.home'), 'akl');
|
||||
assert.ok(ev("!!S.pops.akl"), 'the first POP is in Auckland');
|
||||
assert.ok(ev("NETS.some(n=>sellsAt(n,'akl'))"), 'with transit to buy');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a home that cannot work is refused, and the game falls back to Frankfurt', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.pickStart({city:'stg'});ACT.pickStart({city:'pek'});ACT.pickStart({city:'nowhere'})");
|
||||
assert.equal(ev('UI.startCity'), 'fra');
|
||||
ev("UI.startCity='pek';ACT.start({})");
|
||||
assert.equal(ev('S.home'), 'fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the sixth tile works on a phone and in every language', () => {
|
||||
for (const lang of ['en', 'it', 'pt', 'fr', 'es']) {
|
||||
const { ev, errors } = load(lang === 'en' ? {} : { lang });
|
||||
ev('window.innerWidth=360;showTitle()');
|
||||
assert.equal(ev("document.querySelector('label.start.own b').textContent"), ev("tr('title.anywhere_else')"), lang);
|
||||
if (lang !== 'en') assert.notEqual(ev("tr('title.anywhere_else')"), 'Anywhere else', `${lang}: translated`);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
|
|
@ -108,9 +108,10 @@ test('the static markup is translated by label', () => {
|
|||
assert.equal(ev("document.querySelector('[data-act=help]').getAttribute('aria-label')"), ev("tr('common.how_to_play')"));
|
||||
});
|
||||
|
||||
test('the language buttons on the title screen work before any game exists', () => {
|
||||
test('the language dropdown on the title screen works before any game exists', () => {
|
||||
const { ev } = load();
|
||||
ev("[...document.querySelectorAll('#modalCard [data-act=langSet]')].find(b=>b.textContent==='Italiano').click()");
|
||||
assert.equal(ev('S'), null);
|
||||
ev("const s=document.querySelector('#modalCard select#langTitle');s.value='it';s.dispatchEvent(new Event('change',{bubbles:true}))");
|
||||
assert.equal(ev("localStorage.getItem('sot-lang')"), 'it');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -331,7 +331,8 @@ test('#40 overland between continents costs ten times subsea or more, and has no
|
|||
const sub=waveMo(c.km,true,2)*CAB[c.cid].price*waveMarket(c.a,c.b,true).m;return [land/sub,!!(CITY[c.a].land2||CITY[c.b].land2)];}))`));
|
||||
assert.ok(r.length >= 4, 'Europe–Asia cable routes exist to compare');
|
||||
// Across a land bridge (Cairo, #47) the cable goes the long way round Arabia, so overland is "only" 4–9× dearer.
|
||||
for (const [x, bridge] of r) assert.ok(x >= (bridge ? 4 : 10), `overland is at least ${bridge ? 4 : 10}× subsea (${x.toFixed(1)})`);
|
||||
// EIG from Dubai now follows Arabia and the Suez Canal at sea, which makes it a little longer: 9.97× (#183).
|
||||
for (const [x, bridge] of r) assert.ok(x >= (bridge ? 4 : 9.5), `overland is at least ${bridge ? 4 : 9.5}× subsea (${x.toFixed(1)})`);
|
||||
assert.equal(ev("landX('mrs','hkg')"), true);
|
||||
assert.equal(ev("landX('fra','mrs')"), false, 'inside Europe stays normal');
|
||||
assert.equal(ev("landMult('fra','mrs')"), 1);
|
||||
|
|
|
|||
39
tests/language-picker.test.js
Normal file
39
tests/language-picker.test.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const pick = (ev, id) => JSON.parse(ev(`(()=>{const s=document.getElementById('${id}');return JSON.stringify(s&&{tag:s.tagName,value:s.value,chg:s.dataset.chg,
|
||||
opts:[...s.options].map(o=>[o.value,o.textContent,o.lang]),label:(document.querySelector('label[for=${id}]')||{}).textContent});})()`));
|
||||
|
||||
test('language is one dropdown on the title screen and in Settings, in every language, with the current one selected', () => {
|
||||
for (const lang of ['en', 'it', 'pt', 'fr', 'es']) {
|
||||
const { ev, errors } = load(lang === 'en' ? {} : { lang });
|
||||
const langs = JSON.parse(ev('JSON.stringify(Object.entries(LANGS))'));
|
||||
const title = pick(ev, 'langTitle');
|
||||
assert.equal(title.tag, 'SELECT', `${lang}: title screen`);
|
||||
assert.equal(title.value, lang);
|
||||
assert.deepEqual(title.opts, langs.map(([v, l]) => [v, l, v]), `${lang}: every language, named in itself`);
|
||||
assert.equal(title.label, ev("tr('common.language')"), `${lang}: labelled`);
|
||||
assert.equal(ev("document.querySelectorAll('#modalCard [data-act=langSet]').length"), 0, `${lang}: no language buttons left`);
|
||||
ev("ACT.start({});ACT.settings()");
|
||||
const set = pick(ev, 'langSel');
|
||||
assert.equal(set.value, lang, `${lang}: settings`);
|
||||
assert.equal(set.label, ev("tr('common.language')"));
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
|
||||
test('changing the dropdown in Settings switches language and keeps the game', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});dayTick();ACT.settings();const s=document.getElementById('langSel');s.value='fr';s.dispatchEvent(new Event('change',{bubbles:true}))");
|
||||
assert.equal(ev("localStorage.getItem('sot-lang')"), 'fr');
|
||||
assert.ok(ev("localStorage.getItem('sot-save-v1')"), 'saved before reloading');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the dropdown fits a phone', () => {
|
||||
const { ev, errors } = load();
|
||||
ev('window.innerWidth=360;showTitle()');
|
||||
assert.ok(ev("document.getElementById('langTitle').classList.contains('pick')"));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
139
tests/link-metrics.test.js
Normal file
139
tests/link-metrics.test.js
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Waves between Frankfurt and Amsterdam (tier 3 is 800G, tier 0 is 10G), transit in Amsterdam, eyeballs in Frankfurt.
|
||||
function setup(ev, tiers = [3, 3]) {
|
||||
ev("ACT.start({});S.cash=1e8;S.lvl=4;for(const g of GOALS)S.done[g.id]=0");
|
||||
ev("ACT.buildPop({city:'ams'});for(const c in S.pops){S.pops[c].rgen=3;S.pops[c].routers=2}");
|
||||
ev("ACT.launchBB({city:'fra'});ACT.buyTransit({city:'ams',net:'lvl',tier:3})");
|
||||
tiers.forEach((t, i) => ev(`UI.via=null;openLinkModal('fra','ams');ACT.buildLink({tier:${t}});closeModal();S.links[S.links.length-1].tag=${i}`));
|
||||
ev("var L=i=>S.links.find(l=>l.tag===i),L1=L(0),L2=L(1);compute()");
|
||||
}
|
||||
const load_ = (ev, x) => ev(`R.load[${x}.id]||0`);
|
||||
const body = dom => dom.window.document.body.textContent;
|
||||
|
||||
test('#122 the routing metric belongs to the city pair', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
ev("ACT.setMetric({id:L2.id,v:'avoid'})");
|
||||
assert.equal(ev("S.pairMet['ams|fra']"), 'avoid');
|
||||
ev("ACT.selLink({id:L1.id});renderAll()");
|
||||
assert.ok(ev("[...document.querySelectorAll('[data-act=\"setMetric\"]')].some(b=>b.className.includes('pink')&&/Avoid/.test(b.textContent))"), 'the other link shows the same metric');
|
||||
ev("ACT.setMetric({id:L1.id,v:'normal'})");
|
||||
assert.equal(ev("'ams|fra' in S.pairMet"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 a link on standby idles while the others have room and takes over when they fail', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev);
|
||||
const total = ev("R.served");
|
||||
assert.ok(load_(ev, 'L1') > 0 && load_(ev, 'L2') > 0, 'active links share the load');
|
||||
ev("ACT.setStandby({id:L2.id,on:1});compute()");
|
||||
assert.equal(ev("L2.standby"), true);
|
||||
assert.ok(load_(ev, 'L1') > 0);
|
||||
assert.equal(load_(ev, 'L2'), 0, 'standby link idles');
|
||||
assert.ok(Math.abs(ev("R.served") - total) < 1e-6, 'nothing is lost');
|
||||
ev("ACT.selLink({id:L2.id});renderAll()");
|
||||
assert.match(body(dom), /On standby: idle while the other links/);
|
||||
ev("L1.cut=S.day+5;compute();renderAll()");
|
||||
assert.ok(load_(ev, 'L2') > 0, 'standby link takes over when the active one is cut');
|
||||
assert.match(body(dom), /On standby, but carrying the traffic/);
|
||||
// Every link on standby: they share the traffic like active ones, and the note does not claim the others are down.
|
||||
ev("L1.cut=0;ACT.setStandby({id:L1.id,on:1});compute();renderAll()");
|
||||
assert.ok(load_(ev, 'L1') > 0 && load_(ev, 'L2') > 0);
|
||||
assert.match(body(dom), /no active link between these cities is up/);
|
||||
ev("ACT.setStandby({id:L2.id,on:0})");
|
||||
assert.equal(ev("'standby' in L2"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 a standby link takes the overflow when the active links are full', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev, [0, 3]); // 10G active, 800G next to it
|
||||
const total = ev("R.served");
|
||||
ev("ACT.setStandby({id:L2.id,on:1});compute()");
|
||||
const cap = ev("capOf(L1)");
|
||||
assert.ok(Math.abs(load_(ev, 'L1') - cap) < 1e-6, 'the active link fills up first');
|
||||
assert.ok(load_(ev, 'L2') > 0, 'the rest spills onto the standby link');
|
||||
assert.ok(Math.abs(ev("R.served") - total) < 1e-6, 'standby capacity is never wasted');
|
||||
ev("ACT.selLink({id:L2.id});renderAll()");
|
||||
assert.match(body(dom), /taking the overflow/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 the order links are built in does not change where traffic goes', () => {
|
||||
const tiers = [3, 0, 3], standby = [true, false, false], seen = new Set();
|
||||
for (const order of [[0, 1, 2], [2, 1, 0], [1, 0, 2], [2, 0, 1]]) {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e8;S.lvl=4;for(const g of GOALS)S.done[g.id]=0");
|
||||
ev("ACT.buildPop({city:'ams'});for(const c in S.pops){S.pops[c].rgen=3;S.pops[c].routers=2}");
|
||||
ev("ACT.launchBB({city:'fra'});ACT.buyTransit({city:'ams',net:'lvl',tier:3})");
|
||||
for (const i of order) ev(`UI.via=null;openLinkModal('fra','ams');ACT.buildLink({tier:${tiers[i]}});closeModal();const l=S.links[S.links.length-1];l.tag=${i};if(${standby[i]})ACT.setStandby({id:l.id,on:1})`);
|
||||
ev("ACT.setMetric({id:S.links[0].id,v:'prefer'});compute()");
|
||||
seen.add(ev("JSON.stringify([0,1,2].map(i=>Math.round((R.load[S.links.find(l=>l.tag===i).id]||0)*1e6)))"));
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
assert.equal(seen.size, 1, [...seen].join(' vs '));
|
||||
});
|
||||
|
||||
test('#122 a new link between the same cities adds capacity and keeps the pair metric', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev, [0]);
|
||||
ev("ACT.setMetric({id:L1.id,v:'avoid'});ACT.setStandby({id:L1.id,on:1});compute()");
|
||||
const before = ev("R.served");
|
||||
ev("UI.via=null;openLinkModal('fra','ams');ACT.buildLink({tier:3});closeModal();compute()");
|
||||
const nl = "S.links[S.links.length-1]";
|
||||
assert.equal(ev(`'standby' in ${nl}`), false, 'a new link starts active');
|
||||
assert.equal(ev("pairMet('ams|fra')"), 'avoid');
|
||||
assert.ok(ev("R.served") > before, 'more capacity, more traffic');
|
||||
// The metric leaves with the last link, so a fresh link later starts on normal.
|
||||
for (const id of ev("S.links.map(l=>l.id)")) ev(`UI.confirm=null;ACT.rmLink({id:'${id}'});ACT.rmLink({id:'${id}'})`);
|
||||
assert.equal(ev("'ams|fra' in S.pairMet"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 old saves keep routing as before: per-link metrics become the pair metric', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
// Every link on avoid: the pair is on avoid.
|
||||
ev("delete S.pairMet;L1.metric='avoid';L2.metric='avoid';S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev("S.pairMet['ams|fra']"), 'avoid');
|
||||
assert.equal(ev("S.links.some(l=>'metric' in l)"), false);
|
||||
// Mixed metrics routed at the lowest one, all links carrying: no standby, normal.
|
||||
ev("S.pairMet={};S.links[0].metric='backup';S.links[1].standby='yes';S=migrate(JSON.parse(JSON.stringify(S)));compute()");
|
||||
assert.equal(ev("'ams|fra' in S.pairMet"), false);
|
||||
assert.equal(ev("S.links.some(l=>'standby' in l||'metric' in l)"), false);
|
||||
assert.ok(ev("S.links.every(l=>R.load[l.id]>0)"));
|
||||
// Junk in the new field is dropped.
|
||||
ev("S.pairMet={'ams|fra':'warp','fra|lon':'avoid'};S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.pairMet)")), {});
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 traceroute shows an active link, not one on standby', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
ev("ACT.setStandby({id:L1.id,on:1})");
|
||||
assert.equal(ev("trPaths('ams').path('fra')[0].l.id===L2.id"), true);
|
||||
ev("ACT.setStandby({id:L1.id,on:0});ACT.setStandby({id:L2.id,on:1})");
|
||||
assert.equal(ev("trPaths('ams').path('fra')[0].l.id===L1.id"), true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#122 the standby button shows next to another link, on desktop and phone', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev);
|
||||
for (const w of [1280, 390]) {
|
||||
ev(`window.innerWidth=${w};ACT.selLink({id:L1.id});renderAll()`);
|
||||
const b = dom.window.document.querySelector('[data-act="setStandby"]');
|
||||
assert.ok(b, `standby button at ${w}px`);
|
||||
assert.match(b.textContent, /Put this link on standby/);
|
||||
}
|
||||
ev("S.links=S.links.filter(l=>l!==L2);ACT.selLink({id:L1.id});renderAll()");
|
||||
assert.equal(dom.window.document.querySelector('[data-act="setStandby"]'), null, 'nothing to stand by for');
|
||||
ev("L1.standby=true;renderAll()");
|
||||
assert.match(dom.window.document.querySelector('[data-act="setStandby"]').textContent, /Take it off standby/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -41,6 +41,18 @@ test('the Indian Ocean and Asia-Pacific: the big real cables, Muscat, the Maldiv
|
|||
}
|
||||
// every cable pair has a drawn route and a sane length
|
||||
assert.equal(ev("CABLE_PAIRS.filter(p=>!(p.km>0&&p.km<25000)||p.pts.some(q=>!isFinite(q[0])||!isFinite(q[1]))).length"), 0);
|
||||
// no route jumps across the whole map at the ±180° seam: waypoints keep continuous longitudes (#183)
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(CABLE_PAIRS.filter(p=>p.pts.some((q,i)=>i&&Math.abs(q[0]-p.pts[i-1][0])>W/3)).map(p=>p.cid+':'+p.a+'-'+p.b))")), []);
|
||||
assert.ok(ev("cablePair('fast','sea','osa').km") < 9500, 'FASTEST to Osaka crosses the Pacific, not the world');
|
||||
// subsea cables stay at sea: a stretch over land with sea on both sides is the line cutting across a coast.
|
||||
// Allowed: the Suez Canal and the Dardanelles (not water in the coastline), and Quintillion's overland Alaska leg.
|
||||
const cross = JSON.parse(ev(`JSON.stringify((()=>{const big=COAST.filter(p=>ringArea(p)>=40).map(p=>{let a=1e9,b=-1e9,c=1e9,d=-1e9;for(const [x,y] of p){a=Math.min(a,x);b=Math.max(b,x);c=Math.min(c,y);d=Math.max(d,y);}return {p,a,b,c,d};});
|
||||
const on=(x,y)=>{x=((x%W)+W)%W;return big.some(q=>x>=q.a&&x<=q.b&&y>=q.c&&y<=q.d&&inPoly(x,y,q.p));};const out=[];
|
||||
for(const p of CABLE_PAIRS){if(p.cid==='qtl'&&[p.a,p.b].sort().join()==='anc,brw')continue;const s=[];
|
||||
for(let i=1;i<p.pts.length;i++){const [x0,y0]=p.pts[i-1],[x1,y1]=p.pts[i];const n=Math.max(1,Math.ceil(Math.hypot(x1-x0,y1-y0)/1.5));for(let k=(i===1?0:1);k<=n;k++)s.push([x0+(x1-x0)*k/n,y0+(y1-y0)*k/n]);}
|
||||
const L=s.map(q=>on(q[0],q[1]));let i=0;while(i<L.length){if(!L[i]){i++;continue;}let j=i;while(j+1<L.length&&L[j+1])j++;const km=(j-i+1)*p.km/s.length;if(i>0&&j<L.length-1&&km>160)out.push(p.cid+':'+p.a+'-'+p.b+' '+Math.round(km)+' km');i=j+1;}}
|
||||
return out;})())`));
|
||||
assert.deepEqual(cross, [], 'cables cutting across land');
|
||||
// a hop on one of the new cables carries traffic
|
||||
ev("for(const c of ['sin','hkg']){ACT.buildPop({city:c});S.pops[c].rgen=3;}UI.via='sjc2';UI.route='same';openLinkModal('sin','hkg');ACT.buildLink({tier:2});closeModal();compute()");
|
||||
assert.ok(ev("S.links.some(l=>l.cable==='sjc2')"), 'a wave on SJC2');
|
||||
|
|
|
|||
38
tests/new-game-speed.test.js
Normal file
38
tests/new-game-speed.test.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
test('#186 a new network starts at half speed, even after a game at 8×', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev("ACT.start({});ACT.speed({v:8})");
|
||||
assert.equal(ev('UI.speed'), 8);
|
||||
ev("ACT.newgame();ACT.start({})");
|
||||
assert.equal(ev('UI.speed'), 0.5, 'normal game');
|
||||
assert.ok(dom.window.document.getElementById('sp0.5').classList.contains('on'), 'the HUD shows ½×');
|
||||
ev("ACT.speed({v:0});ACT.newgame();UI.mode='sandbox';ACT.start({})");
|
||||
assert.equal(ev('UI.speed'), 0.5, 'sandbox, and a paused game does not stay paused');
|
||||
ev("ACT.speed({v:4});ACT.startScn({id:SCN[0].id,sure:1})");
|
||||
assert.equal(ev('UI.speed'), 0.5, 'scenario');
|
||||
ev("ACT.speed({v:2});ACT.startWeekly({sure:1})");
|
||||
assert.equal(ev('UI.speed'), 0.5, 'weekly challenge');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#186 on a phone, play after pause resumes at half speed, not the old game\'s speed', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("window.innerWidth=360;ACT.start({});ACT.phoneSpeed();ACT.phoneSpeed();ACT.phoneSpeed()");
|
||||
assert.notEqual(ev('UI.lastSpeed'), 0.5);
|
||||
ev("ACT.newgame();ACT.start({});if(UI.pendGame)ACT.pitchSkip();ACT.phonePlay();ACT.phonePlay()");
|
||||
assert.ok(ev("UI.started&&!UI.pendGame"), "the new game is running");
|
||||
assert.equal(ev('UI.speed'), 0.5);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#186 a saved game still continues at the speed it was saved at', () => {
|
||||
const a = load();
|
||||
a.ev("ACT.start({});ACT.speed({v:4});save(true)");
|
||||
const b = load({ storage: { 'sot-save-v1': a.ev("localStorage.getItem('sot-save-v1')") } });
|
||||
assert.equal(b.ev('UI.speed'), 4);
|
||||
assert.deepEqual(a.errors, []);
|
||||
assert.deepEqual(b.errors, []);
|
||||
});
|
||||
|
|
@ -786,8 +786,9 @@ test('Atlantic islands and Halifax: real landings, real exchanges only, and isla
|
|||
assert.equal(hop(['mia', 'pdl', 'lis']), 1600, 'Florida to Lisbon via the Azores');
|
||||
assert.equal(direct('atn', 'lis'), 1200);
|
||||
assert.equal(hop(['atn', 'bda', 'lis']), 1600);
|
||||
assert.equal(direct('lis', 'lag'), 1200);
|
||||
// Equi-yes follows the coast close enough to fit 1.6T on its own; the Canaries hop matches it
|
||||
assert.equal(hop(['lis', 'tci', 'lag']), 1600, 'Lisbon to Lagos via the Canaries');
|
||||
assert.ok(hop(['lis', 'tci', 'lag']) >= direct('lis', 'lag'));
|
||||
assert.equal(direct('for', 'mad'), 1200);
|
||||
assert.equal(hop(['for', 'rai', 'lis']), 1600, 'Brazil to Europe via Cape Verde');
|
||||
assert.equal(hop(['nyc', 'hfx']), 3200);
|
||||
|
|
|
|||
29
tests/report-link.test.js
Normal file
29
tests/report-link.test.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const ISSUES = 'https://github.com/fjaeckel/seriesoftubes/issues/new/choose';
|
||||
|
||||
test('bugs and ideas point to GitHub from the menu and How to play, and the chat no longer asks for bug reports', () => {
|
||||
for (const lang of ['en', 'it', 'pt', 'fr', 'es']) {
|
||||
const { ev, errors } = load(lang === 'en' ? {} : { lang });
|
||||
ev('ACT.start({})');
|
||||
for (const [where, setup] of [['menu', 'ACT.menu()'], ['help', 'showHelp()']]) {
|
||||
const cards = JSON.parse(ev(`(()=>{${setup};return JSON.stringify([...document.querySelectorAll('#modal a[href="${ISSUES}"]')].map(a=>[a.target,a.rel,a.textContent.trim()]));})()`));
|
||||
assert.equal(cards.length, 1, `${lang}: one GitHub card in ${where}`);
|
||||
assert.deepEqual(cards[0].slice(0, 2), ['_blank', 'noopener'], `${lang}: opens in a new tab`);
|
||||
if (lang !== 'en') assert.doesNotMatch(cards[0][2], /Found a bug/, `${lang}: translated`);
|
||||
const chat = ev(`[...document.querySelectorAll('#modal a.chat')].map(a=>a.textContent).join(' ')`);
|
||||
assert.doesNotMatch(chat, /report bugs|segnala bug|reporte bugs|signale des bugs|informa de fallos/, `${lang}: the chat card is for chatting`);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
|
||||
test('the GitHub card fits a phone', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});window.innerWidth=360;ACT.menu()");
|
||||
assert.ok(ev('isPhone()'));
|
||||
assert.ok(ev(`!!document.querySelector('#modal a.plug[href="${ISSUES}"] .go')`), 'same card layout as the chat card');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue