D1, quarta parte: «Raggruppa i post» o «Tutte le foto» in Libreria e scheda account
Un post con più foto era una tessera sola: per vederle tutte bisognava aprirlo. Ora un interruttore nella riga degli strumenti (Libreria e Contenuti dell'account, non «In evidenza») passa a una tessera per file, video dei caroselli compresi, con la posizione «2/4» sulla tessera; la scelta resta nel browser, una per pagina, e il predefinito è raggruppato (§4.6). - API: /api/library e /api/library/days accettano mode=files; il cursore diventa «ms.elemento.posizione», i giorni contano file e il totale dice anche quanti file. Le finestre restano a chiavi sull'indice di pubblicazione; per i conteggi un indice ix_media_entry_files (entry_id, state, kind) nella migrazione 0002 non ancora unita. Prova di scala a 200.000 elementi: finestre 6-11 ms, conteggi 0,2-0,3 s. - Visualizzatore: si apre sul file della tessera e va di file in file, anche da un elemento al successivo («Libreria, file 12 di 30.340»). - Selezione di file; elenco CSV ed «Elimina» lavorano sugli elementi interi e lo dicono («3 file scelti appartengono a 2 elementi: elimino gli elementi interi, 9 file»). «Copia in…» non è in questo ramo. - Dimostrazione: alcune serie hanno un video in seconda posizione, scelto dall'identificativo senza toccare la sequenza casuale. - Prove di archivio, API, dimostrazione e interfaccia (queste ultime con Chromium, solo nella CI); guida e decisioni aggiornate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
34fe5e9073
commit
30e159cbd4
23 files changed
+1126
-130
No files matched your search
@@ -163,6 +163,34 @@ public sealed class DemoTests
|
||||
Assert.IsGreaterThan(0, videos, "some entries are videos");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TutteLeFotoShowsEveryFileOfTheDemoSeriesAlsoTheirVideos()
|
||||
{
|
||||
// «Tutte le foto» (spec §4.6) has something to show in the demo: posts of many photos, and series with a video.
|
||||
var grouped = await GetAsync("/api/library/days");
|
||||
var files = await GetAsync("/api/library/days?mode=files");
|
||||
Assert.AreEqual(grouped.Int("entries"), files.Int("entries"));
|
||||
Assert.IsGreaterThan(grouped.Int("entries"), files.Int("files"), "more files than entries");
|
||||
Assert.AreEqual(files.Int("files"), files.Items("days").Sum(d => d.Int("count")));
|
||||
|
||||
var seriesVideos = 0;
|
||||
string? cursor = null;
|
||||
var pages = 0;
|
||||
do
|
||||
{
|
||||
var page = await GetAsync("/api/library?mode=files&kind=videos&limit=600" + (cursor is null ? string.Empty : "&cursor=" + Uri.EscapeDataString(cursor)));
|
||||
seriesVideos += page.Items("tiles").Count(t => t.Int("files") >= 3 && t.Int("position") == 2);
|
||||
cursor = page.GetProperty("older").ValueKind == JsonValueKind.String ? page.Str("older") : null;
|
||||
pages++;
|
||||
}
|
||||
while (cursor is not null && pages < 100);
|
||||
|
||||
var first = await GetAsync("/api/library?mode=files&limit=600");
|
||||
var series = first.Items("tiles").Count(t => t.Int("files") > 1 && t.Int("position") == 1);
|
||||
Assert.IsGreaterThan(0, series, "posts of several photos near the top");
|
||||
Assert.IsGreaterThan(0, seriesVideos, "some series have a video in second place");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task EntriesAreDiscoveredAfterPublicationAndTheirFilesLiveInTheTemporaryFolder()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Tests.Support;
|
||||
using Febe.Tests.Web.Support;
|
||||
|
||||
namespace Febe.Tests.Web;
|
||||
|
||||
/// <summary>
|
||||
/// «Tutte le foto» through the API (spec §4.6): <c>mode=files</c> on the days and on the windows, one tile per file
|
||||
/// with its position, cursors that go on inside a post, day rows that count files and totals that say both.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class LibraryFilesApiTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task WindowsOfFilesWalkEveryFileOnceAndTheDaysCountThem()
|
||||
{
|
||||
await using var server = await WebTestServer.StartAsync();
|
||||
var (entries, files) = await FillAsync(server);
|
||||
|
||||
var days = await server.GetJsonAsync("/api/library/days?mode=files");
|
||||
Assert.AreEqual(entries, days.Int("entries"), "the totals still count the entries");
|
||||
Assert.AreEqual(files, days.Int("files"));
|
||||
Assert.AreEqual(files, days.Items("days").Sum(d => d.Int("count")), "the day rows count the files");
|
||||
Assert.AreEqual(JsonValueKind.Null, (await server.GetJsonAsync("/api/library/days")).GetProperty("files").ValueKind, "grouped: no file total");
|
||||
|
||||
var seen = new List<(long Ms, long Id, int Position, long Media)>();
|
||||
string? cursor = null;
|
||||
var pages = 0;
|
||||
do
|
||||
{
|
||||
var page = await server.GetJsonAsync("/api/library?mode=files&limit=4" + (cursor is null ? string.Empty : "&cursor=" + Uri.EscapeDataString(cursor)));
|
||||
foreach (var tile in page.Items("tiles"))
|
||||
{
|
||||
seen.Add((tile.Long("publishedAt"), tile.Long("id"), tile.Int("position"), tile.GetProperty("cover").Long("mediaId")));
|
||||
}
|
||||
|
||||
cursor = page.GetProperty("older").ValueKind == JsonValueKind.Null ? null : page.Str("older");
|
||||
pages++;
|
||||
}
|
||||
while (cursor is not null && pages < 50);
|
||||
|
||||
Assert.HasCount(files, seen);
|
||||
Assert.HasCount(files, seen.Select(s => s.Media).Distinct(), "every file once");
|
||||
Assert.HasCount(entries, seen.Select(s => s.Id).Distinct());
|
||||
for (var i = 1; i < seen.Count; i++)
|
||||
{
|
||||
var (a, b) = (seen[i - 1], seen[i]);
|
||||
Assert.IsTrue(b.Ms < a.Ms || (b.Ms == a.Ms && (b.Id < a.Id || (b.Id == a.Id && b.Position > a.Position))), "entries newest first, each by position");
|
||||
}
|
||||
|
||||
// The cursor of a day starts at that day, in files.
|
||||
foreach (var day in days.Items("days").Take(3))
|
||||
{
|
||||
var page = await server.GetJsonAsync($"/api/library?mode=files&limit={day.Int("count")}&cursor={Uri.EscapeDataString(day.Str("cursor"))}");
|
||||
Assert.IsTrue(page.Items("tiles").All(t => t.Str("day") == day.Str("day")), day.Str("day"));
|
||||
Assert.AreEqual(day.Int("count"), page.Items("tiles").Count());
|
||||
}
|
||||
|
||||
// From inside a carousel: the next file of the same post, and back up.
|
||||
var inside = seen.FindIndex(s => s.Position == 2);
|
||||
var at = seen[inside];
|
||||
var next = await server.GetJsonAsync($"/api/library?mode=files&limit=1&cursor={at.Ms}.{at.Id}.{at.Position}");
|
||||
Assert.AreEqual(seen[inside + 1].Media, next.Items("tiles").Single().GetProperty("cover").Long("mediaId"));
|
||||
var back = await server.GetJsonAsync($"/api/library?mode=files&limit=2&direction=newer&cursor={at.Ms}.{at.Id}.{at.Position}");
|
||||
CollectionAssert.AreEqual(seen.Skip(inside - 2).Take(2).Select(s => s.Media).ToList(), back.Items("tiles").Select(t => t.GetProperty("cover").Long("mediaId")).ToList());
|
||||
|
||||
// A file tile says the files of its post; the grouped tiles have no position.
|
||||
var carousel = seen.First(s => s.Position == 3);
|
||||
var tiles = (await server.GetJsonAsync("/api/library?mode=files&limit=200")).Items("tiles").Where(t => t.Long("id") == carousel.Id).ToList();
|
||||
Assert.IsTrue(tiles.All(t => t.Int("files") == tiles.Count));
|
||||
Assert.IsTrue((await server.GetJsonAsync("/api/library?limit=200")).Items("tiles").All(t => t.GetProperty("position").ValueKind == JsonValueKind.Null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FiltersWorkTheSameAndBadValuesAreRefused()
|
||||
{
|
||||
await using var server = await WebTestServer.StartAsync();
|
||||
await FillAsync(server);
|
||||
|
||||
// «Video» shows only the video files, «Foto» only the photos.
|
||||
var videos = await server.GetJsonAsync("/api/library?mode=files&kind=videos&limit=200");
|
||||
Assert.IsTrue(videos.Items("tiles").All(t => t.GetProperty("cover").Str("kind") == "video"));
|
||||
Assert.AreEqual(videos.Items("tiles").Count(), (await server.GetJsonAsync("/api/library/days?mode=files&kind=videos")).Int("files"));
|
||||
var photos = await server.GetJsonAsync("/api/library?mode=files&kind=photos&limit=200");
|
||||
Assert.IsTrue(photos.Items("tiles").All(t => t.GetProperty("cover").Str("kind") == "photo"));
|
||||
Assert.AreEqual(4, (await server.GetJsonAsync("/api/library/days?mode=files&kind=stories")).Int("files"));
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, "/api/library?mode=gatti")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, "/api/library/days?mode=tutte")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, "/api/library?mode=files&cursor=1.2.x")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, "/api/library?mode=files&cursor=1.2.-1")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, "/api/library?cursor=99999999999999999.2")).Status, "a time outside the calendar");
|
||||
}
|
||||
|
||||
/// <summary>Ten posts of one to four files (the third of a series is a video) and four stories: entries and files.</summary>
|
||||
private static async Task<(int Entries, int Files)> FillAsync(WebTestServer server)
|
||||
{
|
||||
var account = await server.Db.Accounts.AddAsync(Make.Account("marta.demo"));
|
||||
var files = 0;
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var count = (i % 4) + 1;
|
||||
var media = Enumerable.Range(1, count)
|
||||
.Select(p => Make.Stored(p == 3 ? Make.Video(p) : Make.Photo(p), Make.Sha((i * 10) + p), $"p/{i}_{p}.jpg"))
|
||||
.ToList();
|
||||
await server.Db.Entries.AddAsync(Make.Entry(account.Id, $"p{i}", Make.T0 - TimeSpan.FromHours(9 * i)), media);
|
||||
files += count;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
await server.Db.Entries.AddAsync(Make.Entry(account.Id, $"s{i}", Make.T0 - TimeSpan.FromHours((13 * i) + 2), EntryKind.Story), [Make.Stored(Make.Photo(), Make.Sha(500 + i), $"s/{i}.jpg")]);
|
||||
files++;
|
||||
}
|
||||
|
||||
return (14, files);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Febe.Tests.Support;
|
||||
using Febe.Tests.Web.Support;
|
||||
using Febe.Web.Demo;
|
||||
|
||||
namespace Febe.Tests.Web;
|
||||
|
||||
/// <summary>
|
||||
/// «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).
|
||||
/// </summary>
|
||||
[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»");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user