Merge main

# Conflicts:
#	CHANGELOG.md
#	site/i18n/fr.js
#	site/i18n/it.js
#	site/i18n/pt.js
#	site/index.html
This commit is contained in:
Frederic Jung 2026-10-26 23:34:24 +01:00
commit e7fcb041be
No known key found for this signature in database
6 changed files with 155 additions and 21 deletions

View file

@ -405,3 +405,63 @@ test('#117 several scrubbing centers: nearest first, spill to the next, and far
assert.equal(ev("S.scrubs.some(x=>x.city==='lon')"), false);
assert.deepEqual(errors, []);
});
test('notifications: the NOC keeps the last ten minutes, folds repeats and opens what each is about', () => {
const { ev, errors, dom } = load();
const doc = dom.window.document;
ev("let __t=1e12;Date.now=()=>__t;window.__tick=ms=>{__t+=ms};");
ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;for(const c of ['ams','lon'])ACT.buildPop({city:c});UI.via=null;openLinkModal('ams','lon');ACT.buildLink({tier:1});closeModal();S.log=[];UI.logSeen=0");
const linkId = ev("S.links.find(l=>[l.a,l.b].includes('ams')&&[l.a,l.b].includes('lon')).id");
// what each notice is about: its own button, a link between two of your cities, one of your cities, or nothing
ev("toast('<b>Customer upset</b><br>Fix it.','bad',[{l:'Show me',act:'focusCity',args:{city:'fra'}}])");
ev("toast('<b>Fiber cut</b><br>Your Amsterdam–London link is down.','bad')");
ev("toast('<b>Router crashed</b><br>Your router in London is rebooting.','bad')");
ev("toast('<b>Raffle</b><br>You won a T-shirt.','good')");
const os = JSON.parse(ev("JSON.stringify(S.log.map(e=>e.o))"));
assert.deepEqual(os, [null, { a: 'city', v: 'lon' }, { a: 'link', v: linkId }, { a: 'city', v: 'fra' }]);
assert.equal(ev("S.log[0].h"), 'Raffle'); assert.equal(ev("S.log[0].t"), 'Raffle You won a T-shirt.');
// the peering inbox's own button opens the peering inbox
ev("toast('<b>Peering request</b><br>From a small network.','',[{l:'Inbox',act:'inbox',args:{}}])");
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.log[0].o)')), { a: 'inbox' });
ev('ACT.logOpen({id:S.log[0].id})'); assert.equal(ev("$('modal').hidden"), false, 'the inbox opens');ev('closeModal();S.log.shift()');
// an incident points at what broke
assert.deepEqual(JSON.parse(ev(`JSON.stringify(incOpen({ref:'${linkId}'}))`)), { a: 'link', v: linkId });
assert.deepEqual(JSON.parse(ev("JSON.stringify(incOpen({ref:S.links[0].trench||S.links[0].id}))")), { a: 'link', v: ev('S.links[0].id') });
// repeats within a minute fold into one line with a count; numbers in the title do not split them
ev("for(let i=1;i<=5;i++)toast('<b>'+i+' new sessions at HAMS-IX.</b><br>Small networks.','')");
assert.equal(ev("S.log.length"), 5); assert.equal(ev("S.log[0].n"), 5); assert.equal(ev("S.log[0].h"), '5 new sessions at HAMS-IX.');
ev("__tick(61000);toast('<b>1 new session at HAMS-IX.</b><br>Small networks.','')");
assert.equal(ev("S.log.length"), 6, 'a minute later it starts a new line');
// the NOC shows them right after the incidents, with Open where there is something to open
assert.equal(ev("logUnread()"), 6);
ev("renderHUD()"); assert.equal(doc.getElementById('hNocNew').hidden, false); assert.equal(doc.getElementById('hNocNew').textContent, '6');
ev("UI.left='noc';UI.leftOpen=true;UI.sel=null;renderLeft();renderHUD()");
const body = doc.getElementById('leftBody').textContent;
assert.match(body, /Notifications\s*last 10 minutes/);
assert.ok(body.indexOf('Notifications') < body.indexOf('DDoS scrubbing'), 'near the top, not at the bottom');
assert.match(body, /×5/); assert.match(body, /just now/);
assert.equal(doc.querySelectorAll('#leftBody [data-act=logOpen]').length, 2, 'Open only where it leads somewhere (2 of the 5 shown)');
assert.equal(doc.getElementById('hNocNew').hidden, true, 'read once the NOC is open');
assert.equal(ev("logUnread()"), 0);
ev("ACT.logAll()"); assert.equal(doc.querySelectorAll('#leftBody .note').length, 6); assert.equal(doc.querySelectorAll('#leftBody [data-act=logOpen]').length, 3);
// Open goes there
ev("ACT.logOpen({id:S.log.find(e=>e.o&&e.o.a==='link').id})"); assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'link:' + linkId);
ev("ACT.logOpen({id:S.log.find(e=>e.o&&e.o.a==='city'&&e.o.v==='lon').id})"); assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:lon');
ev(`S.links=S.links.filter(l=>l.id!=='${linkId}');ACT.logOpen({id:S.log.find(e=>e.o&&e.o.a==='link').id})`);
assert.equal(ev("S.log[0].h"), 'That link is gone.', 'a removed link says so instead of failing silently');
// ten minutes later it is gone from the list, but stays in the save's log
ev("__tick(10*60*1000+1000);UI.left='noc';renderLeft()");
assert.match(doc.getElementById('leftBody').textContent, /Nothing in the last 10 minutes/);
assert.ok(ev("S.log.length") > 0);
// saves: junk is dropped, old entries without a time stay but are not shown
ev("S.log.push({t:'old',k:'weird',o:{a:'city',v:'atlantis'},n:'many'},{t:5},{t:'x',o:{a:'tab',v:'evil'}},{t:'y',o:{a:'link',v:'l1'},at:'soon'});S=sanitize(S)");
const tail = JSON.parse(ev("JSON.stringify(S.log.slice(-3))"));
assert.deepEqual(tail.map(e => [e.t, e.k, e.o, e.n, e.at]), [['old', '', null, 1, 0], ['x', '', null, 1, 0], ['y', '', { a: 'link', v: 'l1' }, 1, 0]]);
// phones: the NOC tab carries the count
ev("__tick(1000);toast('<b>Router crashed</b><br>Your router in London is rebooting.','bad');UI.left='goals';UI.leftOpen=false");
dom.window.innerWidth = 360; ev("renderAll&&renderAll()");
const nocTab = [...doc.querySelectorAll('#tabbar [data-act=phoneTab]')].find(b => JSON.parse(b.dataset.args).t === 'noc');
assert.equal(nocTab.querySelector('.cnt').textContent, '1', 'one unread notification on the NOC tab');
assert.equal(nocTab.querySelector('.cnt').classList.contains('red'), false, 'not red: red is for incidents');
assert.deepEqual(errors, []);
});