using Febe.Tests.Support;
using Febe.Tests.Web.Support;
using Febe.Web.Demo;
namespace Febe.Tests.Web;
///
/// The copies to external folders in a real browser, on the demo (spec §4.10, §10.3, tappa E2): Impostazioni →
/// Esportazione with the note of Docker, the dialog of a destination (folders of /esporta, the check of the folder, the
/// types, the preview of the names), the block «Copie esterne» of an account whose switch acts at once, «Copia in…» from
/// the selection with its summary and the toast that leads to the Dashboard, the «Copie» filter in the address with the
/// marks of the tiles and the menu of the CSV icon, the rows «Copia» of the viewer with «Copia di nuovo», and the
/// Dashboard tab «Esportazione». Chromium only (CI); the selectors follow the pages of WP3, checked on the demo.
///
[TestClass]
public sealed class ExportInterfaceTests
{
/// The demo copies its general folder to «Disco USB», under /esporta in the Docker look.
private const string General = "document.querySelector('.cartella-impostazioni .val')?.textContent || ''";
/// The «Copie» button of the tools row (the one whose label is a value of the filter).
private const string CopiesButton = "[...document.querySelectorAll('.strumenti .campo.scelta')].find((b) => /^(Copie|Copiati|Non ancora copiati|Tolti o superati)$/.test(b.textContent.trim()))";
/// Clicks the button (or menu item) of a scope whose text contains a given text.
private static string ClickText(string scope, string selector, string text) =>
$"(() => {{ const b = [...document.querySelectorAll({Js(scope + " " + selector)})].find((x) => x.textContent.includes({Js(text)})); if (!b) return false; b.click(); return true; }})()";
/// The last open menu.
private const string LastMenu = "[...document.querySelectorAll('.menu[role=menu]')].pop()";
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()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("esporta-impostazioni-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
// Docker: the folders are under /esporta, and the page says so.
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione?veste=docker"));
await ui.WaitAsync($"({General}) !== ''", "la cartella generale " + ui.Report());
Assert.AreEqual("/esporta/Disco USB", (await ui.EvalAsync(General)).GetString());
var notes = (await ui.EvalAsync("[...document.querySelectorAll('.avviso')].map((a) => a.textContent).join(' | ')")).GetString()!;
StringAssert.Contains(notes, "sottocartelle di /esporta", "la nota di Docker");
StringAssert.Contains(notes, "da riprendere", "il lavoro interrotto della demo");
CollectionAssert.AreEqual(
new[] { "Esportazione", "Cartella generale", "Lo stesso post in due account", "Cartelle degli account" },
(await ui.EvalAsync("[...document.querySelectorAll('.sezione h2')].map((x) => x.textContent)")));
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.stato-copie')?.textContent || ''")).GetString(), "copiati", "i conteggi della cartella");
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.stato-copie button')].some((b) => b.textContent.includes('Controlla le copie'))")).GetBoolean(), "«Controlla le copie»");
StringAssert.Contains((await ui.EvalAsync("[...document.querySelectorAll('table tbody tr')].map((r) => r.textContent).join(' | ')")).GetString(), "@studio.lumen.demo", "la cartella sua di un account");
// Windows: the path of the folder, no note of Docker.
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione?veste=desktop"));
await ui.WaitAsync($"({General}).endsWith('Disco USB') && !({General}).startsWith('/esporta')", "la cartella generale in Windows");
Assert.IsFalse((await ui.EvalAsync("[...document.querySelectorAll('.avviso')].some((a) => a.textContent.includes('sottocartelle di'))")).GetBoolean(), "nessuna nota di Docker");
}
[TestMethod]
public async Task TheDestinationDialogChecksTheFolderAndPreviewsNames()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("esporta-dialogo-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione?veste=docker"));
await ui.WaitAsync($"({General}) !== ''", "la cartella generale");
Assert.IsTrue((await ui.EvalAsync(ClickText(".cartella-impostazioni", "button", "Modifica"))).GetBoolean());
const string Dialog = "document.querySelector('.dialogo.destinazione')";
await ui.WaitAsync($"{Dialog}?.querySelector('.sfoglia-voce') && /liberi/.test({Dialog}.querySelector('.controllo-cartella').textContent)", "il dialogo con le cartelle di /esporta e il controllo");
CollectionAssert.IsSubsetOf(
new[] { "Chiavetta", "Disco USB", "Studio Lumen" },
await ui.EvalAsync($"[...{Dialog}.querySelectorAll('.sfoglia-voce')].map((b) => b.textContent.trim())"));
Assert.AreEqual("Disco USB", (await ui.EvalAsync($"{Dialog}.querySelector('.sfoglia-voce[aria-pressed=true]').textContent.trim()")).GetString(), "la cartella di adesso è scelta");
// Another folder: the check follows it.
await ui.EvalAsync($"[...{Dialog}.querySelectorAll('.sfoglia-voce')].find((b) => b.textContent.trim() === 'Chiavetta').click()");
await ui.WaitAsync($"{Dialog}.querySelector('.controllo-cartella').textContent.includes('/esporta/Chiavetta')", "il controllo della cartella scelta");
// «Uno schema suo»: the three schemes of the library to start from, and the tree follows what is typed.
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");
// 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 }})); }})()");
// ...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())");
await ui.WaitAsync($"!{Dialog}.querySelector('.errore-testo').hidden", "«Scegli almeno un tipo.»");
Assert.IsTrue((await ui.EvalAsync($"[...{Dialog}.querySelectorAll('footer button')].find((b) => b.textContent.includes('Salva')).disabled")).GetBoolean());
// «Annulla» keeps the folder of before.
await ui.EvalAsync($"[...{Dialog}.querySelectorAll('footer button')].find((b) => b.textContent === 'Annulla').click()");
await ui.WaitAsync($"{Dialog} === null", "il dialogo si chiude");
Assert.AreEqual("/esporta/Disco USB", (await ui.EvalAsync(General)).GetString());
}
[TestMethod]
public async Task TheAccountBlockSwitchActsAtOnce()
{
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");
var id = (await ui.EvalAsync("fetch('/api/accounts').then((r) => r.json()).then((j) => j.accounts.find((a) => a.username === 'marta.demo').id)")).GetInt64();
await ui.OpenAsync(new Uri(demo.Address, $"/account/{id}/impostazioni"));
const string Block = "document.querySelector('.copie-esterne')";
await ui.WaitAsync($"{Block}?.querySelector('.conteggio-copie') != null", "il blocco «Copie esterne»");
Assert.IsTrue((await ui.EvalAsync($"{Block}.querySelector('input[role=switch]').checked")).GetBoolean(), "«Esporta questo account» acceso");
StringAssert.Contains((await ui.EvalAsync($"{Block}.textContent")).GetString(), "Nella cartella generale");
StringAssert.Contains((await ui.EvalAsync($"{Block}.querySelector('.conteggio-copie').textContent")).GetString(), "non ancora copiati");
// Off: at once, without «Salva», the server knows it and the block says what it means.
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");
// 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]
public async Task CopyInFromTheSelectionShowsTheSummaryAndStarts()
{
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.
await ui.OpenAsync(new Uri(demo.Address, "/libreria"));
await ui.WaitAsync("document.querySelector('.mosaico .tess') !== null", "il mosaico");
var marta = (await ui.EvalAsync("fetch('/api/accounts').then((r) => r.json()).then((j) => j.accounts.find((a) => a.username === 'marta.demo').id)")).GetInt64();
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());
// 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: {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()");
const string Dialog = "document.querySelector('.dialogo.copia-in')";
await ui.WaitAsync($"{Dialog}?.querySelector('.riepilogo-copia') != null", "il riepilogo");
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");
// 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(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('{items} di {items} file')", $"il lavoro di {items} file ({files} da scrivere)");
}
[TestMethod]
public async Task TheCopiesFilterIsRememberedInTheAddressAndTheTilesShowTheCopiedMark()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("esporta-filtro-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
// «Copiati» from the address: the button says it, every tile has the mark.
await ui.OpenAsync(new Uri(demo.Address, "/libreria?copie=copiati"));
await ui.WaitAsync($"({CopiesButton}) && document.querySelectorAll('.mosaico .tess').length > 0", "la Libreria con «Copiati»");
Assert.AreEqual("Copiati", (await ui.EvalAsync($"({CopiesButton}).textContent.trim()")).GetString());
Assert.IsTrue((await ui.EvalAsync($"({CopiesButton}).classList.contains('attivo')")).GetBoolean());
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.mosaico .tess')].every((t) => t.querySelector('.segno span.copia:not(.parte)') !== null)")).GetBoolean(), "il segno «copiato» su ogni tessera " + ui.Report());
Assert.AreEqual("copia", (await ui.EvalAsync("document.querySelector('.mosaico .tess .segno').lastElementChild.className")).GetString(), "il segno sta per ultimo");
// The menu of the filter: «Tolti o superati» goes to the address and stays after a reload.
await ui.EvalAsync($"({CopiesButton}).click()");
await ui.WaitAsync($"({LastMenu})?.querySelectorAll('[role=menuitemradio]').length === 4", "il menu delle copie");
CollectionAssert.AreEqual(
new[] { "Tutti", "Non ancora copiati", "Copiati", "Tolti o superati" },
await ui.EvalAsync($"[...({LastMenu}).querySelectorAll('[role=menuitemradio]')].map((b) => b.textContent.trim())"));
await ui.EvalAsync($"[...({LastMenu}).querySelectorAll('[role=menuitemradio]')].find((b) => b.textContent.trim() === 'Tolti o superati').click()");
await ui.WaitAsync("new URLSearchParams(location.search).get('copie') === 'tolti'", "«copie=tolti» nell'indirizzo");
await ui.OpenAsync(new Uri(demo.Address, "/libreria?copie=tolti"));
await ui.WaitAsync($"({CopiesButton})?.textContent.trim() === 'Tolti o superati'", "il filtro dopo il ricaricamento");
await ui.WaitAsync("document.querySelectorAll('.mosaico .tess').length > 0", "le tessere dei tolti o superati");
// The CSV icon is a menu: the list, and «Copia i file in…» of what the filter shows.
await ui.EvalAsync("document.querySelector('.strumenti button[aria-label=Esporta]').click()");
await ui.WaitAsync($"({LastMenu})?.querySelectorAll('[role=menuitem]').length === 2", "il menu dell'icona CSV");
CollectionAssert.AreEqual(
new[] { "Esporta l'elenco (CSV)", "Copia i file in…" },
await ui.EvalAsync($"[...({LastMenu}).querySelectorAll('[role=menuitem]')].map((b) => b.textContent.trim())"));
await ui.EvalAsync($"[...({LastMenu}).querySelectorAll('[role=menuitem]')].find((b) => b.textContent.includes('Copia i file')).click()");
await ui.WaitAsync("document.querySelector('.dialogo.copia-in .di-nuovo input') != null", "«Copia in…» del filtro, con «Copia di nuovo anche…»");
Assert.IsFalse((await ui.EvalAsync("document.querySelector('.dialogo.copia-in .di-nuovo input').checked")).GetBoolean(), "«Copia di nuovo» spento");
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.dialogo.copia-in .di-nuovo').textContent")).GetString(), "Copia di nuovo anche i");
await ui.EvalAsync("[...document.querySelectorAll('.dialogo.copia-in footer button')].find((b) => b.textContent === 'Annulla').click()");
await ui.WaitAsync("document.querySelector('.dialogo.copia-in') === null", "il dialogo si chiude");
// «Tutti» takes the filter out of the address.
await ui.EvalAsync($"({CopiesButton}).click()");
await ui.WaitAsync($"({LastMenu})?.querySelectorAll('[role=menuitemradio]').length === 4", "il menu delle copie");
await ui.EvalAsync($"[...({LastMenu}).querySelectorAll('[role=menuitemradio]')].find((b) => b.textContent.trim() === 'Tutti').click()");
await ui.WaitAsync("!new URLSearchParams(location.search).has('copie')", "nessun filtro nell'indirizzo");
Assert.AreEqual("Copie", (await ui.EvalAsync($"({CopiesButton}).textContent.trim()")).GetString());
}
[TestMethod]
public async Task TheViewerShowsCopyRowsWithCopyAgain()
{
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"));
await ui.WaitAsync("document.querySelector('.strumenti .modo-mosaico [data-value=files]') !== null && document.querySelector('.mosaico .tess') !== null", "la Libreria con «Tolti o superati»");
await ui.EvalAsync("document.querySelector('.strumenti .modo-mosaico [data-value=files]').click()");
await ui.WaitAsync("document.querySelector('.strumenti .modo-mosaico [aria-checked=true]').dataset.value === 'files' && document.querySelector('.mosaico .tess') !== null", "«Tutte le foto»");
// The first of those files that is on disk (the demo shares the bytes of a picture with a video that has no file,
// and which comes first depends on the hour the demo is built): «Copia in…» is offered only for a file on disk.
var target = (await ui.EvalAsync(
"(async () => { const j = await (await fetch('/api/library?mode=files&copies=removedOrSuperseded&limit=1000')).json(); "
+ "for (const tile of j.tiles) { if (!tile.cover) continue; const e = await (await fetch('/api/entries/' + tile.id)).json(); "
+ "const m = e.media.find((x) => x.id === tile.cover.mediaId); if (m && m.available) return tile.cover.mediaId; } return 0; })()")).GetInt64();
Assert.IsGreaterThan(0L, target, "a «tolto o superato» file on disk");
var tile = $"document.querySelector('.mosaico .tess[data-id=\"{target}\"]')";
await ui.WaitAsync($"{tile} !== null", "la tessera del file");
await ui.EvalAsync($"{tile}.click()");
await ui.WaitAsync("document.querySelector('.vis .riga-copia') !== null", "le righe «Copia» del visualizzatore " + ui.Report());
var row = (await ui.EvalAsync("document.querySelector('.vis .riga-copia').textContent")).GetString()!;
Assert.IsTrue(row.StartsWith("Tolto da Disco USB", StringComparison.Ordinal) || row.StartsWith("Superato in Disco USB", StringComparison.Ordinal), row);
Assert.AreEqual("Copia", (await ui.EvalAsync("document.querySelector('.vis .riga-copia').previousElementSibling.textContent")).GetString());
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.vis button')].some((b) => b.textContent.trim() === 'Copia in…')")).GetBoolean(), "«Copia in…» in fondo al pannello");
// «Copia di nuovo»: the job starts, with its toast, and the file is copied again (no longer «tolto o superato»).
const string Replaced = "fetch('/api/library?mode=files&copies=removedOrSuperseded&limit=1000').then((r) => r.json()).then((j) => j.tiles.length)";
var before = (await ui.EvalAsync(Replaced)).GetInt32();
Assert.IsGreaterThan(0, before);
await ui.EvalAsync("document.querySelector('.vis .riga-copia .copia-di-nuovo').click()");
// 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");
}
[TestMethod]
public async Task TheDashboardExportTabShowsProgressAndResume()
{
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"));
const string Notice = "[...document.querySelectorAll('.avviso')].find((a) => a.textContent.includes('da riprendere'))";
await ui.WaitAsync($"({Notice}) !== undefined", "l'avviso della copia da riprendere");
CollectionAssert.AreEqual(new[] { "Motore", "Esportazione" }, await ui.EvalAsync("[...document.querySelectorAll('.linguette-dashboard a')].map((a) => a.textContent)"));
await ui.EvalAsync($"({Notice}).querySelector('a').click()");
await ui.WaitAsync("location.pathname === '/dashboard/esportazione' && document.querySelector('.esportazione-dashboard .riga-riprendi') !== null", "la linguetta «Esportazione»");
Assert.AreEqual("Esportazione", (await ui.EvalAsync("document.querySelector('.linguette-dashboard a.qui').textContent")).GetString());
CollectionAssert.AreEqual(new[] { "In corso", "Da riprendere", "Ultimi lavori" }, await ui.EvalAsync("[...document.querySelectorAll('.esportazione-dashboard h2')].map((x) => x.textContent)"));
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.copia-in-corso').textContent")).GetString(), "Nessuna copia al lavoro");
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.riga-riprendi').textContent")).GetString(), "interrotta");
// «Resoconto» of the last job.
await ui.EvalAsync("[...document.querySelectorAll('.esportazione-dashboard .elenco-attivita li')][0].querySelector('button').click()");
await ui.WaitAsync("document.querySelector('.dialogo.resoconto-copia') !== null", "il resoconto");
StringAssert.StartsWith((await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia h2').textContent")).GetString(), "Resoconto");
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia').textContent")).GetString(), "Per account");
await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia header button').click()");
await ui.WaitAsync("document.querySelector('.dialogo.resoconto-copia') === null", "il resoconto si chiude");
// «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());
// 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());
}
}