Files
Febe/tests/Febe.Tests/Web/ExportInterfaceTests.Automatic.cs
T
Alby96andClaude Opus 5.5 9c7f2f1ad5 E5: Dashboard e finestra della cartella dicono il vero sulle copie automatiche
«Riprendi» e «Riprendi tutte» restano attivi mentre lavora una copia
automatica, che cede il passo (risposta 49): li spegne solo un lavoro di
Alberto. «Annulla» di un lavoro automatico dice che i file ripartono da
soli; la risposta a «Interrompi» dice l'ora come il resto («all'1:20»,
«domani alle 0:30»), e «dal» si elide («dall'8 dicembre»). Nella
finestra della cartella «Salva» aspetta il conto dei tipi di adesso, un
conto non riuscito si richiede e il suo errore resta, il fuoco della
tastiera non salta; una nota dice perché «Automatica» è spenta senza
cartelle scrivibili. «Riprendi ora» torna attivo se la richiesta
fallisce. Il conto dei file che aspettano si condivide fra letture e non
si fa per la scheda di un account senza cartella sua; sul telefono i
pulsanti della tabella delle cartelle vanno a capo. Prove nuove: chiusura
che ferma prima il lavoratore, percorso troppo lungo, attesa di due
minuti dall'ultimo file e tetto di un quarto d'ora.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 20:07:48 +01:00

316 lines
27 KiB
C#

using Febe.Core.Domain;
using Febe.Tests.Support;
using Febe.Tests.Web.Support;
using Febe.Web.Demo;
namespace Febe.Tests.Web;
/// <summary>
/// Tappa E5 in a real browser, on the demo (spec §4.10 «Esportazione automatica», §10.3): «Automatica» in the dialog of a
/// folder (turned on it asks «Solo i nuovi» or «Copia anche gli N», with N what «Copia in…» would write; turned off and
/// on it asks again; with another folder it asks again; turned off while an automatic job is unfinished it says the copy
/// stops), the label «Automatica dal …» of a folder, «Riconosci le copie già presenti» from the folder with its job in the
/// Dashboard, the automatic jobs in «Ultimi lavori» and «Da riprendere», the pause of a folder with the files that wait,
/// and what «Usa la cartella generale» says while the general folder is automatic. The demo runs no automatic worker:
/// there is no status line of the automatic copies (decision of 4 December 2026). Chromium only (CI).
/// </summary>
public sealed partial class ExportInterfaceTests
{
/// <summary>The dialog of a folder.</summary>
private const string FolderDialog = "document.querySelector('.dialogo.destinazione')";
/// <summary>The switch «Automatica» of the dialog.</summary>
private const string AutoSwitch = FolderDialog + ".querySelector('.parte-automatica input[role=switch]')";
/// <summary>What the dialog says under the switch.</summary>
private const string AutoBox = FolderDialog + ".querySelector('.parte-automatica .automatica-scelta')";
/// <summary>The two answers of «Che cosa fare dei file già in libreria?».</summary>
private const string AutoChoices = AutoBox + ".querySelectorAll('input[name=automatica-esistenti]')";
/// <summary>N of «Copia anche i N già in libreria» (the Italian thousands separator taken away).</summary>
private const string AlsoCount = "Number(" + AutoBox + ".querySelector('input[value=all]').closest('label').textContent.match(/Copia anche i ([\\d.]+) già in libreria/)[1].replace(/\\./g, ''))";
/// <summary>The line of the general folder under its path (types, names, «Automatica dal …»).</summary>
private const string GeneralDescription = "document.querySelector('.cartella-impostazioni .descrizione-copie')?.textContent || ''";
/// <summary>The general folder as the API gives it.</summary>
private static readonly string GeneralFolder = Get("/api/export") + ".then((j) => j.general)";
/// <summary>
/// The files «Copia in…» would write in the general folder, account by account (the planner, not the count of the
/// dialog): what «Copia anche gli N» must count when the folder keeps its copies.
/// </summary>
private static readonly string PlannedInGeneral = "(async () => { const g = (" + GeneralFolder + ").then((x) => x.id); const id = await g; "
+ "const accounts = (await " + Get("/api/accounts") + ").accounts; let n = 0; "
+ "for (const a of accounts) { const p = await fetch('/api/export/plan', { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ accountId: a.id, copyAgain: false }) }).then((r) => r.json()); "
+ "for (const d of p.destinations || []) if (d.id === id) n += d.files; } return n; })()";
[TestMethod]
public async Task TheFolderDialogAsksOnlyNewWhenAutomaticIsTurnedOnAndAgainAfterOff()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("automatica-dialogo-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, "/impostazioni/esportazione"));
await ui.WaitAsync($"({General}) !== '' && ({GeneralDescription}) !== ''", "la cartella generale");
Assert.IsFalse((await ui.EvalAsync(GeneralDescription)).GetString()!.Contains("Automatica", StringComparison.Ordinal), "«Disco USB» is not automatic in the demo");
var planned = (await ui.EvalAsync(PlannedInGeneral)).GetInt32();
Assert.IsGreaterThan(0, planned, "the demo has files not copied in «Disco USB»");
// On: the question, «Solo i nuovi» first; «Copia anche gli N» counts what «Copia in…» would write, with the space.
await OpenGeneralDialogAsync(ui);
Assert.IsFalse((await ui.EvalAsync($"{AutoSwitch}.checked")).GetBoolean());
Assert.AreEqual(0, (await ui.EvalAsync($"{AutoChoices}.length")).GetInt32(), "off: no question");
await ui.EvalAsync($"{AutoSwitch}.click()");
await ui.WaitAsync($"{AutoChoices}.length === 2", "la domanda «Solo i nuovi» " + ui.Report());
Assert.AreEqual("Che cosa fare dei file già in libreria?", (await ui.EvalAsync($"{AutoBox}.querySelector('.domanda-automatica').textContent")).GetString());
Assert.AreEqual("new", (await ui.EvalAsync($"[...{AutoChoices}].find((i) => i.checked).value")).GetString(), "«Solo i nuovi» is the proposal");
StringAssert.StartsWith((await ui.EvalAsync($"{AutoBox}.querySelector('input[value=new]').closest('label').textContent")).GetString(), "Solo i nuovi");
Assert.AreEqual(planned, (await ui.EvalAsync(AlsoCount)).GetInt32(), "N is what «Copia in…» would write in the folder");
StringAssert.Contains((await ui.EvalAsync($"{AutoBox}.querySelector('input[value=all]').closest('label').textContent")).GetString(), "Circa ");
// «Solo i nuovi», saved: the folder is automatic from now on, and says since when.
await SaveFolderDialogAsync(ui);
await ui.WaitAsync(Shown("Automatica accesa: da adesso si copiano da soli i file nuovi."), "l'avviso dell'accensione");
await ui.WaitAsync($"{GeneralFolder}.then((g) => g.automatic === true && g.automaticSince !== null)", "automatica sul server, con l'istante");
await ui.WaitAsync($"({GeneralDescription}).includes('· Automatica dal')", "«Automatica dal …» sotto la cartella");
// Opened again: on, the same folder: it says since when and asks nothing.
await OpenGeneralDialogAsync(ui);
Assert.IsTrue((await ui.EvalAsync($"{AutoSwitch}.checked")).GetBoolean());
await ui.WaitAsync($"{AutoBox}.textContent.includes('Automatica dal') && {AutoBox}.textContent.includes('copia i file salvati in libreria da allora')", "«Automatica dal …» nel dialogo");
Assert.AreEqual(0, (await ui.EvalAsync($"{AutoChoices}.length")).GetInt32(), "no question while it stays on");
// Off: no automatic job of this folder is unfinished, so no note; saved, it forgets the answer.
await ui.EvalAsync($"{AutoSwitch}.click()");
await ui.WaitAsync($"{AutoBox}.textContent === ''", "spenta: niente da dire");
Assert.IsTrue((await ui.EvalAsync($"{FolderDialog}.querySelector('.spegnere') === null")).GetBoolean());
await SaveFolderDialogAsync(ui);
await ui.WaitAsync($"{GeneralFolder}.then((g) => g.automatic === false && g.automaticSince === null)", "spenta sul server");
await ui.WaitAsync($"!({GeneralDescription}).includes('Automatica')", "nessuna «Automatica» sotto la cartella");
// On again: the question comes back; «Copia anche gli N» stores no instant.
await OpenGeneralDialogAsync(ui);
await ui.EvalAsync($"{AutoSwitch}.click()");
await ui.WaitAsync($"{AutoChoices}.length === 2", "la domanda di nuovo");
Assert.AreEqual(planned, (await ui.EvalAsync(AlsoCount)).GetInt32());
await ui.EvalAsync($"{AutoBox}.querySelector('input[value=all]').click()");
await SaveFolderDialogAsync(ui);
await ui.WaitAsync("window.__notices.some((n) => /^Automatica accesa: [\\d.]+ file da copiare; la copia parte fra poco, mai durante una sessione del motore\\.$/.test(n.text))", "l'avviso con il numero dei file");
Assert.AreEqual(planned, (await ui.EvalAsync("Number(window.__notices.findLast((n) => /^Automatica accesa: [\\d.]+ file/.test(n.text)).text.match(/([\\d.]+) file/)[1].replace(/\\./g, ''))")).GetInt32());
await ui.WaitAsync($"{GeneralFolder}.then((g) => g.automatic === true && g.automaticSince === null)", "tutti i file dovuti, nessun istante");
await ui.WaitAsync($"({GeneralDescription}).endsWith('· Automatica')", "«Automatica» sotto la cartella");
await OpenGeneralDialogAsync(ui);
await ui.WaitAsync($"{AutoBox}.textContent.includes('Automatica: copia tutti i file dovuti.')", "«copia tutti i file dovuti»");
await CancelFolderDialogAsync(ui);
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), "nessun avviso di errore: " + (await ui.EvalAsync("JSON.stringify(window.__notices)")).GetString());
}
[TestMethod]
public async Task TheAutomaticFolderOfAnAccountSaysSinceWhenWhatStopsAndWhatGoesToTheGeneralFolder()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("automatica-account-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
await RecordNoticesAsync(ui);
var studio = (await demo.Storage.Accounts.ListAsync()).Single(a => a.Username == DemoExport.OwnFolderAccount);
var own = (await demo.Storage.Exports.ListDestinationsAsync(includeRetired: false)).Single(d => d.Scope == ExportScope.Account);
Assert.IsTrue(own.Automatic, "the demo's own folder is automatic");
// The card (Docker look: the dialog browses the folders of /esporta): the label «Automatica dal …» next to the kind
// of folder, and what can be done with the folder.
await ui.OpenAsync(new Uri(demo.Address, $"/account/{studio.Id}/impostazioni?veste=docker"));
const string Block = "document.querySelector('.copie-esterne')";
await ui.WaitAsync($"{Block}?.querySelector('.riga-etichetta .et.accento') != null", "l'etichetta «Automatica» " + ui.Report());
StringAssert.StartsWith((await ui.EvalAsync($"{Block}.querySelector('.riga-etichetta .et.accento').textContent")).GetString(), "Automatica dal");
StringAssert.Contains((await ui.EvalAsync($"{Block}.querySelector('.riga-etichetta').textContent")).GetString(), "Nella sua cartella");
var buttons = await ui.EvalAsync<string[]>($"[...{Block}.querySelectorAll('.stato-copie button')].map((b) => b.textContent.trim())");
CollectionAssert.AreEqual(new[] { "Controlla le copie", "Riconosci le copie già presenti" }, buttons);
// The dialog: on since a day; turned off, the automatic job left unfinished stops, and it says so before saving.
Assert.IsTrue((await ui.EvalAsync(ClickText(".copie-esterne .cartella", "button", "Modifica"))).GetBoolean());
await ui.WaitAsync($"{AutoSwitch} != null && {AutoBox}.textContent.includes('Automatica dal')", "il dialogo con «Automatica dal …»");
Assert.IsTrue((await ui.EvalAsync($"{AutoSwitch}.checked")).GetBoolean());
await ui.EvalAsync($"{AutoSwitch}.click()");
await ui.WaitAsync($"{FolderDialog}.querySelector('.spegnere') != null", "la nota «Spegnendo…» " + ui.Report());
Assert.AreEqual(
"Spegnendo, la copia automatica di questa cartella si ferma e i file che restavano non si copiano da soli; quelli già copiati restano.",
(await ui.EvalAsync($"{FolderDialog}.querySelector('.spegnere').textContent.trim()")).GetString());
// On again with the same folder: nothing to ask. Another folder is a new destination: the question comes back,
// and counts the files the new folder would have (none copied there yet).
await ui.EvalAsync($"{AutoSwitch}.click()");
await ui.WaitAsync($"{AutoBox}.textContent.includes('Automatica dal') && {FolderDialog}.querySelector('.spegnere') === null", "di nuovo accesa");
Assert.AreEqual(0, (await ui.EvalAsync($"{AutoChoices}.length")).GetInt32());
await ui.WaitAsync($"{FolderDialog}.querySelector('.sfoglia-voce') != null", "le cartelle");
await ui.EvalAsync($"[...{FolderDialog}.querySelectorAll('.sfoglia-voce')].find((b) => b.textContent.trim() === 'Chiavetta').click()");
await ui.WaitAsync($"{AutoChoices}.length === 2", "la domanda per la cartella nuova " + ui.Report());
var elsewhere = await PreviewInDockerAsync(ui, own.Id, studio.Id, string.Empty);
Assert.AreEqual(elsewhere, (await ui.EvalAsync(AlsoCount)).GetInt32(), "the count of a folder with no copies");
var stillThere = await PreviewInDockerAsync(ui, own.Id, studio.Id, DemoExport.OwnFolder);
Assert.IsGreaterThan(stillThere, elsewhere, "the copies made in «Studio Lumen» do not count in another folder");
await CancelFolderDialogAsync(ui);
var kept = await demo.Storage.Exports.GetDestinationAsync(own.Id);
Assert.AreEqual((true, own.AutomaticSince, own.RootPath), (kept!.Automatic, kept.AutomaticSince, kept.RootPath), "«Annulla» changes nothing");
// The general folder automatic: «Usa la cartella generale» says how many files of the account will go there.
var put = await ui.EvalAsync(
"(async () => { const g = await " + GeneralFolder + "; const r = await fetch('/api/export/destinations/' + g.id, { method: 'PUT', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, "
+ "body: JSON.stringify({ scope: 'general', accountId: null, path: g.rootPath, label: null, types: g.types, namingScheme: g.namingScheme, highlightNamingScheme: g.highlightNamingScheme, "
+ "profileNamingScheme: g.profileNamingScheme, automatic: true, onlyNew: false, photoFormat: g.photoFormat || 'general', videoFormat: g.videoFormat || 'general' }) }); return r.status; })()");
Assert.AreEqual(200, put.GetInt32(), "the general folder turned automatic");
var goes = (await ui.EvalAsync(Post("/api/export/automatic-preview", $"{{ \"mode\": \"removeOwn\", \"accountId\": {studio.Id} }}"))).GetProperty("files").GetInt32();
Assert.IsGreaterThan(0, goes);
await ui.OpenAsync(new Uri(demo.Address, $"/account/{studio.Id}/impostazioni?veste=docker"));
await ui.WaitAsync($"{Block}?.querySelector('.riga-etichetta .et.accento') != null", "la scheda di nuovo");
Assert.IsTrue((await ui.EvalAsync(ClickText(".copie-esterne .cartella", "button", "Usa la cartella generale"))).GetBoolean());
await ui.WaitAsync("document.querySelector('.dialogo .togli-automatica') != null", "la conferma con i file che andranno da soli " + ui.Report());
var said = (await ui.EvalAsync("document.querySelector('.dialogo .togli-automatica').textContent.trim()")).GetString()!;
StringAssert.EndsWith(said, $"file di @{DemoExport.OwnFolderAccount} andranno da soli nella cartella generale.", said);
Assert.AreEqual(goes, int.Parse(said.Split(' ')[0].Replace(".", string.Empty, StringComparison.Ordinal), System.Globalization.CultureInfo.InvariantCulture), said);
await ui.EvalAsync("[...document.querySelectorAll('.dialogo footer button')].find((b) => b.textContent.trim() === 'Annulla').click()");
await ui.WaitAsync("document.querySelector('.dialogo .togli-automatica') === null", "la conferma si chiude");
Assert.IsFalse((await demo.Storage.Exports.GetDestinationAsync(own.Id))!.IsRetired, "«Annulla» keeps the own folder");
}
[TestMethod]
public async Task TheDashboardMarksAutomaticJobsAndRecognizeStartsFromTheFolder()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("automatica-dashboard-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
await RecordNoticesAsync(ui);
var stopped = (await demo.Storage.Exports.ListUnfinishedRunsAsync()).Single(r => r.Origin == ExportRunOrigin.Automatic);
var stoppedTotal = (await demo.Storage.Exports.GetRunSummaryAsync(stopped.Id)).Total;
// The engine tab counts only Alberto's job to resume: the automatic one resumes by itself.
await ui.OpenAsync(new Uri(demo.Address, "/dashboard"));
await ui.WaitAsync("[...document.querySelectorAll('.avviso')].some((a) => a.textContent.includes('da riprendere'))", "l'avviso della copia da riprendere");
StringAssert.Contains((await ui.EvalAsync("[...document.querySelectorAll('.avviso')].find((a) => a.textContent.includes('da riprendere')).textContent")).GetString(), "1 copia da riprendere.");
// «Da riprendere»: both jobs, the automatic one with its label; no status line of the automatic copies (no worker).
await ui.OpenAsync(new Uri(demo.Address, "/dashboard/esportazione"));
await ui.WaitAsync("document.querySelectorAll('.esportazione-dashboard .riga-riprendi').length === 2 && document.querySelector('.esportazione-dashboard .elenco-attivita li') !== null", "«Da riprendere» " + ui.Report());
const string AutomaticRow = "[...document.querySelectorAll('.riga-riprendi')].find((r) => r.querySelector('.et.accento'))";
StringAssert.Contains((await ui.EvalAsync($"({AutomaticRow}).textContent")).GetString(), $"Automatica Copia in Studio Lumen interrotta: 0 di {stoppedTotal} file fatti.");
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.riga-riprendi')].some((r) => !r.querySelector('.et') && r.textContent.includes('Copia in Disco USB interrotta'))")).GetBoolean(), "Alberto's job, without a label");
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.esportazione-dashboard h2')].some((x) => x.textContent === 'Da riprendere') && [...document.querySelectorAll('button')].some((b) => b.textContent.includes('Riprendi tutte'))")).GetBoolean());
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.copia-in-corso').textContent")).GetString(), "Nessuna copia al lavoro");
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.stato-automatiche') === null && !document.body.textContent.includes('giro di recupero')")).GetBoolean(), "the demo shows no automatic status");
// «Ultimi lavori»: the automatic job with its label, the recognition with its name and its resoconto.
const string Rows = "[...document.querySelectorAll('.esportazione-dashboard .elenco-attivita li')]";
Assert.IsTrue((await ui.EvalAsync($"{Rows}.some((li) => li.querySelector('b').textContent.startsWith('Copia automatica in Studio Lumen') && li.querySelector('b .et.accento')?.textContent === 'Automatica')")).GetBoolean(), "the automatic job in «Ultimi lavori»");
const string Recognized = $"{Rows}.find((li) => li.querySelector('b').textContent === 'Riconoscimento delle copie in Studio Lumen')";
await ui.EvalAsync($"({Recognized}).querySelector('button').click()");
await ui.WaitAsync("document.querySelector('.dialogo.resoconto-copia .riepilogo-copia') !== null", "il resoconto del riconoscimento");
Assert.AreEqual("Resoconto: Riconoscimento delle copie in Studio Lumen", (await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia h2').textContent")).GetString());
var summary = (await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia .riepilogo-copia').textContent")).GetString()!;
StringAssert.Contains(summary, "1 già presente, riconosciuto", summary);
StringAssert.Contains(summary, "non trovati", summary);
StringAssert.Contains(summary, "1 diverso", summary);
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia .problemi-copia').textContent")).GetString(), "Nel percorso c'è un altro file", "the different file is a problem to look at");
await ui.EvalAsync("document.querySelector('.dialogo.resoconto-copia header button').click()");
await ui.WaitAsync("document.querySelector('.dialogo.resoconto-copia') === null", "il resoconto si chiude");
// «Riconosci le copie già presenti» from the folder's row of Impostazioni: a job of its own, which writes nothing.
var folder = Path.Combine(demo.Root, "esporta");
var before = Tree(folder);
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione"));
await ui.WaitAsync("document.querySelector('.cartelle-copie tbody tr button') !== null", "la riga della cartella di @studio.lumen.demo");
Assert.IsTrue((await ui.EvalAsync(ClickText(".cartelle-copie tbody tr", "button", "Riconosci le copie già presenti"))).GetBoolean());
await ui.WaitAsync(Shown("Riconoscimento avviato"), "l'avviso del riconoscimento " + ui.Report());
StringAssert.Contains((await ui.EvalAsync("window.__notices.findLast((n) => n.text.includes('Riconoscimento avviato')).text")).GetString(), "Nessun file viene toccato.");
await ui.EvalAsync(FollowNoticeLink);
await ui.WaitAsync("location.pathname === '/dashboard/esportazione'", "la Dashboard");
await ui.WaitAsync(
$"{Get("/api/export/runs?limit=1")}.then((r) => r[0].kind === 'recognize' && r[0].id > {stopped.Id} && r[0].state === 'completed')",
"il nuovo riconoscimento finito");
await ui.WaitAsync($"{Rows}[0]?.querySelector('b').textContent === 'Riconoscimento delle copie in Studio Lumen'", "il riconoscimento in cima agli ultimi lavori");
CollectionAssert.AreEqual(before, Tree(folder), "«Riconosci» writes, renames and deletes nothing");
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), "nessun avviso di errore: " + (await ui.EvalAsync("JSON.stringify(window.__notices)")).GetString());
}
[TestMethod]
public async Task APausedFolderSaysSinceWhenAndHowManyFilesWait()
{
await using var ui = await UiBrowser.StartAsync(1440, 900);
using var temp = new TempFolder("automatica-pausa-ui");
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
await RecordNoticesAsync(ui);
var general = (await demo.Storage.Exports.GetGeneralDestinationAsync())!;
// The stick goes away; «Riprova» (from the API) finds the folder gone and the folder goes in pause.
var away = general.RootPath + " staccato";
Directory.Move(general.RootPath, away);
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione"));
await ui.WaitAsync($"({General}) !== ''", "la cartella generale");
await ui.EvalAsync($"fetch('/api/export/destinations/{general.Id}/resume', {{ method: 'POST', headers: {{ Accept: 'application/json' }} }}).then((r) => r.status)");
await ui.WaitAsync($"{GeneralFolder}.then((g) => g.pausedAt !== null)", "la cartella in pausa sul server");
var waiting = (await ui.EvalAsync($"{GeneralFolder}.then((g) => g.waiting)")).GetInt32();
Assert.IsGreaterThan(0, waiting, "the job left interrupted waits for the folder");
// Impostazioni: since when and why, how many files wait, «Riprova»; no rounds to announce in the demo.
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione"));
await ui.WaitAsync("document.querySelector('.cartella-impostazioni .pausa-copie') !== null", "la pausa della cartella " + ui.Report());
var pause = (await ui.EvalAsync("document.querySelector('.cartella-impostazioni .pausa-copie').textContent")).GetString()!;
StringAssert.StartsWith(pause, "In pausa da oggi: ", pause);
StringAssert.Contains(pause, waiting == 1 ? "1 file aspetta questa cartella." : $"{waiting} file aspettano questa cartella.", pause);
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.cartella-impostazioni .pausa-copie button')].some((b) => b.textContent.includes('Riprova'))")).GetBoolean(), "«Riprova»");
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.pausa-giro') === null")).GetBoolean(), "no automatic worker in the demo: no rounds to announce");
StringAssert.Contains((await ui.EvalAsync("document.querySelector('.cartella-impostazioni .stato-copie').textContent")).GetString(), "copiati", "the counts stay in pause");
// The engine tab: the folder in pause, since files wait for it.
await ui.OpenAsync(new Uri(demo.Address, "/dashboard"));
await ui.WaitAsync("[...document.querySelectorAll('.avviso')].some((a) => a.textContent.includes('Disco USB è in pausa'))", "l'avviso della cartella in pausa");
// The stick comes back: «Riprova» takes the pause away.
Directory.Move(away, general.RootPath);
await ui.OpenAsync(new Uri(demo.Address, "/impostazioni/esportazione"));
await ui.WaitAsync("document.querySelector('.cartella-impostazioni .pausa-copie button') !== null", "«Riprova»");
Assert.IsTrue((await ui.EvalAsync(ClickText(".cartella-impostazioni .pausa-copie", "button", "Riprova"))).GetBoolean());
await ui.WaitAsync($"{GeneralFolder}.then((g) => g.pausedAt === null)", "la pausa tolta sul server");
await ui.WaitAsync("document.querySelector('.cartella-impostazioni .pausa-copie') === null", "la pausa tolta nella pagina");
}
/// <summary>«Copia anche gli N» of the own folder of an account turned on with a folder of /esporta («» for another one).</summary>
private static async Task<int> PreviewInDockerAsync(UiBrowser ui, long destinationId, long accountId, string path)
{
var body = System.Text.Json.JsonSerializer.Serialize(new { mode = "switchOn", destinationId, scope = "account", accountId, path, types = new[] { "postFoto", "postVideo" } });
var answer = await ui.EvalAsync(
"fetch('/api/export/automatic-preview', { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-Febe-Veste': 'docker' }, "
+ $"body: {Js(body)} }}).then((r) => r.json())");
return answer.GetProperty("files").GetInt32();
}
private static async Task OpenGeneralDialogAsync(UiBrowser ui)
{
Assert.IsTrue((await ui.EvalAsync(ClickText(".cartella-impostazioni", "button", "Modifica"))).GetBoolean(), "«Modifica…»");
await ui.WaitAsync($"{AutoSwitch} != null && /liberi/.test({FolderDialog}.querySelector('.controllo-cartella').textContent)", "il dialogo con «Automatica» e il controllo della cartella");
}
private static async Task SaveFolderDialogAsync(UiBrowser ui)
{
const string Save = FolderDialog + ".querySelector('footer .btn.primo')";
await ui.WaitAsync($"!{Save}.disabled", "«Salva» attivo");
await ui.EvalAsync($"{Save}.click()");
await ui.WaitAsync($"{FolderDialog} === null", "il dialogo si chiude dopo il salvataggio");
}
private static async Task CancelFolderDialogAsync(UiBrowser ui)
{
await ui.EvalAsync($"[...{FolderDialog}.querySelectorAll('footer button')].find((b) => b.textContent === 'Annulla').click()");
await ui.WaitAsync($"{FolderDialog} === null", "il dialogo si chiude");
}
/// <summary>Every file under a folder: relative path, length and time of the last write.</summary>
private static string[] Tree(string folder) =>
[.. Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories)
.Select(f => new FileInfo(f))
.Select(f => $"{Path.GetRelativePath(folder, f.FullName)}|{f.Length}|{f.LastWriteTimeUtc.Ticks}")
.Order(StringComparer.Ordinal)];
}