diff --git a/docs/stato.md b/docs/stato.md
index b547af4..875887f 100644
--- a/docs/stato.md
+++ b/docs/stato.md
@@ -38,6 +38,14 @@ sono in §16 (righe 22–27) con la proposta adottata, da confermare.
pagina e ogni mancante si riguarda); «Interrompi» con più cartelle lasciava le corse seguenti «in corso» per sempre;
un alias di una sottocartella della Libreria era accettato come destinazione; una riga vecchia sul nome libero
faceva fallire la registrazione della copia. Le tre prove cadute nella CI (esecuzione 487) erano fra questi.
+- **Dopo l'unione** (ramo `correzione/prove-esportazione-instabili`): tre prove d'interfaccia di
+ `ExportInterfaceTests` cadute nella CI di `main` (esecuzione 492, verde la 490 sullo stesso albero) erano corse delle
+ prove, non difetti: l'anteprima dei nomi letta quando arrivava una risposta della libreria (si aspetta ora il suo
+ contenuto, non «è cambiata»); un avviso breve di 4 s sparito prima che la prova lo cercasse (ora un
+ `MutationObserver` installato prima registra ogni avviso, usato anche per «Riprendi» e per gli avvisi da 8 s di
+ «Copia in…» e «Copia di nuovo»); la riga del lavoro conta anche i file «già copiati» e «tolti o superati» che il lavoro
+ ricontrolla, mentre la prova si aspettava solo quelli da scrivere. Nel dialogo della destinazione un'anteprima
+ chiesta per dati poi cambiati non si disegna più nemmeno durante l'attesa di 150 ms della successiva. Da vedere nella CI.
- Documenti: SPECIFICA §4.10, §8.3, §11, §12, §16 righe 22–27, glossario; guida `Esportazione.md`; `docker.md`,
`windows.md`, `prove-dal-vivo.md` parte F; otto schermate nuove (15–21) con il confronto in
`docs/schermate/differenze.md`; righe del 27/11 in `decisioni.md`.
diff --git a/src/Febe.Web/wwwroot/js/pages/export-dialogs.js b/src/Febe.Web/wwwroot/js/pages/export-dialogs.js
index 76b1112..eb4118f 100644
--- a/src/Febe.Web/wwwroot/js/pages/export-dialogs.js
+++ b/src/Febe.Web/wwwroot/js/pages/export-dialogs.js
@@ -300,9 +300,10 @@ export async function destinationDialog({ scope, accountId = null, username = ''
drawSave();
}
+ // The token moves on at every change of the inputs, not when the debounce fires: a preview asked for inputs that
+ // have changed since is never drawn (nor sets the errors and «Salva»), also while the next one waits its 150 ms.
let previewToken = 0;
- const refresh = later(async () => {
- const mine = ++previewToken;
+ const fetchPreview = later(async (mine) => {
try {
const preview = await api('/api/export/naming-preview', {
method: 'POST',
@@ -310,9 +311,10 @@ export async function destinationDialog({ scope, accountId = null, username = ''
});
if (mine === previewToken) drawTree(preview);
} catch (error) {
- showError(error);
+ if (mine === previewToken) showError(error);
}
}, 150);
+ const refresh = () => fetchPreview(++previewToken);
// ------------------------------------------------------------------------------- save
function ready() {
@@ -376,7 +378,7 @@ export async function destinationDialog({ scope, accountId = null, username = ''
save));
if (state.path) checkFolder(state.path);
else drawCheck();
- return { body, footer, onClose: () => refresh.cancel() };
+ return { body, footer, onClose: () => { previewToken++; fetchPreview.cancel(); } };
},
});
}
diff --git a/tests/Febe.Tests/Web/ExportInterfaceTests.cs b/tests/Febe.Tests/Web/ExportInterfaceTests.cs
index c85cfb1..cd8aa56 100644
--- a/tests/Febe.Tests/Web/ExportInterfaceTests.cs
+++ b/tests/Febe.Tests/Web/ExportInterfaceTests.cs
@@ -30,6 +30,41 @@ public sealed class ExportInterfaceTests
private static string Js(string text) => System.Text.Json.JsonSerializer.Serialize(text);
+ ///
+ /// 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.
+ ///
+ 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 });
+ })();
+ """);
+
+ /// A notice shown (see ) that is not an error and contains a text.
+ private static string Shown(string text) => $"window.__notices.some((n) => n.text.includes({Js(text)}) && !n.kind.includes('errore'))";
+
+ /// No error notice was shown (see ).
+ private const string NoErrorNotice = "!window.__notices.some((n) => n.kind.includes('errore'))";
+
+ ///
+ /// 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).
+ ///
+ 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());
}
}