#105 — Topic ntfy cible par site : - Site.NtfyTopic (migration AddSiteNtfyTopic), UI création/édition SitesPage - NotificationService.ResolveNtfyTopicAsync : topic du site sinon heimdall_{userId} #106 — Paramètres SMTP/ntfy/S3 GLOBAUX : - Seed + sections UI : agentScoped=false pour ntfy.*/email.*/storage.*/sentry.* - Migration douce au démarrage : UPDATE des clés existantes en base #107 — GlitchTip : DSN fixes (central projet 6, agent projet 7) dans appsettings, - plus de champ DSN éditable en UI → switch sentry.enabled (nécessite redémarrage) - Init Sentry déplacé après AddInfrastructure, lit sentry.enabled en base (fallback true) #108 — Composants typés : MudNumericField borné (port SMTP, rétention, heartbeat), - switch pour booléens, select pour log.level — pas de saisie libre
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", null, 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");
|
|
});
|
|
}
|
|
}
|