using Febe.Tests.Support; using Febe.Tests.Web.Support; using Febe.Web.Demo; namespace Febe.Tests.Web; /// /// «Raggruppa i post» / «Tutte le foto» in a real browser, on the demo (spec §4.6, tappa D1): the switch of the tools /// row, the file tiles with their place («2/4»), the day rows in files, the viewer that opens on the file and counts /// files, the selection of files that acts on their entries, the choice remembered per page (Libreria apart from the /// account views) and grouped when the browser keeps nothing. Chromium only (CI). /// [TestClass] public sealed class LibraryModeInterfaceTests { private const string Switch = "document.querySelector('.strumenti .modo-mosaico')"; private const string Mode = Switch + ".querySelector('[aria-checked=true]').dataset.value"; [TestMethod] public async Task TutteLeFotoShowsTheFilesOpensTheViewerOnTheFileAndIsRememberedPerPage() { await using var ui = await UiBrowser.StartAsync(1440, 900); using var temp = new TempFolder("modo-ui"); await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path)); await ui.OpenAsync(new Uri(demo.Address, "/libreria")); await ui.WaitAsync($"{Switch} !== null && document.querySelector('.mosaico .tess') !== null", "Libreria con l'interruttore"); Assert.AreEqual("grouped", (await ui.EvalAsync(Mode)).GetString(), "predefinito «Raggruppa i post» " + ui.Report()); Assert.AreEqual(2, (await ui.EvalAsync($"{Switch}.querySelectorAll('[role=radio]').length")).GetInt32()); var entries = (await ui.EvalAsync("document.querySelector('.quanti')?.textContent || ''")).GetString(); StringAssert.Contains(entries, "elementi"); // «Tutte le foto»: tiles of single files, those of a series with their place. await ui.EvalAsync($"{Switch}.querySelector('[data-value=files]').click()"); await ui.WaitAsync("[...document.querySelectorAll('.mosaico .tess .segno span')].some((s) => /^\\d+\\/\\d+$/.test(s.textContent))", "tessere con «2/4»"); StringAssert.Contains((await ui.EvalAsync("document.querySelector('.mosaico .giorno span')?.textContent || ''")).GetString(), "file", "la riga del giorno conta i file"); await ui.WaitAsync("/ file in .* elementi di /.test(document.querySelector('.quanti')?.textContent || '')", "«61.034 file in 48.212 elementi di 38 account»"); // The viewer opens on the second file of a series and counts files. const string Second = "[...document.querySelectorAll('.mosaico .tess')].find((t) => /^2\\/\\d+$/.test(t.querySelector('.segno span')?.textContent || ''))"; await ui.WaitAsync($"({Second}) !== undefined", "un secondo file di una serie"); await ui.EvalAsync($"({Second}).click()"); await ui.WaitAsync("document.querySelector('.vis .serie button[aria-current=true]') !== null", "visualizzatore con la serie"); Assert.AreEqual(1, (await ui.EvalAsync("[...document.querySelectorAll('.vis .serie button')].findIndex((b) => b.getAttribute('aria-current') === 'true')")).GetInt32(), "aperto sul file della tessera"); StringAssert.Contains((await ui.EvalAsync("document.querySelector('.vis .dove').textContent")).GetString(), "file", "«Libreria, file 12 di …»"); var where = (await ui.EvalAsync("document.querySelector('.vis .dove').textContent")).GetString(); await ui.EvalAsync("document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }))"); await ui.WaitAsync($"document.querySelector('.vis .dove').textContent !== {System.Text.Json.JsonSerializer.Serialize(where)}", "la freccia va al file seguente"); await ui.EvalAsync("document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))"); await ui.WaitAsync("document.querySelector('.vis') === null", "Esc chiude"); // Selection of files: two files of one post are one entry for «Elimina». await ui.EvalAsync("[...document.querySelectorAll('.strumenti .btn')].find((b) => b.textContent.includes('Seleziona')).click()"); await ui.EvalAsync($"(() => {{ const t = {Second}; const entry = t.dataset.entry; const all = [...document.querySelectorAll(`.mosaico .tess[data-entry='${{entry}}']`)]; all.slice(0, 2).forEach((x) => x.click()); return all.length; }})()"); await ui.WaitAsync("/2 file scelti, di 1 elemento/.test(document.querySelector('.salva .nota')?.textContent || '')", "«2 file scelti, di 1 elemento»"); StringAssert.Contains((await ui.EvalAsync("document.querySelector('.salva .btn.pericolo').textContent")).GetString(), "Elimina 1 elemento"); // Remembered for the Libreria, not for the account views. await ui.OpenAsync(new Uri(demo.Address, "/libreria")); await ui.WaitAsync($"{Switch} !== null", "Libreria di nuovo"); Assert.AreEqual("files", (await ui.EvalAsync(Mode)).GetString(), "la Libreria ricorda «Tutte le foto»"); await ui.OpenAsync(new Uri(demo.Address, "/account")); await ui.WaitAsync("document.querySelector('a[href^=\"/account/\"]') !== null", "elenco degli account"); await ui.EvalAsync("document.querySelector('a[href^=\"/account/\"]').click()"); await ui.WaitAsync($"location.pathname.startsWith('/account/') && {Switch} !== null", "scheda account con l'interruttore"); Assert.AreEqual("grouped", (await ui.EvalAsync(Mode)).GetString(), "le viste degli account hanno la loro scelta"); } [TestMethod] public async Task WithoutTheBrowserStorageTheMosaicIsGrouped() { await using var ui = await UiBrowser.StartAsync(1440, 900); using var temp = new TempFolder("modo-senza-memoria"); await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path)); await ui.AddInitScriptAsync("Object.defineProperty(window, 'localStorage', { configurable: true, get() { throw new DOMException('bloccato', 'SecurityError'); } });"); await ui.OpenAsync(new Uri(demo.Address, "/libreria")); await ui.WaitAsync($"{Switch} !== null && document.querySelector('.mosaico .tess') !== null", "Libreria senza memoria del browser"); Assert.AreEqual("grouped", (await ui.EvalAsync(Mode)).GetString(), ui.Report()); // The choice still works for the page that is open. await ui.EvalAsync($"{Switch}.querySelector('[data-value=files]').click()"); await ui.WaitAsync("[...document.querySelectorAll('.mosaico .tess .segno span')].some((s) => /^\\d+\\/\\d+$/.test(s.textContent))", "«Tutte le foto» anche senza memoria"); await ui.OpenAsync(new Uri(demo.Address, "/libreria")); await ui.WaitAsync($"{Switch} !== null", "Libreria riaperta"); Assert.AreEqual("grouped", (await ui.EvalAsync(Mode)).GetString(), "nulla da ricordare: di nuovo «Raggruppa i post»"); } }