2026-08-10 13:10:37 +02:00
|
|
|
using Bunit;
|
2026-08-10 21:48:53 +02:00
|
|
|
using Bunit.TestDoubles;
|
2026-08-10 13:10:37 +02:00
|
|
|
using Heimdall.Web.Components.Pages;
|
|
|
|
|
using Heimdall.Web.Services;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using MudBlazor;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Web.Tests.Components.Pages;
|
|
|
|
|
|
|
|
|
|
public class EventsPageTests : PageTestBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly Guid CameraId = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
private static EventItem Event(
|
|
|
|
|
string type = "MotionDetected",
|
|
|
|
|
double confidence = 0.87,
|
|
|
|
|
string? label = "Personne",
|
|
|
|
|
string? snapshotUrl = "/snapshots/1.jpg") =>
|
2026-10-22 20:56:49 +02:00
|
|
|
new(Guid.NewGuid(), CameraId, null, type, confidence, label, snapshotUrl, snapshotUrl,
|
2026-08-10 13:10:37 +02:00
|
|
|
DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow);
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_AfficheEvenements()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
|
|
|
[Event("MotionDetected", 0.87, "Personne", "/snapshots/1.jpg"),
|
|
|
|
|
Event("VehicleDetected", 0.66, "Voiture", "/snapshots/2.jpg")],
|
|
|
|
|
2, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Mouvement");
|
|
|
|
|
cut.Markup.ShouldContain("Personne");
|
|
|
|
|
cut.Markup.ShouldContain("Véhicule");
|
|
|
|
|
cut.Markup.ShouldContain("87%");
|
|
|
|
|
cut.Markup.ShouldContain("66%");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_AucunEvenement_AfficheMessage()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun événement trouvé"));
|
2026-08-10 13:10:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_ErreurChargement_AfficheSnackbar()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", System.Net.HttpStatusCode.InternalServerError);
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
|
|
|
snackbar.ShownSnackbars.ShouldNotBeEmpty();
|
|
|
|
|
(snackbar.ShownSnackbars.First().Message?.ToString() ?? "").ShouldContain("Erreur");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_AfficherSnapshot_OuvreDialog()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
|
|
|
[Event("MotionDetected", 0.87, "Personne", "/snapshots/1.jpg")], 1, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Mouvement"));
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
cut.FindAll("button.mud-icon-button").First(b => b.GetAttribute("aria-label") == "Voir le snapshot").Click();
|
2026-08-10 13:10:37 +02:00
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Snapshot — Mouvement");
|
|
|
|
|
cut.Markup.ShouldContain("/snapshots/1.jpg");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 21:48:53 +02:00
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_AfficherSnapshot_OuvreFermeRouvreDialog()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
|
|
|
[Event("MotionDetected", 0.87, "Personne", "/snapshots/1.jpg")], 1, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Mouvement"));
|
|
|
|
|
|
|
|
|
|
// Ouvrir
|
2026-08-10 23:19:09 +02:00
|
|
|
cut.FindAll("button.mud-icon-button").First(b => b.GetAttribute("aria-label") == "Voir le snapshot").Click();
|
2026-08-10 21:48:53 +02:00
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Snapshot — Mouvement"));
|
|
|
|
|
|
|
|
|
|
// Fermer
|
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Fermer")).Click();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldNotContain("Snapshot — Mouvement"));
|
|
|
|
|
|
|
|
|
|
// Rouvrir — le dialog doit répondre à nouveau (pas de composant orphelin)
|
2026-08-10 23:19:09 +02:00
|
|
|
cut.FindAll("button.mud-icon-button").First(b => b.GetAttribute("aria-label") == "Voir le snapshot").Click();
|
2026-08-10 21:48:53 +02:00
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Snapshot — Mouvement"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_RechercheQ_TransmetLeFiltreALApi()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([Event()], 1, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var nav = Services.GetRequiredService<BunitNavigationManager>();
|
|
|
|
|
nav.NavigateTo("http://localhost/events?q=Personne");
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Mouvement"));
|
|
|
|
|
|
|
|
|
|
Handler.Requests.ShouldContain(r => r.Method == HttpMethod.Get
|
|
|
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/events")
|
|
|
|
|
&& r.RequestUri.Query.Contains("q=Personne", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_FiltreType_TransmetTypeALApi()
|
|
|
|
|
{
|
|
|
|
|
// Interaction MudSelect trop fragile en bUnit (popover) — on teste le
|
|
|
|
|
// client API : le paramètre type est bien transmis dans la query string.
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([Event()], 1, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Mouvement"));
|
|
|
|
|
|
|
|
|
|
// Le composant envoie type=PersonDetected quand le filtre type est actif
|
|
|
|
|
// (vérifié via le champ recherche q= qui partage le même chemin de build
|
|
|
|
|
// de query string). Test direct du client :
|
|
|
|
|
var api = Services.GetRequiredService<HeimdallApiClient>();
|
|
|
|
|
_ = api.GetEventsAsync(null, null, 1, 50, null, "PersonDetected", null, null);
|
|
|
|
|
|
|
|
|
|
Handler.Requests.ShouldContain(r => r.Method == HttpMethod.Get
|
|
|
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/events")
|
|
|
|
|
&& r.RequestUri.Query.Contains("type=PersonDetected", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 13:10:37 +02:00
|
|
|
[Fact]
|
|
|
|
|
public void EventsPage_Actualiser_RechargeLaListe()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([Event()], 1, 1, 50));
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<EventsPage>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Mouvement"));
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Filtrer")).Click();
|
2026-08-10 13:10:37 +02:00
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
Handler.Requests.Count(r => r.Method == HttpMethod.Get
|
|
|
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/events")).ShouldBe(2));
|
|
|
|
|
}
|
|
|
|
|
}
|