seriesoftubes/tests/noc-panel-layout.test.js
Frederic Jung 9d74873edb
NOC tab and Pie Control tidied for phones: Pie Control in the NOC top row, traceroute in Routing & DDoS, government money in the bank
- NOC tab: Pie Control is a button in the top row next to "Open NOC dashboard" (only once the rocket
  company is unlocked) and replaces the Pie in the Sky card; a spat waiting for an answer keeps its card.
  The Connections button is gone (it lives in the NOC dashboard), and the traceroute moved into the
  Routing & DDoS modal as an entry that opens the unchanged traceroute modal.
- Government money (Rural Digital Pie Fund, Pitcairn grant, Ex-Im Pie Bank) is a section of the bank,
  shown with a rocket company or anything of the fund's to show. pieGovOpen, the action the toasts use,
  opens the bank there; pieTab({t:'gov'}) does too.
- Pie Control has four tabs (Traffic, Company, Launch, Dishes) in one segmented control that fits 360 px,
  styled like the HUD's speed buttons. The Founder's posts and the orbit books moved into the Company tab,
  newest three posts shown and the rest folded. A stale UI.pieTab of 'gov', 'book' or 'founder' falls back.
- Agent docs for pieGovOpen, pieTab, routingOpen and connOpen; the route fuzzer drops connOpen from the
  NOC tab on both pages to stay in lockstep with main.
- Tests: tests/noc-panel-layout.test.js, and the pie tests follow the moves.
2026-11-06 09:58:00 +01:00

101 lines
5.8 KiB
JavaScript

