Prove dell'interfaccia: Attività lasciata mentre carica non ascolta più la libreria e non mostra avvisi

Il controllo «nothing of Attività drawn over the Libreria», aggiunto con
la correzione dell'issue #8, guardava solo main: render() mette in main
la cornice della pagina nuova prima ancora di caricare il modulo, e
Attività disegna solo nei nodi della propria cornice, già staccata. Una
copia rotta apposta lo fa fallire solo scrivendo direttamente in main;
con l'ascolto della libreria rimasto, o con l'errore delle richieste
annullate mostrato come avviso sulla Libreria, la prova passava. Il
messaggio del commit 248e9f7 diceva quindi più di quanto la prova
provasse (rilievo R3 della revisione).

Ora, dopo la risposta in ritardo, la prova controlla ciò che una pagina
lasciata mentre carica può davvero lasciare: il timer di un minuto (come
prima), gli avvisi (registrati da un MutationObserver, anche quelli già
spariti) e l'ascolto della libreria. Per l'ascolto manda alla pagina un
evento «libreria» sul suo EventSource, come farebbe il flusso degli
eventi, aspetta che la Libreria richieda i suoi giorni e controlla che
Attività non abbia chiesto altro. Il controllo su main resta, con il
messaggio di ciò che prova. Una modifica pubblicata sul server non
darebbe lo stesso ordine: il flusso si iscrive in un Task.Run senza dire
quando, e raccoglie le modifiche per 300 ms.

Sulla pagina rimasta aperta la stessa modifica deve ricaricare Attività:
così la prova mostra anche che l'evento arriva davvero a chi ascolta.

Con copie rotte apposta, a velocità normale (2 giri) e con Chrome
rallentato 20 volte (1 giro): timer rimasto, ascolto rimasto, avviso
mostrato e nodo scritto in main trovati ogni volta, ciascuno dal suo
controllo; una copia senza ricarica alla modifica la trova il controllo
della pagina aperta; la copia intatta passa 2 volte su 2 e 3 su 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-21 12:43:03 +02:00
1 parent 4b35178880
commit 44f7f93783
2 files changed
+40 -2

No files matched your search

+39 -2
View File
@@ -570,6 +570,29 @@ public sealed class InterfaceTests
window.setInterval = (fn, ms, ...rest) => { const id = set(fn, ms, ...rest); live.set(id, ms); return id; };
window.clearInterval = (id) => { live.delete(id); clear(id); };
window.__intervals = (ms) => [...live.values()].filter((v) => v === ms).length;
// Every short notice shown, also one already gone again.
window.__notices = [];
new MutationObserver((records) => {
for (const record of records) {
for (const node of record.addedNodes) {
if (node.nodeType === 1 && node.matches('.brevi > *')) window.__notices.push(node.textContent);
}
}
}).observe(document, { childList: true, subtree: true });
// A change of the library as the event stream brings it: every page that listens is called before this
// returns (the number of streams).
const NativeSource = window.EventSource;
const streams = [];
window.EventSource = class extends NativeSource {
constructor(...args) {
super(...args);
streams.push(this);
}
};
window.__libraryChanged = () => {
for (const stream of streams) stream.dispatchEvent(new MessageEvent('libreria', { data: '{}' }));
return streams.length;
};
})();
""");
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
@@ -584,11 +607,25 @@ public sealed class InterfaceTests
await ui.EvalAsync("window.__release('/api/alerts')");
await ui.WaitAsync("window.__done['/api/alerts'] >= 1", "risposta in ritardo arrivata");
Assert.AreEqual(0, (await ui.EvalAsync("window.__intervals(60000)")).GetInt32(), "the minute timer of Attività is gone with its page");
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .attivita') === null && document.querySelector('main .benvenuto') !== null")).GetBoolean(), "nothing of Attività drawn over the Libreria " + ui.Report());
// The page that stays open still works as usual.
// Nothing of it is shown over the Libreria: what it draws went with its frame, so only a short notice, or a
// node put straight into the page area, could show.
var notices = await ui.EvalAsync<string[]>("window.__notices");
Assert.IsEmpty(notices, "no notice of Attività over the Libreria: " + string.Join(" | ", notices));
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .attivita') === null && document.querySelector('main .benvenuto') !== null")).GetBoolean(), "nothing of Attività in the page area " + ui.Report());
// Nor does it still listen to the library: a change reaches the Libreria, which asks for its days again, and
// Attività asks for nothing more than when it was opened.
var days = (await ui.AskedAsync("GET /api/library/days")).Length;
Assert.AreEqual(1, (await ui.EvalAsync("window.__libraryChanged()")).GetInt32(), "the event stream of the interface");
await ui.WaitAsync($"window.__asked.filter((r) => r.includes('GET /api/library/days')).length > {days}", "Libreria aggiornata dopo la modifica");
CollectionAssert.AreEqual(new[] { "GET /api/alerts" }, await ui.AskedAsync("/api/alerts"), "Attività, left, no longer listens to the library");
// The page that stays open still works as usual: its minute timer runs, and a change of the library reloads it.
await ui.NavigateAsync("/attivita");
await ui.WaitAsync("window.__intervals(60000) === 1", "Attività aperta");
await ui.EvalAsync("window.__libraryChanged()");
await ui.WaitAsync("window.__asked.filter((r) => r.includes('/api/alerts')).length >= 3", "Attività aggiornata dopo la modifica");
await ui.NavigateAsync("/libreria");
await ui.WaitAsync("window.__intervals(60000) === 0", "Attività lasciata");
}