Libreria: lo stato vuoto segue il collegamento anche quando il motore risponde dopo
La Libreria vuota sceglieva una volta sola, alla risposta di /api/library/days, fra il benvenuto del primo avvio (§10.3: Febe non collegato, i due pulsanti) e «La libreria è ancora vuota», guardando lo stato del motore in quel momento. Se /api/engine (o il primo evento del flusso) arrivava dopo, lo stato era ancora sconosciuto: il primo avvio mostrava la libreria vuota e ci restava, anche dopo che il motore aveva detto «non collegato». Provato con Chrome trattenendo la risposta del motore. È un difetto a sé, trovato mentre si cercava la causa dell'issue #5, e non è fra le cause di quel fallimento: nella prova del pulsante Indietro lo stato del motore è già noto quando la Libreria si ridisegna, e quella prova passa anche senza questa correzione. Ora lo stato vuoto senza filtri segue il motore finché è sullo schermo: diventa il benvenuto quando si sa che Febe non è collegato e torna «La libreria è ancora vuota» quando si collega. Si ridisegna solo quando cambia tipo, così il fuoco su un pulsante del benvenuto non si perde a ogni evento. Il benvenuto è lo stesso di prima: confrontato con docs/schermate/primo-avvio.png. Nuova prova TheEmptyLibraryFollowsTheConnectionAlsoWhenTheEngineAnswersLate: trattiene /api/engine fino a un segnale e toglie EventSource; sul codice di prima fallisce. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fbb9e602b9
commit
3719adc2d9
3 files changed
+69
-7
No files matched your search
@@ -20,7 +20,8 @@ namespace Febe.Tests.Web;
|
||||
/// The interface itself in a real (headless) Chromium against a test server: what only shows when the scripts run.
|
||||
/// The «driving» lease of the Browser and Collegamento pages (spec §4.1, §10.3: the engine is still only while Alberto
|
||||
/// uses the browser), the remote view's keyboard and mouse, the mosaic and the account card when filters change,
|
||||
/// the unsaved-changes guard on the browser's Back button, the window bar of Limiti, the sidebar status box.
|
||||
/// the empty library that follows the connection, the unsaved-changes guard on the browser's Back button, the window
|
||||
/// bar of Limiti, the sidebar status box.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
[DoNotParallelize]
|
||||
@@ -30,6 +31,25 @@ public sealed class InterfaceTests
|
||||
|
||||
private static readonly ConnectionStatus Verification = new(ConnectionState.VerificationRequired, "tuo.profilo", "Il tuo profilo", false, "https://www.instagram.com/challenge/");
|
||||
|
||||
/// <summary>
|
||||
/// Installed before the page scripts: the answer of <c>/api/engine</c> waits until <c>window.__releaseEngine()</c>,
|
||||
/// and without the event stream (the interface then asks <c>/api/engine</c>) nothing brings the engine sooner.
|
||||
/// </summary>
|
||||
private const string HoldEngine = """
|
||||
(() => {
|
||||
const original = window.fetch.bind(window);
|
||||
let release;
|
||||
const gate = new Promise((resolve) => { release = resolve; });
|
||||
window.__releaseEngine = () => { release(); return true; };
|
||||
window.fetch = async (input, init) => {
|
||||
const url = typeof input === 'string' ? input : input.url;
|
||||
if (url.includes('/api/engine')) await gate;
|
||||
return original(input, init);
|
||||
};
|
||||
delete window.EventSource;
|
||||
})();
|
||||
""";
|
||||
|
||||
// ------------------------------------------------------------------------------------------ the driving lease
|
||||
|
||||
[TestMethod]
|
||||
@@ -362,6 +382,29 @@ public sealed class InterfaceTests
|
||||
await ui.WaitAsync("document.querySelector('main .mosaico .tess') !== null", "tessere disegnate");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheEmptyLibraryFollowsTheConnectionAlsoWhenTheEngineAnswersLate()
|
||||
{
|
||||
await using var server = await WebTestServer.StartAsync();
|
||||
await using var ui = await UiBrowser.StartAsync();
|
||||
await ui.AddInitScriptAsync(HoldEngine);
|
||||
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
||||
|
||||
// The library answered first: nothing says yet whether Febe is connected.
|
||||
await ui.WaitAsync("document.querySelector('main .vuoto-pagina') !== null", "libreria vuota prima del motore");
|
||||
Assert.IsTrue((await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.engineState() === null)")).GetBoolean(), "the engine has not answered yet");
|
||||
|
||||
// Not connected (no own account): the first start with its two ways to begin (spec §10.3).
|
||||
await ui.EvalAsync("window.__releaseEngine()");
|
||||
await ui.WaitAsync("document.querySelector('main .benvenuto') !== null && document.querySelector('main .vuoto-pagina') === null", "primo avvio dopo la risposta del motore");
|
||||
|
||||
// Connected now (the own account is known): the welcome gives way to the empty library.
|
||||
await server.Db.Accounts.AddAsync(Make.Account("tuo.profilo", mine: true));
|
||||
await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.refreshEngine()).then(() => true)");
|
||||
await ui.WaitAsync("document.querySelector('main .benvenuto') === null && document.querySelector('main .vuoto-pagina h2') !== null", "libreria vuota da collegato");
|
||||
Assert.AreEqual("La libreria è ancora vuota", (await ui.EvalAsync("document.querySelector('main .vuoto-pagina h2').textContent")).GetString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheAccountHeaderFollowsEveryMenuAction()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user