Découverts par les tests bUnit des pages : - SnapshotsPage : OnClick était passé à MudPaper, qui n'a pas ce paramètre dans MudBlazor 9.7 → le clic sur une carte était silencieusement ignoré, la lightbox n'ouvrait jamais. Remplacé par un div cliquable (role=button, tabindex) autour du contenu. - FilterBar : SearchChanged/CategoryChanged déclarés mais jamais invoqués → la recherche ne se déclenchait que via le submit du form. ValueChanged câblé pour invoquer les EventCallback à la frappe/sélection. Tests mis à jour pour le comportement corrigé : clic carte → dialog, recherche à la frappe → rechargement sans submit.
98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using Bunit;
|
|
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 SnapshotsPageTests : PageTestBase
|
|
{
|
|
private static readonly Guid CameraId = Guid.NewGuid();
|
|
|
|
private static EventItem SnapshotEvent(
|
|
string type = "PersonDetected",
|
|
double confidence = 0.87,
|
|
string? label = "Personne",
|
|
string? snapshotUrl = "/snapshots/1.jpg") =>
|
|
new(Guid.NewGuid(), CameraId, type, confidence, label, snapshotUrl, snapshotUrl,
|
|
DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow);
|
|
|
|
[Fact]
|
|
public void SnapshotsPage_AfficheSnapshots()
|
|
{
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
[SnapshotEvent("PersonDetected", 0.87, "Personne", "/snapshots/1.jpg"),
|
|
SnapshotEvent("VehicleDetected", 0.66, "Voiture", "/snapshots/2.jpg"),
|
|
SnapshotEvent("MotionDetected", 0.5, null, null)], // sans snapshot → filtré
|
|
3, 1, 100));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<SnapshotsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("2 snapshot(s) trouvé(s)");
|
|
cut.Markup.ShouldContain("Personne");
|
|
cut.Markup.ShouldContain("/snapshots/1.jpg");
|
|
cut.Markup.ShouldContain("/snapshots/2.jpg");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void SnapshotsPage_AucunSnapshot_AfficheMessage()
|
|
{
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
[SnapshotEvent("MotionDetected", 0.5, null, null)], 1, 1, 100));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<SnapshotsPage>();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun snapshot trouvé."));
|
|
}
|
|
|
|
[Fact]
|
|
public void SnapshotsPage_Recherche_FiltreLesSnapshots()
|
|
{
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
[SnapshotEvent("PersonDetected", 0.87, "Personne", "/snapshots/1.jpg"),
|
|
SnapshotEvent("VehicleDetected", 0.66, "Voiture", "/snapshots/2.jpg")],
|
|
2, 1, 100));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<SnapshotsPage>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("2 snapshot(s) trouvé(s)"));
|
|
|
|
// Champ recherche sans Immediate → Change
|
|
cut.FindAll("input")[0].Change("Personne");
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Charger")).Click();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("1 snapshot(s) trouvé(s)");
|
|
cut.Markup.ShouldContain("Personne");
|
|
cut.Markup.ShouldNotContain("Voiture");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void SnapshotsPage_OuvrirLightbox_AfficheDialog()
|
|
{
|
|
// Le clic sur une carte ouvre la lightbox (MudDialog avec le snapshot).
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
[SnapshotEvent("PersonDetected", 0.87, "Personne", "/snapshots/1.jpg")], 1, 1, 100));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<SnapshotsPage>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Personne · 87%"));
|
|
|
|
// La carte est un div cliquable (role=button)
|
|
var cards = cut.FindAll("div[role=button]");
|
|
cards.Count.ShouldBeGreaterThan(0);
|
|
cards[0].Click();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Voir la caméra"));
|
|
}
|
|
}
|