E4: prove dei video fermi e dimostrazione a ogni ora
Completa l'elenco di prove del progetto: analizzatore (grana, luce che pulsa, foto notturna, contenitori, durata sconosciuta, flussi rovinati), servizio (lavori lunghi, file spariti o cambiati, errori, «Interrompi», chiusura), copie del fotogramma (pausa e ripresa, validazione, video sempre intero), API (selezioni, stesso file, eventi) e l'interfaccia vera nel browser: visualizzatore, «Salva il fotogramma», «Cerca i video fermi», Dashboard e filtro «Video fermi». Le prove hanno trovato che la dimostrazione dipendeva dall'ora: la storia ferma poteva avere la copertina del video fermo di marta (un file solo invece di due) e il video «Non analizzabile» poteva mancare. Ora la storia è su un'altra immagine e, se le immagini senza copie non bastano, si usano quelle di foto copiate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eea4394a0f
commit
066addbc84
10 files changed
+1100
-18
No files matched your search
@@ -10,6 +10,7 @@ using Febe.Core.Library.StillVideos;
|
||||
using Febe.Tests.Support;
|
||||
using Febe.Tests.Web.Support;
|
||||
using Febe.Web.Demo;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Febe.Tests.Web;
|
||||
|
||||
@@ -202,6 +203,57 @@ public sealed class DemoStillVideoTests
|
||||
Assert.HasCount(2, (await OkAsync(HttpMethod.Get, "/api/library?kind=stillvideos&limit=100")).Items("tiles").ToList(), "the moving file is never still");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(9)]
|
||||
[DataRow(20)]
|
||||
[Timeout(600_000, CooperativeCancellation = true)]
|
||||
public async Task WhateverTheHourTheDemoHasItsStillVideos(int hour)
|
||||
{
|
||||
// The demo is built around its local time (posts of «oggi» are there or not yet): the still videos never depend
|
||||
// on it. The hour is the zone's, so the test asks for the same thing whenever it runs.
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder("demo-fermi-ore");
|
||||
var offset = TimeSpan.FromMinutes(Math.Round(((hour + 0.5) * 60) - DateTimeOffset.UtcNow.TimeOfDay.TotalMinutes));
|
||||
offset = offset > TimeSpan.FromHours(12) ? offset - TimeSpan.FromHours(24) : offset < TimeSpan.FromHours(-12) ? offset + TimeSpan.FromHours(24) : offset;
|
||||
var zone = TimeZoneInfo.CreateCustomTimeZone("prova", offset, "prova", "prova");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, zone, temp.Path), ct);
|
||||
|
||||
Assert.HasCount(2, demo.World.StillVideoFiles);
|
||||
var tiles = (await demo.Storage.Entries.QueryLibraryAsync(
|
||||
new Febe.Core.Storage.LibraryQuery { Filter = new Febe.Core.Storage.LibraryFilter { Kind = Febe.Core.Storage.LibraryKindFilter.StillVideos }, Limit = 100 },
|
||||
ct)).Tiles;
|
||||
Assert.HasCount(2, tiles, "one post and one story");
|
||||
var accounts = await demo.Storage.Accounts.ListAsync(ct);
|
||||
var marta = accounts.Single(a => a.Username == DemoStillVideos.StillAccount).Id;
|
||||
Assert.AreEqual(1, tiles.Count(t => t.AccountId == marta));
|
||||
var entries = await Task.WhenAll(tiles.Select(async t => (await demo.Storage.Entries.GetAsync(t.EntryId, ct))!));
|
||||
Assert.AreEqual(1, entries.Count(e => e.Kind == EntryKind.Story && e.AccountId != marta));
|
||||
Assert.IsTrue(entries.All(e => e.PublishedAt <= demo.App.Services.GetRequiredService<Febe.Core.Abstractions.IClock>().Now), "published, not to come");
|
||||
|
||||
var outcomes = new List<(VideoAnalysisOutcome, string?)>();
|
||||
var unanalysed = 0;
|
||||
foreach (var video in await VideosAsync(demo, marta, ct))
|
||||
{
|
||||
if (await demo.Storage.VideoAnalyses.GetAsync(video.Sha256!, ct) is { } analysis)
|
||||
{
|
||||
outcomes.Add((analysis.Outcome, analysis.Note));
|
||||
}
|
||||
else
|
||||
{
|
||||
unanalysed++;
|
||||
}
|
||||
}
|
||||
|
||||
CollectionAssert.AreEquivalent(
|
||||
new (VideoAnalysisOutcome, string?)[]
|
||||
{
|
||||
(VideoAnalysisOutcome.Still, null), (VideoAnalysisOutcome.Moving, null), (VideoAnalysisOutcome.NotAnalyzable, VideoAnalysisNotes.TooSlow),
|
||||
},
|
||||
outcomes.Distinct().ToArray(),
|
||||
string.Join(", ", outcomes));
|
||||
Assert.IsGreaterThan(0, unanalysed, "«È un video fermo?» has a video to be tried on");
|
||||
}
|
||||
|
||||
private static async Task<Media> UnanalysedVideoAsync(DemoHost demo, long accountId, CancellationToken ct)
|
||||
{
|
||||
foreach (var media in await VideosAsync(demo, accountId, ct))
|
||||
@@ -218,17 +270,26 @@ public sealed class DemoStillVideoTests
|
||||
/// <summary>The present videos of an account in the library, newest first.</summary>
|
||||
private static async Task<List<Media>> VideosAsync(DemoHost demo, long accountId, CancellationToken ct)
|
||||
{
|
||||
var page = await demo.Storage.Entries.QueryLibraryAsync(
|
||||
new Febe.Core.Storage.LibraryQuery { Filter = new Febe.Core.Storage.LibraryFilter { AccountIds = [accountId] }, Mode = Febe.Core.Storage.MosaicMode.Files, Limit = 1000 },
|
||||
ct);
|
||||
// Every page: @marta.demo has more than a thousand files, and the videos the demo analysed can be among the oldest
|
||||
// (the pictures that no copy uses depend on the hour).
|
||||
var videos = new List<Media>();
|
||||
foreach (var tile in page.Tiles.Where(t => t.CoverKind == MediaKind.Video))
|
||||
Febe.Core.Storage.LibraryCursor? cursor = null;
|
||||
do
|
||||
{
|
||||
if (await demo.Storage.Media.GetAsync(tile.CoverMediaId!.Value, ct) is { Sha256: not null } media && EntryStateRules.IsPresent(media.State))
|
||||
var page = await demo.Storage.Entries.QueryLibraryAsync(
|
||||
new Febe.Core.Storage.LibraryQuery { Filter = new Febe.Core.Storage.LibraryFilter { AccountIds = [accountId] }, Mode = Febe.Core.Storage.MosaicMode.Files, Cursor = cursor, Limit = 500 },
|
||||
ct);
|
||||
foreach (var tile in page.Tiles.Where(t => t.CoverKind == MediaKind.Video))
|
||||
{
|
||||
videos.Add(media);
|
||||
if (await demo.Storage.Media.GetAsync(tile.CoverMediaId!.Value, ct) is { Sha256: not null } media && EntryStateRules.IsPresent(media.State))
|
||||
{
|
||||
videos.Add(media);
|
||||
}
|
||||
}
|
||||
|
||||
cursor = page.Older;
|
||||
}
|
||||
while (cursor is not null);
|
||||
|
||||
return videos;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Core.Library.StillVideos;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Tests.Support;
|
||||
using Febe.Tests.Web.Support;
|
||||
using Febe.Web.Demo;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Febe.Tests.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Tappa E4 in a real browser, on the demo (spec §4.10 «Video fermi», §10.3): the chip, the row and the buttons of a still
|
||||
/// video in the viewer, «Salva il fotogramma» («Scarica» and «Nella cartella delle copie»), «È un video fermo?» and
|
||||
/// «Analizza di nuovo», the filter «Video fermi», the confirmation of «Cerca i video fermi» with its counts, its end, its
|
||||
/// card in the Dashboard with the reason it waits and «Interrompi». Analyses are only ever on request: what each video is
|
||||
/// before the test asks is read from the database and the API, never assumed from how the demo is built (it places its
|
||||
/// entries by the hour, #72).
|
||||
/// </summary>
|
||||
public sealed partial class ExportInterfaceTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task TheViewerShowsAStillVideoAndSavesItsFrame()
|
||||
{
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("fermi-visualizzatore-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||
// The name of every file the page gives to the browser to download.
|
||||
await ui.AddInitScriptAsync("(() => { window.__downloads = []; const click = HTMLAnchorElement.prototype.click; HTMLAnchorElement.prototype.click = function () { if (this.hasAttribute('download')) window.__downloads.push(this.download); return click.call(this); }; })();");
|
||||
|
||||
var (still, analysis) = await DemoVideoAsync(demo, a => a?.Outcome == VideoAnalysisOutcome.Still);
|
||||
await OpenInViewerAsync(ui, demo, still.Id, "docker");
|
||||
await ui.WaitAsync("document.querySelector('.vis .azione-salva-fotogramma') !== null", "«Salva il fotogramma» nel visualizzatore " + ui.Report());
|
||||
var entry = await ui.EvalAsync(Get($"/api/entries/{still.EntryId}"));
|
||||
var said = entry.GetProperty("media").EnumerateArray().Single(m => m.GetProperty("id").GetInt64() == still.Id).GetProperty("still");
|
||||
var label = said.GetProperty("frameLabel").GetString()!;
|
||||
Assert.AreEqual((long)analysis!.FrameAt!.Value.TotalMilliseconds, said.GetProperty("frameAtMs").GetInt64());
|
||||
|
||||
// The chip, the row with the instant chosen, and no question: it was analysed.
|
||||
Assert.IsTrue((await ui.EvalAsync("[...document.querySelectorAll('.vis .etichette .et.accento')].some((e) => e.textContent.trim() === 'Video fermo')")).GetBoolean(), "l'etichetta «Video fermo»");
|
||||
Assert.AreEqual($"Un'immagine sola per tutto il video: basta un fotogramma · fotogramma a {label}", (await ui.EvalAsync("document.querySelector('.vis .riga-fermo span').textContent")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis .azione-video-fermo') === null && document.querySelector('.vis .analizza-di-nuovo') === null")).GetBoolean());
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis .azione-fotogramma') !== null")).GetBoolean(), "«Fotogramma» di E3 resta");
|
||||
|
||||
// «Salva il fotogramma»: the frame alone, with its preview; no instant, no number to choose.
|
||||
const string Dialog = "document.querySelector('.dialogo.fotogrammi')";
|
||||
const string Start = $"{Dialog}.querySelector('footer .btn.primo')";
|
||||
await ui.EvalAsync("document.querySelector('.vis .azione-salva-fotogramma').click()");
|
||||
await ui.WaitAsync($"{Dialog}?.querySelector('.istante-mostrato') != null", "il dialogo «Salva il fotogramma»");
|
||||
Assert.AreEqual("Salva il fotogramma", (await ui.EvalAsync($"{Dialog}.querySelector('h2').textContent")).GetString());
|
||||
Assert.AreEqual($"Il fotogramma più nitido fra quelli guardati dall'analisi, a {label}.", (await ui.EvalAsync($"{Dialog}.querySelector('.istante-mostrato').textContent")).GetString());
|
||||
await ui.WaitAsync($"(() => {{ const i = {Dialog}.querySelector('.anteprima-fotogramma img'); return i && i.complete && i.naturalWidth > 0 && new URL(i.src).pathname === '/api/media/{still.Id}/still/frame'; }})()", "l'anteprima " + ui.Report());
|
||||
Assert.IsTrue((await ui.EvalAsync($"{Dialog}.querySelector('.campo-tempo, input[type=number], [data-value=istante], [data-value=numero]') === null")).GetBoolean(), "nothing to choose but the format");
|
||||
Assert.AreEqual("Il fotogramma non ha l'audio.", (await ui.EvalAsync($"{Dialog}.querySelector('.nota-audio').textContent.trim()")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis video').paused")).GetBoolean(), "the video waits while the dialog is open");
|
||||
|
||||
// PNG first, without loss; JPG says it loses.
|
||||
Assert.AreEqual("png", (await ui.EvalAsync($"{Dialog}.querySelector('[role=radio][aria-checked=true][data-value]').dataset.value")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync($"{Dialog}.querySelector('.nota-perdita').hidden")).GetBoolean());
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('[role=radio][data-value=jpg]').click()");
|
||||
Assert.IsFalse((await ui.EvalAsync($"{Dialog}.querySelector('.nota-perdita').hidden")).GetBoolean());
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('[role=radio][data-value=png]').click()");
|
||||
|
||||
// «Scarica»: one file, its name says «_fotogramma».
|
||||
await ui.WaitAsync($"{Start}.textContent.trim() === 'Scarica 1 fotogramma' && !{Start}.disabled", "«Scarica 1 fotogramma»");
|
||||
Assert.AreEqual("1 fotogramma", (await ui.EvalAsync($"{Dialog}.querySelector('.riepilogo-fotogrammi .riepilogo-copia').textContent")).GetString());
|
||||
await ui.EvalAsync($"{Start}.click()");
|
||||
await ui.WaitAsync($"{Dialog} === null && {Shown("Scaricamento del fotogramma avviato.")}", "il fotogramma si scarica " + ui.Report());
|
||||
Assert.HasCount(1, await ui.AskedAsync($"GET /api/media/{still.Id}/still/frame?format=png&download=1"));
|
||||
var downloads = await ui.EvalAsync<string[]>("window.__downloads");
|
||||
Assert.AreEqual(Path.GetFileNameWithoutExtension(LibraryLayout.ToPlatform(still.RelativePath!)) + "_fotogramma.png", downloads.Single());
|
||||
|
||||
// «Nella cartella delle copie»: the plan of the copies, then a copy of one frame at the instant of the analysis.
|
||||
await ui.EvalAsync("document.querySelector('.vis .azione-salva-fotogramma').click()");
|
||||
await ui.WaitAsync($"{Dialog}?.querySelector('input[type=radio][value=cartella]') != null", "il dialogo, di nuovo");
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('input[type=radio][value=cartella]').click()");
|
||||
await ui.WaitAsync($"{Start}.textContent.trim() === 'Copia 1 fotogramma' && !{Start}.disabled", "«Copia 1 fotogramma» " + ui.Report());
|
||||
await ui.EvalAsync($"{Start}.click()");
|
||||
await ui.WaitAsync($"{Dialog} === null && window.__notices.some((n) => n.href === '/dashboard/esportazione' && !n.kind.includes('errore'))", "la copia parte " + ui.Report());
|
||||
await ui.WaitAsync($"{Get("/api/export/progress")}.then((j) => !j.running)", "la copia finisce");
|
||||
var copy = (await demo.Storage.Exports.ListCopiesBySha256Async(still.Sha256!)).Single(c => c.MediaId == still.Id);
|
||||
Assert.AreEqual((ExportCopyState.Copied, ExportVariant.Frame, ExportFormat.Png, analysis.FrameAt), (copy.State, copy.Variant, copy.Format, copy.FrameAt));
|
||||
StringAssert.EndsWith(copy.RelativePath, "_fotogramma.png");
|
||||
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), ui.Report());
|
||||
await CloseViewerAsync(ui);
|
||||
|
||||
// The viewer opened again has the copy row, as for any frame (looked up by its words: the demo has others).
|
||||
await OpenInViewerAsync(ui, demo, still.Id, "docker");
|
||||
await ui.WaitAsync($"[...document.querySelectorAll('.vis .riga-copia')].some((r) => r.textContent.includes('Copiato in Disco USB') && r.textContent.includes({Js($"fotogramma a {label} · PNG")}))", "la riga «Copia» del fotogramma " + ui.Report());
|
||||
await CloseViewerAsync(ui);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AVideoIsAnalysedFromTheViewerOnlyWhenAsked()
|
||||
{
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("fermi-domanda-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||
|
||||
// Never analysed: no chip, no row, «È un video fermo?». Opening the viewer asks for nothing.
|
||||
var (video, _) = await DemoVideoAsync(demo, a => a is null);
|
||||
const string Ask = "document.querySelector('.vis .azione-video-fermo')";
|
||||
await OpenInViewerAsync(ui, demo, video.Id, "docker");
|
||||
await ui.WaitAsync($"{Ask} !== null && !{Ask}.disabled", "«È un video fermo?» " + ui.Report());
|
||||
Assert.AreEqual("È un video fermo?", (await ui.EvalAsync($"{Ask}.textContent.trim()")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis .riga-fermo') === null && document.querySelector('.vis .azione-salva-fotogramma') === null && document.querySelector('.vis .azione-fotogramma') !== null")).GetBoolean());
|
||||
Assert.IsEmpty(await ui.AskedAsync("/still"));
|
||||
|
||||
// An answer that is not one (an analysis past its 30 seconds): the notice says why, the question stays.
|
||||
await ui.EvalAsync($"(() => {{ const real = window.fetch; window.__real = real; window.fetch = (input, init) => (String(input).endsWith('/api/media/{video.Id}/still') ? Promise.resolve(new Response(JSON.stringify({{ message: {Js(StillVideoText.TooSlow)} }}), {{ status: 503, headers: {{ 'Content-Type': 'application/json' }} }})) : real(input, init)); return true; }})()");
|
||||
await ui.EvalAsync($"{Ask}.click()");
|
||||
await ui.WaitAsync($"window.__notices.some((n) => n.kind.includes('errore') && n.text.includes({Js(StillVideoText.TooSlow)}))", "l'avviso dell'analisi troppo lunga " + ui.Report());
|
||||
await ui.WaitAsync($"{Ask} !== null && !{Ask}.disabled && {Ask}.textContent.trim() === 'È un video fermo?'", "la domanda resta");
|
||||
Assert.IsNull(await demo.Storage.VideoAnalyses.GetAsync(video.Sha256!));
|
||||
await ui.EvalAsync("(() => { window.fetch = window.__real; window.__notices.length = 0; return true; })()");
|
||||
|
||||
// Asked: «Analisi in corso…» until the answer comes, then the row; the button is gone.
|
||||
await ui.EvalAsync($"window.__hold('/api/media/{video.Id}/still')");
|
||||
await ui.EvalAsync($"{Ask}.click()");
|
||||
await ui.WaitAsync($"(window.__started['/api/media/{video.Id}/still'] || 0) === 1 && {Ask}.disabled && {Ask}.textContent.trim() === 'Analisi in corso…'", "«Analisi in corso…»");
|
||||
await ui.EvalAsync($"window.__release('/api/media/{video.Id}/still')");
|
||||
await ui.WaitAsync("document.querySelector('.vis .riga-fermo') !== null", "la riga «Video fermo» " + ui.Report());
|
||||
Assert.AreEqual("No: l'immagine cambia", (await ui.EvalAsync("document.querySelector('.vis .riga-fermo span').textContent")).GetString());
|
||||
await ui.WaitAsync(Shown("Non è un video fermo: l'immagine cambia."), "l'avviso dell'esito");
|
||||
Assert.IsTrue((await ui.EvalAsync($"{Ask} === null && document.querySelector('.vis .azione-salva-fotogramma') === null")).GetBoolean(), "nothing more to ask");
|
||||
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), ui.Report());
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, (await demo.Storage.VideoAnalyses.GetAsync(video.Sha256!))!.Outcome);
|
||||
await CloseViewerAsync(ui);
|
||||
|
||||
// «Non analizzabile» because it took too long: «Analizza di nuovo» gives the answer.
|
||||
var (slow, _) = await DemoVideoAsync(demo, a => a?.Note == VideoAnalysisNotes.TooSlow);
|
||||
await OpenInViewerAsync(ui, demo, slow.Id, "docker");
|
||||
await ui.WaitAsync("document.querySelector('.vis .analizza-di-nuovo') !== null", "«Analizza di nuovo» " + ui.Report());
|
||||
Assert.AreEqual("Non analizzabile: l'analisi richiedeva troppo tempo", (await ui.EvalAsync("document.querySelector('.vis .riga-fermo span').textContent")).GetString());
|
||||
Assert.AreEqual("Analizza di nuovo", (await ui.EvalAsync("document.querySelector('.vis .analizza-di-nuovo').textContent.trim()")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync($"{Ask} === null")).GetBoolean());
|
||||
await ui.EvalAsync("document.querySelector('.vis .analizza-di-nuovo').click()");
|
||||
await ui.WaitAsync("document.querySelector('.vis .riga-fermo span')?.textContent === \"No: l'immagine cambia\" && document.querySelector('.vis .analizza-di-nuovo') === null", "l'esito nuovo " + ui.Report());
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, (await demo.Storage.VideoAnalyses.GetAsync(slow.Sha256!))!.Outcome);
|
||||
await CloseViewerAsync(ui);
|
||||
|
||||
// A photo has nothing of this.
|
||||
var photo = await DemoCopyAsync(demo, ExportVariant.Whole);
|
||||
await OpenInViewerAsync(ui, demo, photo.MediaId!.Value, "docker");
|
||||
await ui.WaitAsync("document.querySelector('.vis .riga-copia') !== null", "una foto nel visualizzatore");
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.vis .riga-fermo, .vis .azione-video-fermo, .vis .azione-salva-fotogramma') === null")).GetBoolean());
|
||||
await CloseViewerAsync(ui);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheFilterVideoFermiIsInTheLibraryAfterVideo()
|
||||
{
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("fermi-filtro-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
|
||||
const string Chips = "[...document.querySelectorAll('.strumenti .filtri button')]";
|
||||
const string Active = "document.querySelector('.strumenti .filtri button.qui')?.textContent.trim()";
|
||||
const string Tiles = "[...document.querySelectorAll('.mosaico .tess')].map((t) => Number(t.dataset.id))";
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/libreria"));
|
||||
await ui.WaitAsync("document.querySelector('.mosaico .tess') !== null", "il mosaico");
|
||||
var names = await ui.EvalAsync<string[]>($"{Chips}.map((b) => b.textContent.trim())");
|
||||
Assert.AreEqual(Array.IndexOf(names, "Video") + 1, Array.IndexOf(names, "Video fermi"), string.Join(" · ", names));
|
||||
Assert.IsGreaterThan(0, Array.IndexOf(names, "Video"), string.Join(" · ", names));
|
||||
|
||||
// Chosen: the address says it, the tiles are those of the API, and the page read again keeps it.
|
||||
var expected = await ui.EvalAsync<long[]>($"{Get("/api/library?kind=stillvideos&limit=100")}.then((j) => j.tiles.map((t) => t.id).sort((a, b) => a - b))");
|
||||
Assert.IsNotEmpty(expected);
|
||||
var same = $"JSON.stringify(({Tiles}).sort((a, b) => a - b)) === {Js(JsonSerializer.Serialize(expected))}";
|
||||
await ui.EvalAsync($"{Chips}.find((b) => b.textContent.trim() === 'Video fermi').click()");
|
||||
await ui.WaitAsync($"new URLSearchParams(location.search).get('tipo') === 'fermi' && {Active} === 'Video fermi'", "il filtro nell'indirizzo");
|
||||
await ui.WaitAsync(same, "le tessere dei video fermi " + ui.Report());
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/libreria?tipo=fermi"));
|
||||
await ui.WaitAsync($"{Active} === 'Video fermi' && {same}", "il filtro riletto dall'indirizzo " + ui.Report());
|
||||
|
||||
// «Tutte le foto»: the still files, one tile each.
|
||||
var files = await ui.EvalAsync<long[]>($"{Get("/api/library?kind=stillvideos&mode=files&limit=100")}.then((j) => j.tiles.map((t) => t.cover.mediaId).sort((a, b) => a - b))");
|
||||
await ui.EvalAsync("document.querySelector('.strumenti .modo-mosaico [data-value=files]').click()");
|
||||
await ui.WaitAsync($"JSON.stringify(({Tiles}).sort((a, b) => a - b)) === {Js(JsonSerializer.Serialize(files))}", "i file dei video fermi " + ui.Report());
|
||||
|
||||
// The account tab has «Cerca i video fermi» but not the filter (answer 40: Libreria only).
|
||||
var (still, _) = await DemoVideoAsync(demo, a => a?.Outcome == VideoAnalysisOutcome.Still);
|
||||
var account = (await demo.Storage.Entries.GetAsync(still.EntryId))!.AccountId;
|
||||
await ui.OpenAsync(new Uri(demo.Address, $"/account/{account}"));
|
||||
await ui.WaitAsync("document.querySelector('.mosaico .tess') !== null && document.querySelector('.filtri button') !== null && [...document.querySelectorAll('.btn')].some((b) => b.textContent.includes('Seleziona'))", "i contenuti dell'account");
|
||||
Assert.IsFalse((await ui.EvalAsync("[...document.querySelectorAll('.filtri button')].some((b) => b.textContent.includes('Video fermi'))")).GetBoolean());
|
||||
await ui.EvalAsync("[...document.querySelectorAll('.btn')].find((b) => b.textContent.includes('Seleziona')).click()");
|
||||
await ui.EvalAsync("document.querySelector('.mosaico .tess').click()");
|
||||
await ui.WaitAsync("document.querySelector('.salva .fermi-selezione') !== null && !document.querySelector('.salva .fermi-selezione').disabled", "«Cerca i video fermi» nella scheda dell'account");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CercaIVideoFermiCountsStartsAndSaysItsEnd()
|
||||
{
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("fermi-cerca-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
var chosen = await ChooseVideosAsync(ui, demo);
|
||||
var body = $"{{ \"entryIds\": {JsonSerializer.Serialize(chosen)} }}";
|
||||
var fresh = (await UnanalysedAsync(demo, chosen))[0];
|
||||
|
||||
// One of the chosen videos is still when it is analysed (the file of the demo's still video is served for it).
|
||||
Assert.IsTrue(demo.World.StillVideoFiles.TryAdd(fresh.Sha256!, demo.World.StillVideoFiles.First().Value));
|
||||
var plan = await ui.EvalAsync(Post("/api/still-videos/plan", body));
|
||||
var toAnalyse = plan.GetProperty("toAnalyse").GetInt32();
|
||||
Assert.IsGreaterThan(0, toAnalyse, plan.ToString());
|
||||
Assert.IsGreaterThan(0, plan.GetProperty("photosSkipped").GetInt32(), plan.ToString());
|
||||
|
||||
// The confirmation says what the API says.
|
||||
const string Dialog = "document.querySelector('.dialogo.cerca-fermi')";
|
||||
await OpenSearchAsync(ui);
|
||||
Assert.AreEqual("Cerca i video fermi", (await ui.EvalAsync($"{Dialog}.querySelector('h2').textContent")).GetString());
|
||||
Assert.AreEqual(plan.GetProperty("summary").GetString(), (await ui.EvalAsync($"{Dialog}.querySelector('.riepilogo-copia').textContent")).GetString());
|
||||
Assert.AreEqual($"Analizza {toAnalyse} video", (await ui.EvalAsync($"{Dialog}.querySelector('footer .btn.primo').textContent.trim()")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync($"{Dialog}.querySelector('.avviso.ambra') === null")).GetBoolean(), "nothing makes it wait");
|
||||
|
||||
// «Annulla» analyses nothing.
|
||||
await ui.EvalAsync($"[...{Dialog}.querySelectorAll('footer button')].find((b) => b.textContent === 'Annulla').click()");
|
||||
await ui.WaitAsync($"{Dialog} === null", "il dialogo si chiude");
|
||||
Assert.IsNull(await demo.Storage.VideoAnalyses.GetAsync(fresh.Sha256!));
|
||||
Assert.AreEqual(0, (await ui.EvalAsync(Get("/api/still-videos/progress"))).GetProperty("total").GetInt32());
|
||||
|
||||
// Started: the notice leads to the Dashboard; the end is said on the page, with the link to what was found.
|
||||
await OpenSearchAsync(ui);
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('footer .btn.primo').click()");
|
||||
await ui.WaitAsync($"{Dialog} === null && {Shown($"Ricerca dei video fermi avviata: {toAnalyse} video da analizzare.")}", "la ricerca parte " + ui.Report());
|
||||
Assert.AreEqual("/dashboard/esportazione", (await ui.EvalAsync("window.__notices.find((n) => n.text.includes('Ricerca dei video fermi avviata')).href")).GetString());
|
||||
await ui.WaitAsync("window.__notices.some((n) => n.text.startsWith('Analizzat'))", "l'avviso della fine " + ui.Report());
|
||||
var done = await ui.EvalAsync(Get("/api/still-videos/progress"));
|
||||
Assert.AreEqual((false, toAnalyse, toAnalyse, 1), (done.GetProperty("running").GetBoolean(), done.GetProperty("total").GetInt32(), done.GetProperty("done").GetInt32(), done.GetProperty("still").GetInt32()), done.ToString());
|
||||
Assert.IsTrue((await ui.EvalAsync(Shown(done.GetProperty("summary").GetString() + "."))).GetBoolean(), "the notice is the summary of the API");
|
||||
Assert.AreEqual("/libreria", (await ui.EvalAsync("window.__notices.find((n) => n.text.startsWith('Analizzat')).href")).GetString());
|
||||
Assert.AreEqual("?tipo=fermi", (await ui.EvalAsync("new URL(window.__noticeLinks.at(-1).href).search")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), ui.Report());
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, (await demo.Storage.VideoAnalyses.GetAsync(fresh.Sha256!))!.Outcome);
|
||||
|
||||
// «Mostra i video fermi»: the filter, with the entry just found (the link of the last notice: the one of the start,
|
||||
// which leads to the Dashboard, can still be on screen).
|
||||
await ui.EvalAsync("(() => { const link = window.__noticeLinks.at(-1); if (link.isConnected) link.click(); else location.assign(link.href); return true; })()");
|
||||
await ui.WaitAsync("location.pathname === '/libreria' && new URLSearchParams(location.search).get('tipo') === 'fermi' && document.querySelector('.strumenti .filtri button.qui')?.textContent.trim() === 'Video fermi' && document.querySelector('.mosaico .tess') !== null", "la Libreria dei video fermi " + ui.Report());
|
||||
var found = await ui.EvalAsync<long[]>($"{Get("/api/library?kind=stillvideos&limit=1000")}.then((j) => j.tiles.map((t) => t.id))");
|
||||
CollectionAssert.Contains(found, fresh.EntryId);
|
||||
|
||||
// The Dashboard keeps the end of the last search, with the same link; a second search has nothing left.
|
||||
await ui.OpenAsync(new Uri(demo.Address, "/dashboard/esportazione"));
|
||||
await ui.WaitAsync($"document.querySelector('.ricerca-fermi .riga-conteggi span')?.textContent === {Js(done.GetProperty("summary").GetString() + ".")}", "la fine nella Dashboard " + ui.Report());
|
||||
Assert.AreEqual("/libreria?tipo=fermi", (await ui.EvalAsync("(() => { const u = new URL(document.querySelector('.ricerca-fermi .riga-conteggi a').href); return u.pathname + u.search; })()")).GetString());
|
||||
var left = await ui.EvalAsync(Post("/api/still-videos/plan", body));
|
||||
Assert.AreEqual(0, left.GetProperty("toAnalyse").GetInt32(), left.ToString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheDashboardSaysWhyTheSearchWaitsAndInterrompiEndsIt()
|
||||
{
|
||||
await using var ui = await UiBrowser.StartAsync(1440, 900);
|
||||
using var temp = new TempFolder("fermi-dashboard-ui");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path));
|
||||
await RecordNoticesAsync(ui);
|
||||
|
||||
var chosen = await ChooseVideosAsync(ui, demo);
|
||||
var fresh = await UnanalysedAsync(demo, chosen);
|
||||
Assert.IsTrue(demo.App.Services.GetRequiredService<LongWorkGate>().TryEnter(LongWorkKind.Import, out var lease, out _));
|
||||
using (lease)
|
||||
{
|
||||
// An import at work: the confirmation says the search will wait, and lets it start.
|
||||
const string Dialog = "document.querySelector('.dialogo.cerca-fermi')";
|
||||
await OpenSearchAsync(ui);
|
||||
Assert.AreEqual(StillVideoText.LongWork, (await ui.EvalAsync($"{Dialog}.querySelector('.avviso.ambra').textContent.trim()")).GetString());
|
||||
await ui.EvalAsync($"{Dialog}.querySelector('footer .btn.primo').click()");
|
||||
await ui.WaitAsync($"{Dialog} === null && {Shown("Ricerca dei video fermi avviata")}", "la ricerca parte " + ui.Report());
|
||||
await ui.EvalAsync(FollowNoticeLink);
|
||||
|
||||
// Dashboard → Esportazione: nothing done yet, the reason, «Interrompi».
|
||||
const string Card = "document.querySelector('.ricerca-fermi .avanzamento-fermi')";
|
||||
await ui.WaitAsync($"location.pathname === '/dashboard/esportazione' && {Card}?.querySelector('.fase-copia') != null", "la ricerca nella Dashboard " + ui.Report());
|
||||
var job = await ui.EvalAsync(Get("/api/still-videos/progress"));
|
||||
var total = job.GetProperty("total").GetInt32();
|
||||
Assert.AreEqual((true, 0), (job.GetProperty("running").GetBoolean(), job.GetProperty("done").GetInt32()), job.ToString());
|
||||
Assert.AreEqual(StillVideoText.LongWork, (await ui.EvalAsync($"{Card}.querySelector('.fase-copia').textContent.trim()")).GetString());
|
||||
Assert.AreEqual(total == 1 ? "0 di 1 video analizzato" : $"0 di {total} video analizzati", (await ui.EvalAsync($"{Card}.querySelector('.conteggio').textContent")).GetString());
|
||||
Assert.IsTrue((await ui.EvalAsync("(() => { const b = [...document.querySelectorAll('.avanzamento-fermi button')].find((x) => x.textContent.trim() === 'Interrompi'); if (!b || b.disabled) return false; b.click(); return true; })()")).GetBoolean());
|
||||
await ui.WaitAsync("document.querySelector('.ricerca-fermi .riga-conteggi span')?.textContent === 'Ricerca interrotta: nessun video analizzato.'", "la ricerca interrotta " + ui.Report());
|
||||
}
|
||||
|
||||
var ended = await ui.EvalAsync(Get("/api/still-videos/progress"));
|
||||
Assert.AreEqual((false, true, 0), (ended.GetProperty("running").GetBoolean(), ended.GetProperty("stopped").GetBoolean(), ended.GetProperty("done").GetInt32()), ended.ToString());
|
||||
foreach (var media in fresh)
|
||||
{
|
||||
Assert.IsNull(await demo.Storage.VideoAnalyses.GetAsync(media.Sha256!), "nothing was analysed");
|
||||
}
|
||||
|
||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('.ricerca-fermi .riga-conteggi a') === null")).GetBoolean(), "nothing found, nothing to show");
|
||||
Assert.IsTrue((await ui.EvalAsync(NoErrorNotice)).GetBoolean(), ui.Report());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------- support
|
||||
|
||||
/// <summary>
|
||||
/// The newest video of @marta.demo whose analysis (null: never analysed) is the one looked for. Read from the database:
|
||||
/// which of the demo's videos they are depends on the hour it is built.
|
||||
/// </summary>
|
||||
private static async Task<(Media Media, VideoAnalysis? Analysis)> DemoVideoAsync(DemoHost demo, Func<VideoAnalysis?, bool> wanted)
|
||||
{
|
||||
var marta = (await demo.Storage.Accounts.ListAsync()).Single(a => a.Username == DemoStillVideos.StillAccount).Id;
|
||||
LibraryCursor? cursor = null;
|
||||
do
|
||||
{
|
||||
var page = await demo.Storage.Entries.QueryLibraryAsync(
|
||||
new LibraryQuery { Filter = new LibraryFilter { AccountIds = [marta] }, Mode = MosaicMode.Files, Cursor = cursor, Limit = 500 });
|
||||
foreach (var tile in page.Tiles.Where(t => t.CoverKind == MediaKind.Video && t.CoverMediaId is not null))
|
||||
{
|
||||
if (await demo.Storage.Media.GetAsync(tile.CoverMediaId!.Value) is { Sha256: { } sha, RelativePath: not null } media && EntryStateRules.IsPresent(media.State)
|
||||
&& await demo.Storage.VideoAnalyses.GetAsync(sha) is var analysis && wanted(analysis))
|
||||
{
|
||||
return (media, analysis);
|
||||
}
|
||||
}
|
||||
|
||||
cursor = page.Older;
|
||||
}
|
||||
while (cursor is not null);
|
||||
|
||||
Assert.Fail("the demo has no such video");
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects, in the Libreria of @marta.demo, up to two entries with a video never analysed and one of photos only among
|
||||
/// the tiles on screen (what they are is asked of the API). Returns the entries.
|
||||
/// </summary>
|
||||
private static async Task<long[]> ChooseVideosAsync(UiBrowser ui, DemoHost demo)
|
||||
{
|
||||
var marta = (await demo.Storage.Accounts.ListAsync()).Single(a => a.Username == DemoStillVideos.StillAccount).Id;
|
||||
await ui.OpenAsync(new Uri(demo.Address, string.Create(CultureInfo.InvariantCulture, $"/libreria?account={marta}")));
|
||||
await ui.WaitAsync("document.querySelectorAll('.mosaico .tess').length >= 4 && [...document.querySelectorAll('.mosaico .tess')].every((t) => t.dataset.id)", "il mosaico di marta.demo");
|
||||
Assert.IsTrue((await ui.EvalAsync(ClickText(".strumenti", ".btn", "Seleziona"))).GetBoolean());
|
||||
return await ui.EvalAsync<long[]>(
|
||||
"(async () => { const fresh = []; const photos = []; "
|
||||
+ "for (const id of [...document.querySelectorAll('.mosaico .tess')].map((t) => Number(t.dataset.id))) { "
|
||||
+ "if (fresh.length === 2 && photos.length === 1) break; "
|
||||
+ "const e = await fetch(`/api/entries/${id}`, { headers: { Accept: 'application/json' } }).then((r) => r.json()); "
|
||||
+ "if (e.media.some((m) => m.kind === 'video' && m.available && !m.still)) { if (fresh.length < 2) fresh.push(id); } "
|
||||
+ "else if (e.media.every((m) => m.kind === 'photo') && !photos.length) photos.push(id); } "
|
||||
+ "const chosen = [...fresh, ...photos]; "
|
||||
+ "chosen.forEach((id) => document.querySelector(`.mosaico .tess[data-id=\"${id}\"]`).click()); return chosen; })()");
|
||||
}
|
||||
|
||||
/// <summary>The videos never analysed of the entries.</summary>
|
||||
private static async Task<List<Media>> UnanalysedAsync(DemoHost demo, long[] entries)
|
||||
{
|
||||
var found = new List<Media>();
|
||||
foreach (var id in entries)
|
||||
{
|
||||
foreach (var media in (await demo.Storage.Entries.GetWithMediaAsync(id))!.Media.Where(m => m.Kind == MediaKind.Video && m.Sha256 is not null))
|
||||
{
|
||||
if (await demo.Storage.VideoAnalyses.GetAsync(media.Sha256!) is null)
|
||||
{
|
||||
found.Add(media);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsNotEmpty(found, "a video never analysed among the tiles on screen");
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>«Cerca i video fermi» of the selection bar, until its counts are there and the button can be pressed.</summary>
|
||||
private static async Task OpenSearchAsync(UiBrowser ui)
|
||||
{
|
||||
const string Search = "document.querySelector('.salva .fermi-selezione')";
|
||||
const string Start = "document.querySelector('.dialogo.cerca-fermi footer .btn.primo')";
|
||||
await ui.WaitAsync($"{Search} && !{Search}.disabled", "«Cerca i video fermi» nella barra della scelta " + ui.Report());
|
||||
Assert.AreEqual("Cerca i video fermi", (await ui.EvalAsync($"{Search}.textContent.trim()")).GetString());
|
||||
await ui.EvalAsync($"{Search}.click()");
|
||||
await ui.WaitAsync($"document.querySelector('.dialogo.cerca-fermi .riepilogo-copia') !== null && !{Start}.disabled", "i conti della ricerca " + ui.Report());
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ namespace Febe.Tests.Web;
|
||||
/// the selection with its summary and the toast that leads to the Dashboard, the «Copie» filter in the address with the
|
||||
/// marks of the tiles and the menu of the CSV icon, the rows «Copia» of the viewer with «Copia di nuovo», and the
|
||||
/// Dashboard tab «Esportazione». Chromium only (CI); the selectors follow the pages of WP3, checked on the demo. Tappa
|
||||
/// E3 (formats, frames, the conversion of the library) is in ExportInterfaceTests.Formats.cs.
|
||||
/// E3 (formats, frames, the conversion of the library) is in ExportInterfaceTests.Formats.cs, tappa E4 (still videos) in
|
||||
/// ExportInterfaceTests.StillVideos.cs.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed partial class ExportInterfaceTests
|
||||
|
||||
@@ -343,6 +343,111 @@ public sealed class StillVideosApiTests
|
||||
Assert.IsFalse((await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task EverySelectionIsCountedAndTheSameFileIsAnalysedOnce()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var luca = await server.Db.Accounts.AddAsync(Make.Account("luca.demo", "200"));
|
||||
var same = Still(14);
|
||||
var first = await WebLibrary.AddPostAsync(server, marta, "uno", Make.T0.AddDays(-1), WebLibrary.Video(same), WebLibrary.Photo(4), WebLibrary.Photo(5));
|
||||
var twin = (await server.Db.Entries.AddAsync(
|
||||
Make.Entry(marta.Id, "due", Make.T0.AddDays(-2)),
|
||||
[Make.Stored(Make.Video(1), first.Media[0].Sha256!, first.Media[0].RelativePath!)],
|
||||
ct)).Stored;
|
||||
var other = await WebLibrary.AddPostAsync(server, luca, "tre", Make.T0.AddDays(-3), WebLibrary.Video(Moving()));
|
||||
Assert.AreEqual(first.Media[0].Sha256, twin.Media[0].Sha256);
|
||||
|
||||
async Task<JsonElement> PlanAsync(object selection)
|
||||
{
|
||||
var (status, plan) = await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection);
|
||||
Assert.AreEqual(HttpStatusCode.OK, status, plan.ToString());
|
||||
return plan;
|
||||
}
|
||||
|
||||
// The files, the entries, a filter in both modes, an account: one file counts once, the photos are told apart.
|
||||
foreach (var (selection, toAnalyse, photos) in new (object, int, int)[]
|
||||
{
|
||||
(new { mediaIds = new[] { first.Media[0].Id, first.Media[1].Id } }, 1, 1),
|
||||
(new { mediaIds = new[] { first.Media[1].Id, first.Media[2].Id } }, 0, 2),
|
||||
(new { entryIds = new[] { first.Entry.Id, twin.Entry.Id, other.Entry.Id } }, 2, 2),
|
||||
(new { query = $"accounts={marta.Id}", mode = "grouped" }, 1, 2),
|
||||
(new { query = "kind=videos", mode = "files" }, 2, 0),
|
||||
(new { query = "kind=stillvideos", mode = "files" }, 0, 0),
|
||||
(new { accountId = luca.Id }, 1, 0),
|
||||
})
|
||||
{
|
||||
var plan = await PlanAsync(selection);
|
||||
Assert.AreEqual((toAnalyse, photos), (plan.Int("toAnalyse"), plan.Int("photosSkipped")), $"{JsonSerializer.Serialize(selection)}: {plan}");
|
||||
}
|
||||
|
||||
// Photos only: nothing to start, and the job does not.
|
||||
var none = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", new { mediaIds = new[] { first.Media[1].Id } })).Body;
|
||||
Assert.AreEqual((false, 0), (none.Bool("running"), none.Int("total")), none.ToString());
|
||||
|
||||
// Analysed once, under either post; the second asks nothing more.
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", new { accountId = marta.Id })).Status);
|
||||
await WebLibrary.WaitAsync(async () => !(await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"), "the job ends");
|
||||
Assert.AreEqual(1, (await server.GetJsonAsync("/api/still-videos/progress")).Int("still"));
|
||||
var shown = (await server.GetJsonAsync($"/api/entries/{twin.Entry.Id}")).Items("media").Single().GetProperty("still");
|
||||
Assert.AreEqual("still", shown.Str("outcome"), "the same file under another post has the same analysis");
|
||||
var tiles = (await server.GetJsonAsync("/api/library?kind=stillvideos&limit=50")).Items("tiles").Select(t => t.Long("id")).ToArray();
|
||||
CollectionAssert.AreEquivalent(new[] { first.Entry.Id, twin.Entry.Id }, tiles);
|
||||
Assert.AreEqual(1, (await PlanAsync(new { query = "kind=stillvideos", mode = "grouped" })).Int("alreadyAnalysed"));
|
||||
|
||||
// An analysis of an algorithm newer than this Febe's is current (there is none older than 1 yet).
|
||||
await server.Db.VideoAnalyses.SetAsync(new VideoAnalysis(other.Media[0].Sha256!, StillVideoAnalyzer.Algorithm + 1, VideoAnalysisOutcome.Moving, server.Clock.Now), ct);
|
||||
var newer = (await server.GetJsonAsync($"/api/entries/{other.Entry.Id}")).Items("media").Single().GetProperty("still");
|
||||
Assert.AreEqual(("moving", true), (newer.Str("outcome"), newer.Bool("current")), newer.ToString());
|
||||
Assert.AreEqual(0, (await PlanAsync(new { accountId = luca.Id })).Int("toAnalyse"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task TheFrameOfAPhotoAnUnknownOrAMissingFileIsRefused()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var post = await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(Still(15)), WebLibrary.Photo(4));
|
||||
var video = post.Media[0];
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still")).Status);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{post.Media[1].Id}/still/frame")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, (await server.SendJsonAsync(HttpMethod.Get, "/api/media/999999/still/frame")).Status);
|
||||
|
||||
// Another file in its place: the analysis was of the old one, so there is no frame to save.
|
||||
var sha = video.Sha256!;
|
||||
await server.Db.Media.UpdateAsync((await server.Db.Media.GetAsync(video.Id, ct))! with { Sha256 = Make.Sha(91) }, ct);
|
||||
var (replaced, body) = await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{video.Id}/still/frame");
|
||||
Assert.AreEqual(HttpStatusCode.Conflict, replaced);
|
||||
StringAssert.StartsWith(body.Str("message"), StillVideoText.NotStill);
|
||||
await server.Db.Media.UpdateAsync((await server.Db.Media.GetAsync(video.Id, ct))! with { Sha256 = sha }, ct);
|
||||
|
||||
File.Delete(WebLibrary.PathOf(server, marta, video));
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{video.Id}/still/frame?download=1")).Status);
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, (await server.Db.VideoAnalyses.GetAsync(sha, ct))!.Outcome, "what was found of the file stays");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task TheOpenPagesHearOfAnAnalysisOnce()
|
||||
{
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var video = (await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(Still(16)))).Media[0];
|
||||
var changes = server.Changes.SubscribeAsync().GetAsyncEnumerator();
|
||||
var next = changes.MoveNextAsync().AsTask();
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still")).Status);
|
||||
|
||||
Assert.IsTrue(await next.WaitAsync(TimeSpan.FromSeconds(20)), "the library of the open pages is read again");
|
||||
Assert.AreEqual(("fermi", (long?)marta.Id), (changes.Current.Reason, changes.Current.AccountId));
|
||||
await changes.DisposeAsync();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------- support
|
||||
|
||||
private static readonly FebeWebOptions Options = new() { Edition = FebeEdition.Desktop, Access = AccessMode.None };
|
||||
|
||||
Reference in new issue
Block a user