[ and ] select the previous or next of your POPs, in the order Find a city lists them, and move the map there. - and = (also _ and +) zoom around the middle of the map. ? opens a list of every shortcut, and Help links to it on a computer. Keys are ignored while typing, with Ctrl or Cmd held, or behind an open window.
87 lines
4.8 KiB
JavaScript
87 lines
4.8 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { load } = require('./harness');
|
|
|
|
const start = "ACT.start({});S.nextFail=1e9;S.nextEvent=1e9;S.cash=1e9";
|
|
const keyer = dom => (k, t, o) => (t || dom.window.document.body).dispatchEvent(new dom.window.KeyboardEvent('keydown', { key: k, bubbles: true, ...o }));
|
|
|
|
test('[ and ] step through your POPs in name order, wrap around, and move the map there', () => {
|
|
const { ev, dom, errors } = load();
|
|
const key = keyer(dom);
|
|
ev(start + ";for(const c of ['par','lon','ams'])ACT.buildPop({city:c})");
|
|
assert.equal(ev("popOrder().join()"), 'ams,fra,lon,par', 'Amsterdam, Frankfurt, London, Paris');
|
|
const sel = () => ev('UI.sel&&UI.sel.type==="city"?UI.sel.id:null');
|
|
assert.equal(sel(), 'fra', 'the game starts on the home POP');
|
|
key(']'); assert.equal(sel(), 'lon');
|
|
assert.equal(ev('cam.x'), ev('CITY.lon.x'), 'with the map on it');
|
|
key(']'); assert.equal(sel(), 'par');
|
|
key(']'); assert.equal(sel(), 'ams', '] wraps to the first');
|
|
key('['); assert.equal(sel(), 'par', '[ wraps to the last');
|
|
key('['); assert.equal(sel(), 'lon');
|
|
// Nothing selected, or a city without a POP: ] starts at the first POP, [ at the last.
|
|
ev('UI.sel=null'); key(']'); assert.equal(sel(), 'ams');
|
|
ev('UI.sel=null'); key('['); assert.equal(sel(), 'par');
|
|
ev("selectCity('tok')"); key(']'); assert.equal(sel(), 'ams');
|
|
// The NOC dashboard steps aside so the POP can be seen.
|
|
ev("ACT.dash()"); assert.equal(ev("$('dash').hidden"), false);
|
|
key(']'); assert.equal(sel(), 'fra'); assert.equal(ev("$('dash').hidden"), true);
|
|
// Not while typing, not with Ctrl or Cmd, not behind an open window.
|
|
key(']', null, { ctrlKey: true }); key(']', null, { metaKey: true }); assert.equal(sel(), 'fra');
|
|
key(']', null, { altKey: true }); assert.equal(sel(), 'lon', 'Option or AltGr types [ ] on many layouts');
|
|
ev("ACT.rename()");
|
|
key(']', dom.window.document.getElementById('rnIn'));
|
|
key(']');
|
|
assert.equal(sel(), 'lon');
|
|
assert.equal(ev("$('modal').hidden"), false);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test('- and = zoom the map out and in around its middle, within the zoom limits', () => {
|
|
const { ev, dom, errors } = load();
|
|
const key = keyer(dom);
|
|
ev(start + ';cam.z=1');
|
|
const x = ev('cam.x'), z = () => ev('cam.z');
|
|
key('='); assert.ok(Math.abs(z() - 1.25) < 1e-9);
|
|
key('+'); assert.ok(Math.abs(z() - 1.5625) < 1e-9, '+ zooms in too');
|
|
key('-'); key('_'); assert.ok(Math.abs(z() - 1) < 1e-9, '- and _ zoom out');
|
|
assert.ok(Math.abs(ev('cam.x') - x) < 1e-6, 'the middle of the map stays put');
|
|
ev('cam.z=ZMAX'); key('='); assert.equal(z(), ev('ZMAX'));
|
|
ev('cam.z=ZMIN'); key('-'); assert.equal(z(), ev('ZMIN'));
|
|
ev("cam.z=1;ACT.rename()"); key('=', dom.window.document.getElementById('rnIn')); key('='); assert.equal(z(), 1, 'not while a window is open');
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test('? shows every keyboard shortcut and closes again; Help links to it on a computer, not on a phone', () => {
|
|
const { ev, dom, errors } = load();
|
|
const doc = dom.window.document, key = keyer(dom);
|
|
ev(start);
|
|
key('?');
|
|
assert.equal(ev("$('modal').className"), 'keys', '? opens the list');
|
|
const txt = doc.getElementById('modalCard').textContent;
|
|
for (const s of ['Keyboard shortcuts', 'Space', 'Pause or play', 'Find a city', 'Previous or next of your POPs', 'Zoom the map out or in', 'Esc', 'Show this list'])
|
|
assert.ok(txt.includes(s), s);
|
|
for (const k of ['[', ']', '-', '=', '/', '?', '0', '4']) assert.ok([...doc.querySelectorAll('#modalCard .kbd')].some(e => e.textContent === k), k);
|
|
key('?', null, { repeat: true }); assert.equal(ev("$('modal').hidden"), false, 'holding ? does not flicker it');
|
|
key('?'); assert.equal(ev("$('modal').hidden"), true, '? again closes it');
|
|
key('?'); key('Escape'); assert.equal(ev("$('modal').hidden"), true, 'so does Escape');
|
|
// Another window stays as it is, and ? in a text field is just a question mark.
|
|
ev("ACT.findOpen()"); key('?'); assert.equal(ev("$('modal').className"), 'find');
|
|
key('?', doc.getElementById('findIn')); assert.equal(ev("$('modal').className"), 'find');
|
|
ev('closeModal();ACT.help()');
|
|
const link = doc.querySelector('#modalCard [data-act="keys"]');
|
|
assert.ok(link, 'Help has a Keyboard shortcuts button');
|
|
link.click(); assert.equal(ev("$('modal').className"), 'keys');
|
|
ev("closeModal();window.innerWidth=360;ACT.help()");
|
|
assert.equal(doc.querySelector('#modalCard [data-act="keys"]'), null, 'not on a phone, which has no keys');
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test('the shortcut list in German', () => {
|
|
const { ev, dom, errors } = load({ lang: 'de' });
|
|
ev(start + ';if(ACT.pitchSkip)ACT.pitchSkip()');
|
|
keyer(dom)('?');
|
|
const txt = dom.window.document.getElementById('modalCard').textContent;
|
|
assert.match(txt, /Tastenkürzel/);
|
|
assert.match(txt, /Leertaste/);
|
|
assert.deepEqual(errors, []);
|
|
});
|