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
@@ -0,0 +1,157 @@
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Data;
|
||||
using Febe.Tests.Support;
|
||||
|
||||
namespace Febe.Tests.Data;
|
||||
|
||||
/// <summary>
|
||||
/// «Tutte le foto» (spec §4.6): one tile per file of the library, in the order of the entries and then of the series,
|
||||
/// with keyset paging that may stop and start again inside a post.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class LibraryFilesTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task EveryFileOfTheLibraryIsATileInTheOrderOfTheEntriesAndOfTheSeries()
|
||||
{
|
||||
using var temp = new TempFolder();
|
||||
await using var db = await TestDatabase.OpenAsync(temp);
|
||||
var (carousel, single, partial, story) = await FillAsync(db);
|
||||
|
||||
var page = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files });
|
||||
var keys = page.Tiles.Select(t => (t.EntryId, t.FilePosition)).ToList();
|
||||
CollectionAssert.AreEqual(
|
||||
new (long, int?)[] { (story, 1), (carousel, 1), (carousel, 2), (carousel, 3), (partial, 1), (partial, 3), (single, 1) },
|
||||
keys,
|
||||
"Newest entry first, each by position; the file still to download of the partial post is not a tile.");
|
||||
Assert.IsNull(page.Older);
|
||||
Assert.IsNull(page.Newer);
|
||||
|
||||
// A file tile describes that file, and keeps the count of the files of its post («2/3»).
|
||||
var second = page.Tiles[2];
|
||||
Assert.AreEqual(3, second.MediaCount);
|
||||
Assert.AreEqual(MediaKind.Video, second.CoverKind);
|
||||
Assert.AreEqual(Make.Sha(12), second.CoverSha256);
|
||||
Assert.AreEqual(TimeSpan.FromSeconds(15), second.CoverDuration);
|
||||
Assert.AreEqual(3, page.Tiles[5].FilePosition);
|
||||
Assert.AreEqual(3, page.Tiles[5].MediaCount);
|
||||
|
||||
// The grouped mosaic is what it was: one tile per entry.
|
||||
var grouped = await db.Entries.QueryLibraryAsync(new LibraryQuery());
|
||||
CollectionAssert.AreEqual(new[] { story, carousel, partial, single }, grouped.Tiles.Select(t => t.EntryId).ToArray());
|
||||
Assert.IsTrue(grouped.Tiles.All(t => t.FilePosition is null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task WindowsOfTwoWalkEveryFileOnceInBothDirectionsAlsoFromInsideAPost()
|
||||
{
|
||||
using var temp = new TempFolder();
|
||||
await using var db = await TestDatabase.OpenAsync(temp);
|
||||
await FillAsync(db);
|
||||
var all = (await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files })).Tiles.Select(Key).ToList();
|
||||
|
||||
// Older, two at a time from the top: the second window starts in the middle of the carousel.
|
||||
var walked = new List<string>();
|
||||
LibraryCursor? cursor = null;
|
||||
var windows = 0;
|
||||
do
|
||||
{
|
||||
var page = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Limit = 2, Cursor = cursor });
|
||||
walked.AddRange(page.Tiles.Select(Key));
|
||||
Assert.AreEqual(windows > 0, page.Newer is not null, "a window after the first has something newer");
|
||||
cursor = page.Older;
|
||||
windows++;
|
||||
}
|
||||
while (cursor is not null);
|
||||
|
||||
CollectionAssert.AreEqual(all, walked);
|
||||
Assert.AreEqual(4, windows);
|
||||
|
||||
// Newer, two at a time from the last file, back to the top.
|
||||
var last = (await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Limit = 1000 })).Tiles[^1];
|
||||
cursor = new LibraryCursor(last.PublishedAt, last.EntryId, last.FilePosition!.Value);
|
||||
var back = new List<string>();
|
||||
while (cursor is not null)
|
||||
{
|
||||
var page = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Limit = 2, Cursor = cursor, Direction = LibraryDirection.Newer });
|
||||
Assert.IsNotNull(page.Older, "a window newer than a file has that file after it");
|
||||
back.InsertRange(0, page.Tiles.Select(Key));
|
||||
cursor = page.Newer;
|
||||
}
|
||||
|
||||
CollectionAssert.AreEqual(all.Take(all.Count - 1).ToList(), back);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FiltersCountsAndDaysCountTheFiles()
|
||||
{
|
||||
using var temp = new TempFolder();
|
||||
await using var db = await TestDatabase.OpenAsync(temp);
|
||||
var (carousel, _, _, _) = await FillAsync(db);
|
||||
|
||||
// «Video» shows only the videos, «Foto» only the photos (of posts, as in the grouped mosaic).
|
||||
var videos = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Filter = new LibraryFilter { Kind = LibraryKindFilter.Videos } });
|
||||
CollectionAssert.AreEqual(new[] { $"{carousel}.2" }, videos.Tiles.Select(Key).ToArray());
|
||||
var photos = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Filter = new LibraryFilter { Kind = LibraryKindFilter.Photos } });
|
||||
Assert.HasCount(5, photos.Tiles);
|
||||
Assert.IsTrue(photos.Tiles.All(t => t.CoverKind == MediaKind.Photo));
|
||||
|
||||
Assert.AreEqual(7, await db.Entries.CountLibraryFilesAsync(new LibraryFilter()));
|
||||
Assert.AreEqual(1, await db.Entries.CountLibraryFilesAsync(new LibraryFilter { Kind = LibraryKindFilter.Videos }));
|
||||
Assert.AreEqual(5, await db.Entries.CountLibraryFilesAsync(new LibraryFilter { Kind = LibraryKindFilter.Photos }));
|
||||
Assert.AreEqual(1, await db.Entries.CountLibraryFilesAsync(new LibraryFilter { Kind = LibraryKindFilter.Stories }));
|
||||
Assert.AreEqual(new LibraryTotals(4, 1), await db.Entries.GetLibraryTotalsAsync(new LibraryFilter()), "the totals stay entries");
|
||||
|
||||
var days = await db.Entries.CountLibraryByDayAsync(new LibraryFilter(), TestZones.Rome, MosaicMode.Files);
|
||||
CollectionAssert.AreEqual(new[] { new DayCount(new DateOnly(2026, 10, 13), 6), new DayCount(new DateOnly(2026, 10, 12), 1) }, days.ToArray());
|
||||
var entryDays = await db.Entries.CountLibraryByDayAsync(new LibraryFilter(), TestZones.Rome);
|
||||
CollectionAssert.AreEqual(new[] { new DayCount(new DateOnly(2026, 10, 13), 3), new DayCount(new DateOnly(2026, 10, 12), 1) }, entryDays.ToArray());
|
||||
|
||||
// With a filter on accounts the files are counted entry by entry: the same numbers.
|
||||
var accountId = (await db.Entries.GetAsync(carousel))!.AccountId;
|
||||
var other = await db.Accounts.AddAsync(Make.Account("luca.demo"));
|
||||
await db.Entries.AddAsync(Make.Entry(other.Id, "o", new DateTimeOffset(2026, 10, 13, 8, 0, 0, TimeSpan.Zero)), [Make.Stored(Make.Photo(), Make.Sha(41), "o/o.jpg")]);
|
||||
var mine = new LibraryFilter { AccountIds = [accountId] };
|
||||
Assert.AreEqual(7, await db.Entries.CountLibraryFilesAsync(mine));
|
||||
Assert.AreEqual(8, await db.Entries.CountLibraryFilesAsync(new LibraryFilter()));
|
||||
CollectionAssert.AreEqual(days.ToArray(), (await db.Entries.CountLibraryByDayAsync(mine, TestZones.Rome, MosaicMode.Files)).ToArray());
|
||||
Assert.AreEqual(8, (await db.Entries.CountLibraryByDayAsync(new LibraryFilter(), TestZones.Rome, MosaicMode.Files)).Sum(d => d.Count));
|
||||
Assert.AreEqual(1, await db.Entries.CountLibraryFilesAsync(mine with { Kind = LibraryKindFilter.Videos }));
|
||||
|
||||
// A day whose files are all of another kind has no row in «Video».
|
||||
var videoDays = await db.Entries.CountLibraryByDayAsync(new LibraryFilter { Kind = LibraryKindFilter.Videos }, TestZones.Rome, MosaicMode.Files);
|
||||
CollectionAssert.AreEqual(new[] { new DayCount(new DateOnly(2026, 10, 13), 1) }, videoDays.ToArray());
|
||||
|
||||
// The cursor at the end of a day (what the mosaic asks first for a day) starts with that day's newest file.
|
||||
var dayStart = LocalCalendar.StartOfDay(new DateOnly(2026, 10, 13), TestZones.Rome);
|
||||
var fromDay = await db.Entries.QueryLibraryAsync(new LibraryQuery { Mode = MosaicMode.Files, Limit = 1, Cursor = new LibraryCursor(dayStart, 0) });
|
||||
Assert.AreEqual(new DateOnly(2026, 10, 12), LocalCalendar.Today(fromDay.Tiles.Single().PublishedAt, TestZones.Rome));
|
||||
}
|
||||
|
||||
private static string Key(LibraryTile tile) => $"{tile.EntryId}.{tile.FilePosition}";
|
||||
|
||||
/// <summary>
|
||||
/// A story (13 Oct, 12:00), a carousel of photo, video, photo (13 Oct, 10:00), a post with its second file still to
|
||||
/// download (13 Oct, 9:00) and a single photo (12 Oct, 9:00), all of one account.
|
||||
/// </summary>
|
||||
private static async Task<(long Carousel, long Single, long Partial, long Story)> FillAsync(FebeDatabase db)
|
||||
{
|
||||
var account = await db.Accounts.AddAsync(Make.Account("marta.demo"));
|
||||
var day = new DateTimeOffset(2026, 10, 13, 0, 0, 0, TimeSpan.FromHours(2));
|
||||
var single = await db.Entries.AddAsync(Make.Entry(account.Id, "s", day.AddHours(-15)), [Make.Stored(Make.Photo(), Make.Sha(1), "p/s.jpg")]);
|
||||
var partial = await db.Entries.AddAsync(Make.Entry(account.Id, "p", day.AddHours(9)), [
|
||||
Make.Stored(Make.Photo(1), Make.Sha(21), "p/p1.jpg"),
|
||||
Make.Photo(2),
|
||||
Make.Stored(Make.Photo(3), Make.Sha(23), "p/p3.jpg"),
|
||||
]);
|
||||
var carousel = await db.Entries.AddAsync(Make.Entry(account.Id, "c", day.AddHours(10)), [
|
||||
Make.Stored(Make.Photo(1), Make.Sha(11), "p/c1.jpg"),
|
||||
Make.Stored(Make.Video(2), Make.Sha(12), "p/c2.mp4"),
|
||||
Make.Stored(Make.Photo(3), Make.Sha(13), "p/c3.jpg"),
|
||||
]);
|
||||
var story = await db.Entries.AddAsync(Make.Entry(account.Id, "st", day.AddHours(12), EntryKind.Story), [Make.Stored(Make.Photo(), Make.Sha(31), "s/st.jpg")]);
|
||||
Assert.AreEqual(EntryState.Partial, partial.Stored.Entry.State);
|
||||
return (carousel.Stored.Entry.Id, single.Stored.Entry.Id, partial.Stored.Entry.Id, story.Stored.Entry.Id);
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,34 @@ public sealed class LibraryScaleTests
|
||||
Assert.AreEqual(new LibraryTotals(Entries, Accounts), totals);
|
||||
var days = await Measure("conteggi per giorno", AggregateBoundMs, () => db.Entries.CountLibraryByDayAsync(new LibraryFilter(), TestZones.Rome));
|
||||
Assert.AreEqual(Entries, days.Sum(d => d.Count));
|
||||
// «Tutte le foto» (spec §4.6): one tile per file, in the same times as the grouped mosaic.
|
||||
var files = await Measure("tutte le foto: prima finestra", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files }));
|
||||
Assert.HasCount(200, files.Tiles);
|
||||
Assert.IsTrue(files.Tiles.All(t => t.FilePosition is not null));
|
||||
var insidePost = files.Tiles.First(t => t.MediaCount == 2 && t.FilePosition == 1);
|
||||
var resumed = await Measure("tutte le foto: finestra dentro un post", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery
|
||||
{
|
||||
Limit = 200,
|
||||
Mode = MosaicMode.Files,
|
||||
Cursor = new LibraryCursor(insidePost.PublishedAt, insidePost.EntryId, 1),
|
||||
}));
|
||||
Assert.AreEqual((insidePost.EntryId, (int?)2), (resumed.Tiles[0].EntryId, resumed.Tiles[0].FilePosition));
|
||||
var filesMiddle = await Measure("tutte le foto: finestra a metà", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Cursor = middleCursor }));
|
||||
Assert.HasCount(200, filesMiddle.Tiles);
|
||||
await Measure("tutte le foto: più recente da metà", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Cursor = middleCursor, Direction = LibraryDirection.Newer }));
|
||||
await Measure("tutte le foto: filtro Video", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Filter = new LibraryFilter { Kind = LibraryKindFilter.Videos } }));
|
||||
await Measure("tutte le foto: un account", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Filter = new LibraryFilter { AccountIds = [accountIds[3]] } }));
|
||||
await Measure("tutte le foto: ricerca comune", AggregateBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Filter = new LibraryFilter { Search = "caffe" } }));
|
||||
var fileCount = await Measure("tutte le foto: totale dei file", AggregateBoundMs, () => db.Entries.CountLibraryFilesAsync(new LibraryFilter()));
|
||||
Assert.AreEqual(Entries + (Entries / 5), fileCount);
|
||||
var fileDays = await Measure("tutte le foto: conteggi per giorno", AggregateBoundMs, () => db.Entries.CountLibraryByDayAsync(new LibraryFilter(), TestZones.Rome, MosaicMode.Files));
|
||||
Assert.AreEqual(fileCount, fileDays.Sum(d => d.Count));
|
||||
var accountFiles = await Measure("tutte le foto: conteggi di un account", AggregateBoundMs, () => db.Entries.CountLibraryByDayAsync(new LibraryFilter { AccountIds = [accountIds[3]] }, TestZones.Rome, MosaicMode.Files));
|
||||
Assert.AreEqual(await db.Entries.CountLibraryFilesAsync(new LibraryFilter { AccountIds = [accountIds[3]] }, ct), accountFiles.Sum(d => d.Count));
|
||||
await Measure("scheda account: Post", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Filter = new LibraryFilter { AccountIds = [accountIds[3]], Kind = LibraryKindFilter.Posts } }));
|
||||
await Measure("scheda account: Post, tutte le foto", IndexBoundMs, () => db.Entries.QueryLibraryAsync(new LibraryQuery { Limit = 200, Mode = MosaicMode.Files, Filter = new LibraryFilter { AccountIds = [accountIds[3]], Kind = LibraryKindFilter.Posts } }));
|
||||
await Measure("scheda account: conteggi dei Post", AggregateBoundMs, () => db.Entries.CountLibraryByDayAsync(new LibraryFilter { AccountIds = [accountIds[3]], Kind = LibraryKindFilter.Posts }, TestZones.Rome));
|
||||
await Measure("tutte le foto: conteggi del filtro Video", AggregateBoundMs, () => db.Entries.CountLibraryByDayAsync(new LibraryFilter { Kind = LibraryKindFilter.Videos }, TestZones.Rome, MosaicMode.Files));
|
||||
await Measure("è già noto? (pagina di 12)", IndexBoundMs, async () => await db.Entries.GetKnownInstagramIdsAsync(accountIds[5], EntryKind.Post, Enumerable.Range(0, 12).Select(i => $"id{5 + (i * 40)}").ToList()));
|
||||
await Measure("SHA-256 in tutta la libreria", IndexBoundMs, () => db.Media.FindBySha256Async(Make.Sha(150_001)));
|
||||
var summaries = await Measure("elenco account con conteggi", AggregateBoundMs, () => db.Accounts.ListSummariesAsync(new DateTimeOffset(2026, 10, 1, 0, 0, 0, TimeSpan.Zero)));
|
||||
|
||||
@@ -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