E2: prove dell'esportazione stabili su un esecutore lento
Le tre prove d'interfaccia cadute nella CI di main (esecuzione 492, verde la 490 sullo stesso albero) erano corse delle prove, non difetti del prodotto. - Anteprima dei nomi: la prova aspettava «l'albero è cambiato» e leggeva una risposta della libreria arrivata dopo la digitazione; ora aspetta il contenuto (prima l'albero della libreria in Chiavetta, poi quello dello schema scritto) e controlla che lo schema della libreria sia sparito. - Interruttore dell'account: l'avviso di 4 s compare prima che il blocco si ridisegni e spariva prima che la prova lo cercasse; un MutationObserver installato prima dell'apertura registra ogni avviso. Lo stesso per «Copia in…», «Copia di nuovo» e «Riprendi»; il collegamento dell'avviso si segue anche se l'avviso è già sparito. - «Copia in…»: la riga del lavoro conta anche i file «già copiati» e «tolti o superati» che il lavoro ricontrolla; la prova li somma al piano e controlla i già copiati nel riepilogo. Gli id della scelta si leggono con i clic. Nel dialogo della destinazione il gettone dell'anteprima avanza a ogni modifica e non quando scatta l'attesa di 150 ms: una risposta per dati superati non si disegna più, nemmeno per un attimo, e non tocca errori e «Salva». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
baeaa3dff7
commit
3e8df3245e
3 files changed
+92
-19
No files matched your search
@@ -30,6 +30,41 @@ public sealed class ExportInterfaceTests
|
||||
|
||||
private static string Js(string text) => System.Text.Json.JsonSerializer.Serialize(text);
|
||||
|
||||
/// <summary>
|
||||
/// Records every short notice shown, also one already gone again (window.__notices: kind, text and the path of its
|
||||
/// link; window.__noticeLinks: the links themselves). A notice lasts 4 s, 8 s with a link (core/ui.js), and the pages
|
||||
/// show it before they redraw or close a dialog, so a slow runner that polls the DOM after the waits before it can
|
||||
/// miss it. Installed before the first page opens: it runs in every new document.
|
||||
/// </summary>
|
||||
private static Task RecordNoticesAsync(UiBrowser ui) => ui.AddInitScriptAsync("""
|
||||
(() => {
|
||||
window.__notices = [];
|
||||
window.__noticeLinks = [];
|
||||
new MutationObserver((records) => {
|
||||
for (const record of records) {
|
||||
for (const node of record.addedNodes) {
|
||||
if (node.nodeType !== 1 || !node.matches('.brevi > *')) continue;
|
||||
const link = node.querySelector('a.breve-link');
|
||||
if (link) window.__noticeLinks.push(link);
|
||||
window.__notices.push({ kind: node.className, text: node.textContent, href: link ? new URL(link.href).pathname : null });
|
||||
}
|
||||
}
|
||||
}).observe(document, { childList: true, subtree: true });
|
||||
})();
|
||||
""");
|
||||
|
||||
/// <summary>A notice shown (see <see cref="RecordNoticesAsync"/>) that is not an error and contains a text.</summary>
|
||||
private static string Shown(string text) => $"window.__notices.some((n) => n.text.includes({Js(text)}) && !n.kind.includes('errore'))";
|
||||
|
||||
/// <summary>No error notice was shown (see <see cref="RecordNoticesAsync"/>).</summary>
|
||||
private const string NoErrorNotice = "!window.__notices.some((n) => n.kind.includes('errore'))";
|
||||
|
||||
/// <summary>
|
||||
/// Follows the link of the last notice with one: a click on it while it is on screen, else its address (the notice is
|
||||
/// already gone on a slow runner; the address is still the one the link leads to).
|
||||
/// </summary>
|
||||
private const string FollowNoticeLink = "(() => { const live = document.querySelector('.brevi .breve a.breve-link'); if (live) live.click(); else location.assign(window.__noticeLinks.at(-1).href); return true; })()";
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheExportSettingsPageShowsTheGeneralFolderAndTheDockerNote()
|
||||
{
|
||||
@@ -82,10 +117,16 @@ public sealed class ExportInterfaceTests
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('input[value=suo]').click()");
|
||||
await ui.WaitAsync($"!{Dialog}.querySelector('.schemi-copie').hidden", "gli schemi");
|
||||
Assert.IsTrue((await ui.EvalAsync($"[...{Dialog}.querySelectorAll('.schemi-copie input')].every((i) => i.value.includes('{{account}}'))")).GetBoolean(), "gli schemi partono da quelli della libreria");
|
||||
var before = (await ui.EvalAsync($"{Dialog}.querySelector('.albero').textContent")).GetString();
|
||||
// The tree is first drawn in the folder just chosen, with the names of the library... (waited for by its content:
|
||||
// a preview asked before a change can still land after the next one is asked, so «it changed» proves nothing)
|
||||
const string Tree = $"{Dialog}.querySelector('.albero').textContent";
|
||||
await ui.WaitAsync($"{Tree}.startsWith('Chiavetta') && {Tree}.includes('marta.demo / post / ')", "l'anteprima nella cartella scelta");
|
||||
await ui.EvalAsync($"(() => {{ const i = {Dialog}.querySelector('#schema-copie'); i.value = '{{account}}/{{anno}}/{{codice}}_{{n}}'; i.dispatchEvent(new Event('input', {{ bubbles: true }})); }})()");
|
||||
await ui.WaitAsync($"{Dialog}.querySelector('.albero').textContent !== {Js(before!)} && {Dialog}.querySelector('.albero').textContent.startsWith('Chiavetta')", "l'anteprima dei nomi nella cartella scelta");
|
||||
StringAssert.Contains((await ui.EvalAsync($"{Dialog}.querySelector('.albero').textContent")).GetString(), "marta.demo / 2026");
|
||||
// ...then it follows what is typed: the tree of the library never has «marta.demo / 2026».
|
||||
await ui.WaitAsync($"{Tree}.startsWith('Chiavetta') && {Tree}.includes('marta.demo / 2026')", "l'anteprima dei nomi nella cartella scelta");
|
||||
var tree = (await ui.EvalAsync(Tree)).GetString()!;
|
||||
StringAssert.Contains(tree, "marta.demo / 2026");
|
||||
Assert.IsFalse(tree.Contains("marta.demo / post / ", StringComparison.Ordinal), "lo schema scritto sostituisce quello della libreria: " + tree);
|
||||
|
||||
// No type: nothing to save.
|
||||
await ui.EvalAsync($"{Dialog}.querySelectorAll('.tipi input:checked').forEach((i) => i.click())");
|
||||
@@ -104,6 +145,7 @@ public sealed class ExportInterfaceTests
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("esporta-account-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/account"));
|
||||
await ui.WaitAsync("document.querySelector('a[href^=\"/account/\"]') !== null", "elenco degli account");
|
||||
@@ -119,13 +161,16 @@ public sealed class ExportInterfaceTests
|
||||
await ui.EvalAsync($"{Block}.querySelector('input[role=switch]').click()");
|
||||
await ui.WaitAsync($"{Block}.textContent.includes('Questo account non si esporta')", "il blocco spento");
|
||||
await ui.WaitAsync($"fetch('/api/accounts/{id}').then((r) => r.json()).then((j) => j.export.enabled === false)", "spento sul server");
|
||||
await ui.WaitAsync("[...document.querySelectorAll('.brevi .breve')].some((b) => b.textContent.includes('non si copia più'))", "l'avviso breve");
|
||||
// The notice comes before the block is drawn again, and lasts 4 s: it is looked for among those shown.
|
||||
await ui.WaitAsync(Shown("non si copia più"), "l'avviso breve");
|
||||
Assert.IsFalse((await ui.EvalAsync($"[...{Block}.querySelectorAll('button')].some((b) => b.textContent.includes('Copia in'))")).GetBoolean(), "niente «Copia in…» da spento");
|
||||
|
||||
// On again.
|
||||
await ui.EvalAsync($"{Block}.querySelector('input[role=switch]').click()");
|
||||
await ui.WaitAsync($"{Block}.querySelector('.conteggio-copie')?.textContent.includes('non ancora copiati') && {Block}.querySelector('input[role=switch]').checked", "di nuovo acceso");
|
||||
await ui.WaitAsync($"fetch('/api/accounts/{id}').then((r) => r.json()).then((j) => j.export.enabled === true)", "acceso sul server");
|
||||
await ui.WaitAsync("window.__notices.some((n) => n.text.includes('si copia nelle cartelle') && !n.text.includes('non si copia'))", "l'avviso breve di riaccensione");
|
||||
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), "nessun avviso di errore: " + (await ui.EvalAsync("JSON.stringify(window.__notices)")).GetString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -134,6 +179,7 @@ public sealed class ExportInterfaceTests
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("esporta-selezione-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
// The newest entries of marta.demo (general folder) with a file still to copy. The demo places its entries by the
|
||||
// hour it is built (decision of 26 November 2026), so how many files they have is asked of the plan, not assumed.
|
||||
@@ -143,12 +189,19 @@ public sealed class ExportInterfaceTests
|
||||
await ui.OpenAsync(new Uri(demo.Address, $"/libreria?copie=non-copiati&account={marta}"));
|
||||
await ui.WaitAsync("document.querySelectorAll('.mosaico .tess').length >= 1 && [...document.querySelectorAll('.mosaico .tess')].every((t) => t.dataset.id)", "il mosaico dei non ancora copiati");
|
||||
Assert.IsTrue((await ui.EvalAsync(ClickText(".strumenti", ".btn", "Seleziona"))).GetBoolean());
|
||||
await ui.EvalAsync("[...document.querySelectorAll('.mosaico .tess')].slice(0, 3).forEach((t) => t.click())");
|
||||
var files = (await ui.EvalAsync(
|
||||
// The ids are read with the clicks, so the plan asked below is the one of the selection even if the mosaic redraws.
|
||||
var ids = (await ui.EvalAsync("(() => { const tiles = [...document.querySelectorAll('.mosaico .tess')].slice(0, 3); const ids = tiles.map((t) => Number(t.dataset.id)); tiles.forEach((t) => t.click()); return JSON.stringify(ids); })()")).GetString()!;
|
||||
var plan = await ui.EvalAsync(
|
||||
"fetch('/api/export/plan', { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, "
|
||||
+ "body: JSON.stringify({ entryIds: [...document.querySelectorAll('.mosaico .tess')].slice(0, 3).map((t) => Number(t.dataset.id)), copyAgain: false }) })"
|
||||
+ ".then((r) => r.json()).then((j) => j.files)")).GetInt32();
|
||||
+ $"body: JSON.stringify({{ entryIds: {ids}, copyAgain: false }}) }})"
|
||||
+ ".then((r) => r.json())");
|
||||
var files = plan.GetProperty("files").GetInt32();
|
||||
var alreadyCopied = plan.GetProperty("alreadyCopied").GetInt32();
|
||||
Assert.IsGreaterThan(0, files, "«Non ancora copiati» has files to copy");
|
||||
// The job records every file of the plan that goes to a folder, «già copiati» and «tolti o superati» included (the
|
||||
// copier checks them again and the resoconto counts them), while the dialog counts only the files to write. An entry
|
||||
// of the filter can have files already copied (a carousel, or a picture the demo shares), as the demo is built.
|
||||
var items = files + alreadyCopied + plan.GetProperty("removedOrSuperseded").GetInt32();
|
||||
const string CopyIn = "[...document.querySelectorAll('.salva button')].find((b) => b.textContent.includes('Copia in'))";
|
||||
await ui.WaitAsync($"({CopyIn}) && !({CopyIn}).disabled", "«Copia in…» nella barra della scelta");
|
||||
await ui.EvalAsync($"({CopyIn}).click()");
|
||||
@@ -158,18 +211,24 @@ public sealed class ExportInterfaceTests
|
||||
var summary = (await ui.EvalAsync($"{Dialog}.querySelector('.riepilogo-copia').textContent")).GetString()!;
|
||||
StringAssert.StartsWith(summary, $"{files} file", summary);
|
||||
StringAssert.Contains(summary, "circa", "lo spazio");
|
||||
if (alreadyCopied > 0)
|
||||
{
|
||||
StringAssert.Contains(summary, alreadyCopied == 1 ? "1 già copiato" : $"{alreadyCopied} già copiati", "i già copiati nel riepilogo");
|
||||
}
|
||||
|
||||
StringAssert.Contains((await ui.EvalAsync($"{Dialog}.querySelector('.destinazioni-copia').textContent")).GetString(), "In Disco USB");
|
||||
Assert.AreEqual($"Copia {files} file", (await ui.EvalAsync($"{Dialog}.querySelector('footer .btn.primo').textContent.trim()")).GetString());
|
||||
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('footer .btn.primo').click()");
|
||||
await ui.WaitAsync($"{Dialog} === null", "il dialogo si chiude");
|
||||
await ui.WaitAsync("document.querySelector('.brevi .breve a.breve-link') !== null", "l'avviso breve con il collegamento");
|
||||
Assert.AreEqual("/dashboard/esportazione", (await ui.EvalAsync("new URL(document.querySelector('.brevi .breve a.breve-link').href).pathname")).GetString());
|
||||
// The notice with its link is shown before the dialog closes and lasts 8 s: it is looked for among those shown.
|
||||
await ui.WaitAsync("window.__notices.some((n) => n.href !== null && !n.kind.includes('errore'))", "l'avviso breve con il collegamento");
|
||||
Assert.AreEqual("/dashboard/esportazione", (await ui.EvalAsync("window.__notices.findLast((n) => n.href !== null).href")).GetString());
|
||||
|
||||
// The job is in the Dashboard tab, finished: the demo copies at once.
|
||||
await ui.EvalAsync("document.querySelector('.brevi .breve a.breve-link').click()");
|
||||
await ui.EvalAsync(FollowNoticeLink);
|
||||
await ui.WaitAsync("location.pathname === '/dashboard/esportazione' && document.querySelector('.esportazione-dashboard .elenco-attivita li') !== null", "la linguetta «Esportazione»");
|
||||
await ui.WaitAsync($"document.querySelector('.esportazione-dashboard .elenco-attivita li').textContent.includes('{files} di {files} file')", $"il lavoro di {files} file " + ui.Report());
|
||||
await ui.WaitAsync($"document.querySelector('.esportazione-dashboard .elenco-attivita li').textContent.includes('{items} di {items} file')", $"il lavoro di {items} file ({files} da scrivere)");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -226,6 +285,7 @@ public sealed class ExportInterfaceTests
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("esporta-visualizzatore-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
// «Tutte le foto» with «Tolti o superati»: every tile is a file whose copy was removed or superseded.
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/libreria?copie=tolti"));
|
||||
@@ -255,8 +315,9 @@ public sealed class ExportInterfaceTests
|
||||
var before = (await ui.EvalAsync(Replaced)).GetInt32();
|
||||
Assert.IsGreaterThan(0, before);
|
||||
await ui.EvalAsync("document.querySelector('.vis .riga-copia .copia-di-nuovo').click()");
|
||||
await ui.WaitAsync("document.querySelector('.brevi .breve a.breve-link') !== null", "l'avviso breve del lavoro");
|
||||
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.brevi .breve').textContent")).GetString(), "Copia avviata");
|
||||
// The notice lasts 8 s: it is looked for among those shown.
|
||||
await ui.WaitAsync("window.__notices.some((n) => n.href !== null && !n.kind.includes('errore'))", "l'avviso breve del lavoro");
|
||||
StringAssert.Contains((await ui.EvalAsync("window.__notices.findLast((n) => n.href !== null).text")).GetString(), "Copia avviata");
|
||||
await ui.WaitAsync($"({Replaced}).then((n) => n < {before})", "il file copiato di nuovo");
|
||||
await ui.EvalAsync("document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))");
|
||||
await ui.WaitAsync("document.querySelector('.vis') === null", "Esc chiude");
|
||||
@@ -268,6 +329,7 @@ public sealed class ExportInterfaceTests
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("esporta-dashboard-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
// The engine tab says there is a copy to resume and leads to the export tab.
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/dashboard"));
|
||||
@@ -292,7 +354,8 @@ public sealed class ExportInterfaceTests
|
||||
|
||||
// «Riprendi»: the job goes on (the demo copies at once) and leaves «Da riprendere».
|
||||
Assert.IsTrue((await ui.EvalAsync(ClickText(".riga-riprendi", "button", "Riprendi"))).GetBoolean());
|
||||
await ui.WaitAsync("[...document.querySelectorAll('.brevi .breve')].some((b) => b.textContent.includes('ripresa'))", "«Copia ripresa»");
|
||||
// The notice lasts 4 s: it is looked for among those shown.
|
||||
await ui.WaitAsync(Shown("ripresa"), "«Copia ripresa»");
|
||||
await ui.WaitAsync("document.querySelector('.esportazione-dashboard .riga-riprendi') === null", "niente più da riprendere " + ui.Report());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user