Files
Heimdall/tests/Heimdall.Web.Tests/Components/Pages/SnapshotsPageTests.cs
T
Arnaud Dartois 93757dfe8b test(web): couvre les pages IHM restantes (Users, Profile, Settings, Events, Snapshots, Audit, Agents, AllAgents) — 158 tests Web verts
Ajout des tests bUnit : UsersPageTests (11), ProfileTests, SettingsPageTests,
EventsPageTests, SnapshotsPageTests, AuditLogsPageTests, AgentsPageTests,
AllAgentsPageTests.

Découvertes de bugs réels par les tests :
- SnapshotsPage : OnClick passé à MudPaper est ignoré (pas de paramètre
  OnClick dans MudBlazor 9.7) → lightbox jamais ouvrable au clic
- FilterBar : SearchChanged déclaré mais jamais invoqué → la recherche ne
  recharge que via le submit du form
2026-08-10 13:10:37 +02:00

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()
{
// NB : MudPaper n'a pas de paramètre OnClick dans MudBlazor 9.7 → le clic
// de la carte est silencieusement ignoré (bug src connu). On vérifie donc
// que la carte affiche bien les données attendues (label + confiance).
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%");
cut.Markup.ShouldContain("/snapshots/1.jpg");
cut.Markup.ShouldContain("cursor: pointer");
});
}
}