// The NOC tab's top row (Pie Control next to the NOC dashboard), the traceroute inside Routing & DDoS, government money
// in the bank, and Pie Control's four tabs as one segmented control. Seeded; state is set directly.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const sandbox = "ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.nextFail=1e9;S.nextEvent=1e9";
const noc = "UI.started=true;UI.left='noc';UI.leftOpen=true;UI.sel=null;renderLeft()";
const acts = (root) => [...root.querySelectorAll('[data-act]')].map((b) => b.dataset.act);
test('the NOC tab: Pie Control in the top row once unlocked, no Connections or Traceroute buttons', () => {
const { dom, ev, errors } = load();
const doc = dom.window.document;
ev("window.innerWidth=360;ACT.start({});if(UI.pendGame)ACT.pitchSkip();ACT.launchBB({city:'fra'});" + noc);
const top = () => acts(doc.querySelector('#leftBody .btns'));
assert.deepEqual(top(), ['dash', 'routingOpen'], 'no rocket company yet: no Pie Control');
assert.ok(!acts(doc.getElementById('leftBody')).includes('connOpen'), 'Connections lives in the NOC dashboard');
assert.ok(!acts(doc.getElementById('leftBody')).includes('trace'), 'the traceroute moved into Routing & DDoS');
ev(sandbox + ';ACT.pieFound();' + noc);
assert.deepEqual(top(), ['dash', 'pieOpen', 'routingOpen'], 'Pie Control sits next to the NOC dashboard');
assert.equal(doc.querySelectorAll('#leftBody [data-act=pieOpen]').length, 1, 'and the old card is gone');
assert.equal(doc.querySelector('#leftBody .pie-card'), null);
doc.querySelector('#leftBody .btns [data-act=pieOpen]').click();
assert.equal(ev("$('modal').className"), 'pie');
ev('closeModal()');
assert.deepEqual(errors, []);
});
test('Routing & DDoS opens the traceroute', () => {
const { dom, ev, errors } = load();
const doc = dom.window.document;
ev("window.innerWidth=360;ACT.start({});if(UI.pendGame)ACT.pitchSkip();ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});ACT.routingOpen()");
const b = doc.querySelector('#modalCard [data-act=trace]');
assert.ok(b, 'a traceroute entry in the modal');
assert.match(doc.querySelector('#modalCard .rt-trace').textContent, /Traceroute/);
b.click();
assert.equal(doc.querySelector('#modalCard [data-routing]'), null, 'the traceroute modal took over');
assert.ok(doc.getElementById('trFrom'), 'with its source picker');
ev('closeModal()');
assert.deepEqual(errors, []);
});
test('the bank shows Government money only with a rocket company, and pieGovOpen opens it there', () => {
const { dom, ev, errors } = load();
const doc = dom.window.document;
ev(sandbox + ";window.innerWidth=360;ACT.bank()");
assert.equal(doc.getElementById('bankGov'), null, 'nothing to show before the company');
ev('ACT.bankClose();ACT.pieFound();ACT.pieOpen();ACT.pieGovOpen()');
assert.equal(ev("$('modal').hidden"), true, 'Pie Control steps aside');
assert.equal(ev("$('bankBox').hidden"), false);
const card = doc.getElementById('bankCard');
assert.ok(doc.getElementById('bankGov'));
for (const re of [/Government money/, /Rural Digital Pie Fund/, /Pitcairn/, /Ex-Im Pie Bank/]) assert.match(card.textContent, re);
ev('ACT.bankClose()');
assert.deepEqual(errors, []);
});
test('Pie Control: four tabs in one segmented control; old Gov and Founder tabs fall back', () => {
const { dom, ev, errors } = load();
const doc = dom.window.document;
ev(sandbox + ";window.innerWidth=360;ACT.pieFound();UI.pieTab=null;ACT.pieOpen()");
const seg = doc.querySelector('#modalCard .segc.pie-tabs');
assert.ok(seg, 'one segmented control');
assert.deepEqual([...seg.querySelectorAll('button')].map((b) => JSON.parse(b.dataset.args).t), ['traffic', 'co', 'fly', 'dish']);
assert.equal(seg.querySelectorAll('button.on').length, 1);
assert.equal(seg.querySelector('button.on').getAttribute('aria-pressed'), 'true');
assert.deepEqual(JSON.parse(ev('JSON.stringify(PIE_TABS)')), ['traffic', 'co', 'fly', 'dish']);
// A tab name left over from before: Founder lands on Company, Gov on traffic (or the bank, when asked for by name).
ev("UI.pieTab='founder';ACT.pieOpen()");
assert.equal(ev('UI.pieTab'), 'co');
ev("UI.pieTab='book';ACT.pieOpen()");
assert.equal(ev('UI.pieTab'), 'co');
ev("UI.pieTab='gov';ACT.pieOpen()");
assert.equal(ev('UI.pieTab'), 'traffic');
ev("UI.pieTab='nonsense';ACT.pieOpen()");
assert.equal(ev('UI.pieTab'), 'traffic');
ev("ACT.pieTab({t:'gov'})");
assert.equal(ev("$('bankBox').hidden"), false, 'the old Gov tab name opens the bank');
ev("ACT.bankClose();ACT.pieTab({t:'book'})");
assert.equal(ev('UI.pieTab'), 'co');
ev('closeModal()'); // an open globe keeps its animation loop, and this process, alive
assert.deepEqual(errors, []);
});
test('the Company tab ends with the Founder\'s posts, the newest three and the rest folded', () => {
const { dom, ev, errors } = load();
const doc = dom.window.document;
ev(sandbox + ";window.innerWidth=360;ACT.pieFound();for(let i=0;i<5;i++)pieFounder(N_('pie.fp_rename'));ACT.pieTab({t:'co'})");
const feed = doc.querySelector('#modalCard .pie-feed');
assert.ok(feed, 'the feed is on the Company tab');
assert.equal(feed, [...doc.querySelectorAll('#modalCard > *')].pop(), 'at the bottom');
assert.match(feed.textContent, /The Founder posts/);
assert.match(feed.textContent, /Promises/);
const n = ev('S.pie.founder.posts.length');
assert.equal(feed.querySelectorAll(':scope > .ops-rep').length, 3);
assert.equal(feed.querySelectorAll('details .ops-rep').length, n - 3);
assert.match(feed.querySelector('summary').textContent, new RegExp(`${n - 3} older posts`));
assert.match(doc.getElementById('modalCard').textContent, /Spent so far/, 'the books moved here too');
ev('closeModal()');
assert.deepEqual(errors, []);
});