Prove dell'interfaccia: ridisegni rimandati e trascinamento senza pause

AfterInEvidenzaTheOtherTabsStayTheirs aspettava 500 e 600 ms perché un
ridisegno rimasto di «In evidenza» (150 ms dopo un cambio di dimensione)
avesse il tempo di coprire i post. Ora aspetta i timer della pagina che
erano in sospeso al cambio di filtro (PageTimers) e, dopo il cambio di
dimensione, un ResizeObserver della prova, chiamato dopo quelli della
pagina, e i timer che quelli hanno lasciato.

TheWindowBarHandleFollowsTheWholeDrag lasciava 60 ms fra un passo e
l'altro del trascinamento: su una macchina lenta più passi possono
arrivare come un solo movimento, e la prova non provava più che la
maniglia segua tutto il trascinamento. Ora ogni passo aspetta il suo
orario nel campo prima del successivo.

TheAccountHeaderFollowsEveryMenuAction aveva 200 ms fra un'azione e
l'altra che non proteggevano nulla: ogni giro aspetta già l'intestazione
ridisegnata.

Con copie dell'interfaccia rotte apposta (ridisegno non annullato,
osservatore non staccato, tessere tardive disegnate, trascinamento che
finisce al primo passo) le prove falliscono in ogni giro provato, anche
con Chrome rallentato 20 volte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-21 10:45:17 +02:00
1 parent 7a9c235552
commit 7513f41d4d
2 files changed
+75 -8

No files matched your search

+74 -8
View File
@@ -50,6 +50,33 @@ public sealed class InterfaceTests
})();
""";
/// <summary>
/// Installed before the page scripts: <c>window.__timers()</c> lists the timeouts of the page still pending and
/// <c>window.__timersOver(ids)</c> says whether those have all run or been cleared. A test waits for the timers that
/// were pending at a given moment (a debounced redraw, say) to be over, instead of a pause that may be too short.
/// </summary>
private const string PageTimers = """
(() => {
const set = window.setTimeout.bind(window);
const clear = window.clearTimeout.bind(window);
const pending = new Set();
window.setTimeout = (fn, ms, ...rest) => {
const id = set((...args) => {
pending.delete(id);
fn(...args);
}, ms, ...rest);
pending.add(id);
return id;
};
window.clearTimeout = (id) => {
pending.delete(id);
clear(id);
};
window.__timers = () => [...pending];
window.__timersOver = (ids) => ids.every((id) => !pending.has(id));
})();
""";
// ------------------------------------------------------------------------------------------ the driving lease
[TestMethod]
@@ -325,15 +352,47 @@ public sealed class InterfaceTests
await using var ui = await UiBrowser.StartAsync();
await ui.AddInitScriptAsync(UiBrowser.Requests);
await ui.AddInitScriptAsync(PageTimers);
await ui.OpenAsync(new Uri(server.Address, $"/account/{account.Id}?tipo=evidenza"));
await ui.WaitAsync("document.querySelector('main .raccolta-titolo') !== null", "raccolte in evidenza");
// «Post» after «In evidenza»: the posts stay, also when the area changes size.
await ui.EvalAsync("document.querySelectorAll('.strumenti .filtri button')[0].click()");
// «Post» after «In evidenza»: the posts stay, also once what «In evidenza» left pending has run (it redraws
// itself 150 ms after a change of size, and it has just been drawn).
await ui.EvalAsync("""
(() => {
window.__pendingAtSwitch = window.__timers();
document.querySelectorAll('.strumenti .filtri button')[0].click();
return true;
})()
""");
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno') !== null", "mosaico dei post");
await Task.Delay(500);
await ui.WaitAsync("window.__timersOver(window.__pendingAtSwitch)", "attese di «In evidenza» finite");
await AssertPostsShownAsync(ui);
// The area changes size. The page's own observers see it before this one, which came last: what they left
// pending then (a redraw, a frame) runs, and the posts are still there.
await ui.EvalAsync("""
(() => {
let before = null;
window.__afterResize = null;
new ResizeObserver((entries, observer) => {
const width = entries[0].contentRect.width;
if (before === null) {
before = width;
return;
}
if (Math.abs(width - before) < 1) return;
observer.disconnect();
const pending = window.__timers();
requestAnimationFrame(() => { window.__afterResize = pending; });
}).observe(document.querySelector('main .corpo > div'));
window.__resizeWatched = () => before !== null;
return true;
})()
""");
await ui.WaitAsync("window.__resizeWatched()", "dimensione dei contenuti osservata");
await ui.SendAsync("Emulation.setDeviceMetricsOverride", new JsonObject { ["width"] = 1100, ["height"] = 900, ["deviceScaleFactor"] = 1, ["mobile"] = false });
await Task.Delay(600);
await ui.WaitAsync("window.__afterResize !== null && window.__timersOver(window.__afterResize)", "contenuti ridisegnati alla nuova larghezza");
await AssertPostsShownAsync(ui);
// «In evidenza» and at once «Post», while the tiles of the collections are still loading: they come after the
@@ -464,7 +523,6 @@ public sealed class InterfaceTests
})()
""",
$"intestazione aggiornata dopo «{choice}»");
await Task.Delay(200);
}
}
@@ -547,19 +605,27 @@ public sealed class InterfaceTests
var handle = await ui.EvalAsync("(() => { const r = document.querySelector('.fascia-barra .maniglia').getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; })()");
var (handleX, handleY) = (handle[0].GetDouble(), handle[1].GetDouble());
var left = barX - (barWidth / 2);
string TimeAt(double at)
{
var minutes = (int)(Math.Round((at - left) / barWidth * 1440 / 15) * 15);
return $"{minutes / 60:00}:{minutes % 60:00}";
}
await ui.MouseAsync("mouseMoved", handleX, handleY);
await ui.MouseAsync("mousePressed", handleX, handleY, buttons: 1);
var x = handleX;
foreach (var ratio in new[] { 0.30, 0.34, 0.38, 0.42, 0.46 })
{
// Each step is followed before the next one moves: a handle drawn again would lose the drag after the
// first step, and steps sent together may reach the page as one move.
x = left + (barWidth * ratio);
await ui.MouseAsync("mouseMoved", x, barY, buttons: 1);
await Task.Delay(60);
var step = TimeAt(x);
await ui.WaitAsync($"document.querySelector('#fascia-inizio').value === '{step}'", $"inizio della fascia a {step} durante il trascinamento");
}
await ui.MouseAsync("mouseReleased", x, barY);
var minutes = (int)(Math.Round((x - left) / barWidth * 1440 / 15) * 15);
var expected = $"{minutes / 60:00}:{minutes % 60:00}";
var expected = TimeAt(x);
await ui.WaitAsync($"document.querySelector('#fascia-inizio').value === '{expected}'", $"inizio della fascia a {expected}");
}