Pages couvertes : Login, Register, Dashboard, SitesPage, SiteDetail, CamerasPage (+ AuthState, HeimdallAuthStateProvider) — 105 tests Web verts. Infrastructure nécessaire pour rendre les pages testables avec bUnit : - MudTestBase : JSInterop en mode Loose + wrapper générique IAsyncDisposable→IDisposable (Castle DynamicProxy) pour les services MudBlazor (PopoverService, PointerEventsNoneService...) qui cassent le Dispose synchrone de bUnit - HostWithProviders.razor : fournit MudPopoverProvider + MudDialogProvider — sans eux les MudDialog inline des pages ne sont jamais rendus - PageTestBase.RenderPage<T> : rend les pages dans ce host - bunit 2.7.2 → 2.9.0, AngleSharp → 1.7.0, SDK Razor pour les .razor locaux Correctifs de tests : ShouldContain avec prédicat (sous-chaîne au lieu d'égalité stricte sur les messages snackbar), .Input()/.Change() selon Immediate des champs, format P0 (87% sans espace), index des boutons d'action (copier vs supprimer).
177 lines
5.3 KiB
C#
177 lines
5.3 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 DashboardTests : PageTestBase
|
|
{
|
|
private static readonly Guid SiteId = Guid.NewGuid();
|
|
private static readonly Guid AgentId = Guid.NewGuid();
|
|
private static readonly Guid CameraId = Guid.NewGuid();
|
|
|
|
private void SetupHappyPath()
|
|
{
|
|
Handler.OnGet("api/stats", new StatsEnvelope(
|
|
new StatsResult(
|
|
TotalSites: 3,
|
|
TotalCameras: 42,
|
|
TotalAgents: 10,
|
|
OnlineAgents: 7,
|
|
ActiveSites: 2,
|
|
OfflineAgents: 3,
|
|
CamerasOnline: 30,
|
|
CamerasOffline: 8,
|
|
TotalUsers: 5),
|
|
DateTime.UtcNow));
|
|
|
|
Handler.OnGet("api/sites", new PagedData<SiteItem>(
|
|
[new SiteItem(SiteId, "Site Principal", "12 rue des Caméras", "Europe/Paris", true, DateTime.UtcNow.AddDays(-10))],
|
|
1, 1, 5));
|
|
|
|
Handler.OnGet("api/agents", new PagedData<AgentItem>(
|
|
[new AgentItem
|
|
{
|
|
Id = AgentId,
|
|
SiteId = SiteId,
|
|
SiteName = "Site Principal",
|
|
Name = "Agent-1",
|
|
Hostname = "agent-1",
|
|
Version = "1.0.0",
|
|
Status = "Online",
|
|
LastHeartbeat = DateTime.UtcNow.AddMinutes(-1),
|
|
HasGpu = true
|
|
}],
|
|
1, 1, 5));
|
|
|
|
Handler.OnGet("api/events", new EventPageResult(
|
|
[new EventItem(
|
|
Guid.NewGuid(), CameraId, "PersonDetected", 0.87, "Personne",
|
|
"/snapshots/1.jpg", "/snapshots/1-thumb.jpg",
|
|
DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow)],
|
|
1, 1, 10));
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AfficheStatistiques()
|
|
{
|
|
SetupHappyPath();
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Caméras");
|
|
cut.Markup.ShouldContain("Agents en ligne");
|
|
cut.Markup.ShouldContain("Événements (24h)");
|
|
cut.Markup.ShouldContain("Sites");
|
|
cut.Markup.ShouldContain("42");
|
|
cut.Markup.ShouldContain("7");
|
|
cut.Markup.ShouldContain("30 en ligne");
|
|
cut.Markup.ShouldContain("8 hors ligne");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AfficheNomUtilisateur()
|
|
{
|
|
SetupHappyPath();
|
|
LoginAs("Admin", "Jean Dupont");
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Bienvenue");
|
|
cut.Markup.ShouldContain("Jean Dupont");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AfficheSites()
|
|
{
|
|
SetupHappyPath();
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Site Principal"));
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AfficheEvenementsRecents()
|
|
{
|
|
SetupHappyPath();
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Derniers événements");
|
|
cut.Markup.ShouldContain("Personne");
|
|
cut.Markup.ShouldContain("87%");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AfficheAgentsEtLienAdmin()
|
|
{
|
|
SetupHappyPath();
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Charge des agents");
|
|
cut.Markup.ShouldContain("Agent-1");
|
|
cut.Markup.ShouldContain($"/agents/{AgentId}");
|
|
cut.Markup.ShouldContain("/admin/agents");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_AucunSite_AfficheEtatVide()
|
|
{
|
|
Handler.OnGet("api/stats", new StatsEnvelope(
|
|
new StatsResult(0, 0, 0, 0, 0, 0, 0, 0, 0), DateTime.UtcNow));
|
|
Handler.OnGet("api/sites", new PagedData<SiteItem>([], 0, 1, 5));
|
|
Handler.OnGet("api/agents", new PagedData<AgentItem>([], 0, 1, 5));
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 10));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Aucun site configuré");
|
|
cut.Markup.ShouldContain("Aucun événement récent.");
|
|
cut.Markup.ShouldContain("Aucun agent enregistré.");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void DashboardPage_ErreurStats_AfficheSnackbarErreur()
|
|
{
|
|
Handler.OnGet("api/stats", System.Net.HttpStatusCode.InternalServerError);
|
|
Handler.OnGet("api/sites", new PagedData<SiteItem>([], 0, 1, 5));
|
|
Handler.OnGet("api/agents", new PagedData<AgentItem>([], 0, 1, 5));
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 10));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<Dashboard>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
snackbar.ShownSnackbars.ShouldNotBeEmpty();
|
|
(snackbar.ShownSnackbars.First().Message?.ToString() ?? "").ShouldContain("Erreur");
|
|
});
|
|
}
|
|
}
|