IPv4 notices in the notifications open the address space (#150)

The IPv4 toasts (CGNAT, out of IPv4, a renewal that could not grow, an
IPv6-only city done) carry an Address space button, but openOf() did not know
ip4Open, so their line in the NOC's notifications had no Open. It now maps to
a log target of its own, 'ip4', like 'ops' for opsOpen: Open runs ip4Open, the
bank scrolled to its Address space (just the bank if IPv4 is off since).
sanitize() keeps the new target. ip4Open is also on the NOC window's list of
actions it may run in the game, should a dashboard tab ever draw it.
This commit is contained in:
jvanvik 2026-11-09 22:52:06 +01:00
parent 27ffa33d7c
commit 7930d332f1
6 changed files with 40 additions and 5 deletions

View file

@ -330,6 +330,40 @@ test('the day says it once when homes go behind CGNAT, and when even CGNAT canno
assert.deepEqual(errors, []);
});
// The notices came with an Address space button, but their line in the NOC's notifications had no Open: the log did not
// know the button (openOf), so it fell back to the text, which names no POP. Open now goes where the button went.
test('an address-space notice in the notifications opens the bank at its Address space, and the NOC window may ask for it', (t) => {
const { ev, dom, errors } = game(t);
const doc = dom.window.document;
// Where the bank scrolls to: the Address space's own button scrolls it into view.
ev("S.log=[];window.__into=[];(()=>{const s=Element.prototype.scrollIntoView;Element.prototype.scrollIntoView=function(){__into.push(this.id);if(s)return s.apply(this,arguments);};})()");
homes(ev, 250);
ev('ip4Day(S.day)');
assert.match(ev('S.log[0].t'), /Your IPv4 is full/);
assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' });
ev("closeModal();ACT.leftTab({t:'noc'})");
const b = doc.querySelector(`#leftBody [data-act=logOpen][data-args='${lit({ id: ev('S.log[0].id') })}']`);
assert.ok(b, 'the notice has an Open button');
b.click();
assert.equal(doc.getElementById('bankBox').hidden, false, 'the bank is open');
assert.ok(doc.getElementById('bankIp4'));
assert.deepEqual(J(ev, '__into'), ['bankIp4'], 'at its Address space');
// A renewal that could not grow carries the same button.
biz(ev, { id: 'h1', name: 'Hoster' });
ev("ACT.bankClose();S.log=[];ip4News([[S.biz.find(b=>b.id==='h1'),20]])");
assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' });
// Kept in the save; with IPv4 off (a save from a gentler preset) it still opens the bank.
ev("S=migrate(JSON.parse(JSON.stringify(S)));");
assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' });
ev("ACT.bankClose();S.rules.ip4=false;__into.length=0;ACT.logOpen({id:S.log[0].id})");
assert.equal(ev('ip4On()'), false);
assert.equal(doc.getElementById('bankBox').hidden, false);
assert.deepEqual(J(ev, '__into'), []);
// The NOC window's clicks run in the game only from its list; the address space is on it (#150).
assert.ok(ev("NOC_GO.includes('ip4Open')&&!NOC_LOCAL.includes('ip4Open')"));
assert.deepEqual(errors, []);
});
test('rule off means no effect: gentler presets, sandbox, puzzles and scenarios unless they opt in', (t) => {
const { ev, dom, errors } = game(t);
assert.deepEqual(J(ev, "['soft','freeze','oncall','bgp','sandbox','puzzle'].map(p=>makeRules(p).ip4)"), [false, false, null, null, false, false], 'On-call and BGP keep the default (on), written nowhere');