using Febe.Tests.Support; using Febe.Tests.Web.Support; using Febe.Web.Demo; namespace Febe.Tests.Web; /// /// The Dashboard in a real browser, on the demo (spec §7.9, §10.3, tappa D1): the first item of the sidebar with its own /// icon, the preview of the browser always visible at the top, the thumbnails of the history and the enlarged preview /// they open (arrows, Esc, «Apri l'account», «Apri nella Libreria»), and one column below 1000 px. Chromium only (CI). /// [TestClass] public sealed class DashboardInterfaceTests { [TestMethod] public async Task TheHistoryThumbnailsOpenALightPreviewThatTheArrowsWalkAndEscCloses() { await using var ui = await UiBrowser.StartAsync(1440, 900); using var temp = new TempFolder("dashboard-ui"); await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path)); await ui.OpenAsync(new Uri(demo.Address, "/?scena=sessione")); await ui.WaitAsync("location.pathname === '/dashboard' && document.querySelector('main .dashboard .cruscotto .anteprima img:not([hidden])') !== null", "Dashboard con l'anteprima del browser"); Assert.AreEqual("#i-layout-dashboard", (await ui.EvalAsync("document.querySelector('.nav a[data-nav=dashboard] use').getAttribute('href')")).GetString(), "la sua icona"); Assert.AreEqual("dashboard", (await ui.EvalAsync("document.querySelector('.nav a').dataset.nav")).GetString(), "prima voce"); Assert.IsTrue((await ui.EvalAsync("(() => { const p = document.querySelector('.cruscotto .anteprima').getBoundingClientRect(); return p.top < 200 && p.bottom <= innerHeight; })()")).GetBoolean(), "l'anteprima sta in alto, intera, senza scorrere " + ui.Report()); // The thumbnails of a line come when it is in view; a click opens the light dialog, not the full viewer. await ui.EvalAsync("document.querySelector('.storia').scrollIntoView()"); // A line with two thumbnails at least, so that the arrows have somewhere to go. const string Line = "[...document.querySelectorAll('.storia .miniature')].find((m) => m.querySelectorAll('.miniatura').length >= 2)"; await ui.WaitAsync($"({Line}) !== undefined", "miniature della cronologia"); await ui.EvalAsync($"({Line}).querySelector('.miniatura').click()"); await ui.WaitAsync("document.querySelector('.dialogo.anteprima-cronologia .anteprima-palco img, .dialogo.anteprima-cronologia .anteprima-palco video, .dialogo.anteprima-cronologia .anteprima-neutra') !== null", "anteprima ingrandita"); Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis') === null")).GetBoolean(), "non il visualizzatore a tutta finestra"); var first = (await ui.EvalAsync("document.querySelector('.anteprima-cronologia footer .dati').textContent")).GetString(); var dida = (await ui.EvalAsync("document.querySelector('.anteprima-cronologia .anteprima-dida').textContent")).GetString(); StringAssert.StartsWith(dida, "@"); StringAssert.StartsWith((await ui.EvalAsync("new URL(document.querySelector('.anteprima-cronologia footer a.btn').href).pathname")).GetString(), "/account/", "«Apri l'account»"); // The arrows walk the files of the line also with the focus on a button of the footer. await ui.EvalAsync("document.querySelector('.anteprima-cronologia footer button.primo').focus()"); await ui.EvalAsync("document.activeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }))"); await ui.WaitAsync($"document.querySelector('.anteprima-cronologia .anteprima-dida').textContent !== {System.Text.Json.JsonSerializer.Serialize(dida)} || document.querySelector('.anteprima-cronologia footer .dati').textContent !== {System.Text.Json.JsonSerializer.Serialize(first)}", "la freccia passa al file seguente"); await ui.EvalAsync("document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))"); await ui.WaitAsync("document.querySelector('.anteprima-cronologia') === null", "Esc chiude"); Assert.AreEqual("/dashboard", (await ui.EvalAsync("location.pathname")).GetString(), "senza lasciare la pagina"); } [TestMethod] public async Task BelowAThousandPixelsTheDashboardIsOneColumnWithThePreviewOnTop() { await using var ui = await UiBrowser.StartAsync(860, 900); using var temp = new TempFolder("dashboard-stretta"); await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path)); await ui.OpenAsync(new Uri(demo.Address, "/dashboard?scena=sessione&tema=scuro")); await ui.WaitAsync("document.querySelector('main .dashboard .cruscotto .anteprima') !== null && document.querySelector('.storia') !== null", "Dashboard stretta"); Assert.IsTrue((await ui.EvalAsync("(() => { const a = document.querySelector('.cruscotto .anteprima').getBoundingClientRect(); const s = document.querySelector('.cruscotto-lato').getBoundingClientRect(); return a.bottom <= s.top + 1; })()")).GetBoolean(), "l'anteprima sopra lo stato e i tetti"); Assert.IsTrue((await ui.EvalAsync("(() => { const h = document.querySelector('.storia').getBoundingClientRect(); const q = document.querySelector('.coda').getBoundingClientRect(); return h.bottom <= q.top + 1; })()")).GetBoolean(), "cronologia e coda in una colonna"); Assert.IsTrue((await ui.EvalAsync("document.documentElement.scrollWidth <= innerWidth")).GetBoolean(), "nessuno scorrimento orizzontale"); } }