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
This commit is contained in:
1 parent
34a3dd4232
commit
93757dfe8b
8 files changed
+1205
No files matched your search
@@ -0,0 +1,106 @@
|
||||
using Bunit;
|
||||
using Bunit.TestDoubles;
|
||||
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 AgentsPageTests : PageTestBase
|
||||
{
|
||||
private static readonly Guid SiteId = Guid.NewGuid();
|
||||
private static readonly Guid AgentId = Guid.NewGuid();
|
||||
|
||||
private static AgentItem Agent(string name = "Agent-1", string status = "Online") => new()
|
||||
{
|
||||
Id = AgentId,
|
||||
SiteId = SiteId,
|
||||
SiteName = "Site Alpha",
|
||||
Name = name,
|
||||
Hostname = "agent-1",
|
||||
Version = "1.2.3",
|
||||
Status = status,
|
||||
LastHeartbeat = DateTime.UtcNow.AddMinutes(-1),
|
||||
PublicIp = "10.0.0.5",
|
||||
CreatedAt = DateTime.UtcNow.AddDays(-3)
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void AgentsPage_AfficheAgentsDuSite()
|
||||
{
|
||||
Handler.OnGet("api/agents/by-site", new PagedData<AgentItem>(
|
||||
[Agent("Agent-1"), Agent("Agent-2")], 2, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AgentsPage>(p => p.Add(x => x.SiteId, SiteId));
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Agent-1");
|
||||
cut.Markup.ShouldContain("Agent-2");
|
||||
cut.Markup.ShouldContain("agent-1");
|
||||
cut.Markup.ShouldContain("1.2.3");
|
||||
cut.Markup.ShouldContain("Online");
|
||||
cut.Markup.ShouldContain("10.0.0.5");
|
||||
cut.Markup.ShouldContain($"/agents/{AgentId}");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AgentsPage_AucunAgent_AfficheEtatVide()
|
||||
{
|
||||
Handler.OnGet("api/agents/by-site", new PagedData<AgentItem>([], 0, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AgentsPage>(p => p.Add(x => x.SiteId, SiteId));
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun agent enregistré"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AgentsPage_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/agents/by-site", System.Net.HttpStatusCode.InternalServerError);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AgentsPage>(p => p.Add(x => x.SiteId, SiteId));
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement des agents."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AgentsPage_RetourAuxSites_Navigue()
|
||||
{
|
||||
Handler.OnGet("api/agents/by-site", new PagedData<AgentItem>([], 0, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var nav = Services.GetRequiredService<BunitNavigationManager>();
|
||||
var cut = RenderPage<AgentsPage>(p => p.Add(x => x.SiteId, SiteId));
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Retour aux sites"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Retour aux sites")).Click();
|
||||
|
||||
cut.WaitForAssertion(() => nav.Uri.ShouldBe("http://localhost/sites"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AgentsPage_Pagination_Suivant_ChargePage2()
|
||||
{
|
||||
Handler.OnGet("api/agents/by-site", new PagedData<AgentItem>(
|
||||
Enumerable.Range(1, 20).Select(i => Agent($"Agent-{i}")).ToArray(), 25, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AgentsPage>(p => p.Add(x => x.SiteId, SiteId));
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Page 1 sur 2"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Suivant")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/agents/by-site")
|
||||
&& r.RequestUri.Query.Contains("page=2")).ShouldBeTrue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using Bunit;
|
||||
using Bunit.TestDoubles;
|
||||
using Heimdall.Web.Components.Pages.Admin;
|
||||
using Heimdall.Web.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MudBlazor;
|
||||
using Shouldly;
|
||||
|
||||
namespace Heimdall.Web.Tests.Components.Pages;
|
||||
|
||||
public class AllAgentsPageTests : PageTestBase
|
||||
{
|
||||
private static readonly Guid SiteId = Guid.NewGuid();
|
||||
private static readonly Guid AgentId = Guid.NewGuid();
|
||||
|
||||
private static AgentItem Agent(string name = "Agent-1", string siteName = "Site Alpha") => new()
|
||||
{
|
||||
Id = AgentId,
|
||||
SiteId = SiteId,
|
||||
SiteName = siteName,
|
||||
Name = name,
|
||||
Hostname = "agent-1",
|
||||
Version = "1.2.3",
|
||||
Status = "Online",
|
||||
LastHeartbeat = DateTime.UtcNow.AddMinutes(-1),
|
||||
PublicIp = "10.0.0.5",
|
||||
CreatedAt = DateTime.UtcNow.AddDays(-3)
|
||||
};
|
||||
|
||||
private static List<AgentStatItem> Stats() =>
|
||||
[
|
||||
new("total", "Agents", 4, "#4caf50"),
|
||||
new("online", "En ligne", 3, "#2196f3")
|
||||
];
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_AfficheAgentsEtStats()
|
||||
{
|
||||
Handler.OnGet("api/agents", new PagedData<AgentItem>(
|
||||
[Agent("Agent-1"), Agent("Agent-2", "Site Beta")], 2, 1, 20));
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Agent-1");
|
||||
cut.Markup.ShouldContain("Agent-2");
|
||||
cut.Markup.ShouldContain("Site Alpha");
|
||||
cut.Markup.ShouldContain("Site Beta");
|
||||
cut.Markup.ShouldContain("1.2.3");
|
||||
cut.Markup.ShouldContain("Online");
|
||||
cut.Markup.ShouldContain("Agents");
|
||||
cut.Markup.ShouldContain("En ligne");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_AucunAgent_AfficheEtatVide()
|
||||
{
|
||||
Handler.OnGet("api/agents", new PagedData<AgentItem>([], 0, 1, 20));
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Aucun agent déployé");
|
||||
cut.Markup.ShouldContain("Voir les sites");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/agents", System.Net.HttpStatusCode.InternalServerError);
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement des agents."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_Recherche_RechargeLaListe()
|
||||
{
|
||||
Handler.OnGet("api/agents", new PagedData<AgentItem>(
|
||||
[Agent("Agent-1"), Agent("Agent-2")], 2, 1, 20));
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Agent-1"));
|
||||
|
||||
// Le FilterBar n'invoque pas SearchChanged (bug src) : la recherche se
|
||||
// déclenche via le submit du form → OnSearch → LoadData
|
||||
cut.FindAll("input")[0].Input("Agent-2");
|
||||
cut.Find("form").Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Count(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/agents")).ShouldBe(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_VoirLesSites_Navigue()
|
||||
{
|
||||
Handler.OnGet("api/agents", new PagedData<AgentItem>([], 0, 1, 20));
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var nav = Services.GetRequiredService<BunitNavigationManager>();
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Voir les sites"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Voir les sites")).Click();
|
||||
|
||||
cut.WaitForAssertion(() => nav.Uri.ShouldBe("http://localhost/sites"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllAgentsPage_Pagination_Suivant_ChargePage2()
|
||||
{
|
||||
Handler.OnGet("api/agents", new PagedData<AgentItem>(
|
||||
Enumerable.Range(1, 20).Select(i => Agent($"Agent-{i}")).ToArray(), 25, 1, 20));
|
||||
Handler.OnGet("api/stats/agent-stats", Stats());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AllAgentsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Page 1 sur 2"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Suivant")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/agents")
|
||||
&& r.RequestUri.Query.Contains("page=2")).ShouldBeTrue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
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 AuditLogsPageTests : PageTestBase
|
||||
{
|
||||
private static AuditLogItem Log(
|
||||
string action = "UserCreated",
|
||||
string resourceType = "User",
|
||||
string? userEmail = "admin@heimdall.local",
|
||||
string? ip = "192.168.1.10") => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserEmail = userEmail,
|
||||
Action = action,
|
||||
ResourceType = resourceType,
|
||||
ResourceId = Guid.NewGuid().ToString(),
|
||||
IpAddress = ip,
|
||||
Timestamp = DateTime.UtcNow.AddHours(-1)
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_AfficheLogs()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", new PagedData<AuditLogItem>(
|
||||
[Log("UserCreated", "User", "admin@heimdall.local", "192.168.1.10"),
|
||||
Log("Site.Created", "Site", "admin@heimdall.local", "192.168.1.10")], 2, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("admin@heimdall.local");
|
||||
cut.Markup.ShouldContain("UserCreated");
|
||||
cut.Markup.ShouldContain("Site.Created");
|
||||
cut.Markup.ShouldContain("192.168.1.10");
|
||||
cut.Markup.ShouldContain("User");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_AucunLog_AfficheMessage()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", new PagedData<AuditLogItem>([], 0, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucune entrée d'audit"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", System.Net.HttpStatusCode.InternalServerError);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement du journal d'audit."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_Filtrer_EnvoieTypeRessource()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", new PagedData<AuditLogItem>([Log()], 1, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("UserCreated"));
|
||||
|
||||
// Champ resourceType (Immediate=true → Input), puis submit du form de filtre
|
||||
cut.FindAll("input")[0].Input("User");
|
||||
cut.Find("form").Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/audit-logs")
|
||||
&& r.RequestUri.Query.Contains("resourceType=User")).ShouldBeTrue());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_ReinitialiserFiltres_RelanceSansFiltre()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", new PagedData<AuditLogItem>([Log()], 1, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("UserCreated"));
|
||||
|
||||
cut.FindAll("input")[0].Input("User");
|
||||
cut.Find("form").Submit();
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.RequestUri!.Query.Contains("resourceType=User")).ShouldBeTrue());
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Réinitialiser")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Last(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/audit-logs"))
|
||||
.RequestUri!.Query.ShouldNotContain("resourceType"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AuditLogsPage_Pagination_Suivant_ChargePage2()
|
||||
{
|
||||
Handler.OnGet("api/audit-logs", new PagedData<AuditLogItem>(
|
||||
Enumerable.Range(1, 20).Select(i => Log($"Action{i}")).ToArray(), 25, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<AuditLogsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Page 1 sur 2"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Suivant")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/audit-logs")
|
||||
&& r.RequestUri.Query.Contains("page=2")).ShouldBeTrue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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 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") =>
|
||||
new(Guid.NewGuid(), CameraId, type, confidence, label, snapshotUrl, snapshotUrl,
|
||||
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>();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun événement trouvé."));
|
||||
}
|
||||
|
||||
[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"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Snapshot — Mouvement");
|
||||
cut.Markup.ShouldContain("/snapshots/1.jpg");
|
||||
});
|
||||
}
|
||||
|
||||
[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"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Actualiser")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Count(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/events")).ShouldBe(2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
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 ProfileTests : PageTestBase
|
||||
{
|
||||
private static UserItem ProfileUser() => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Email = "jean@heimdall.local",
|
||||
DisplayName = "Jean Dupont",
|
||||
Theme = "Auto",
|
||||
Language = "fr",
|
||||
Roles = ["Admin"],
|
||||
TwoFactorEnabled = true,
|
||||
EmailConfirmed = true,
|
||||
CreatedAt = DateTime.UtcNow.AddDays(-30)
|
||||
};
|
||||
|
||||
private static NotificationConfigItem NotifConfig() => new()
|
||||
{
|
||||
EmailEnabled = false,
|
||||
NtfyEnabled = true,
|
||||
NtfyUrl = "http://ntfy:80",
|
||||
DailyDigest = true,
|
||||
WeeklyDigest = false
|
||||
};
|
||||
|
||||
private void SetupHappyPath()
|
||||
{
|
||||
Handler.OnGet("api/users/me", ProfileUser());
|
||||
Handler.OnGet("api/notifications/config", NotifConfig());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_AfficheInformationsEtSections()
|
||||
{
|
||||
SetupHappyPath();
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Mon profil");
|
||||
cut.Markup.ShouldContain("Jean Dupont");
|
||||
cut.Markup.ShouldContain("jean@heimdall.local");
|
||||
cut.Markup.ShouldContain("Informations personnelles");
|
||||
cut.Markup.ShouldContain("Changer le mot de passe");
|
||||
cut.Markup.ShouldContain("Notifications");
|
||||
cut.Markup.ShouldContain("Activé"); // 2FA
|
||||
cut.Markup.ShouldContain("Oui"); // Email confirmé
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/users/me", System.Net.HttpStatusCode.InternalServerError);
|
||||
Handler.OnGet("api/notifications/config", NotifConfig());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement du profil."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_EnregistrerProfil_AfficheSucces()
|
||||
{
|
||||
SetupHappyPath();
|
||||
Handler.On(HttpMethod.Put, "api/users/me", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Informations personnelles"));
|
||||
|
||||
// Le premier input du formulaire profil est le nom d'affichage (Immediate=true)
|
||||
cut.FindAll("input")[0].Input("Jean Nouveau");
|
||||
cut.FindAll("form")[0].Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Profil mis à jour", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_EnregistrerProfil_NomVide_AfficheErreur()
|
||||
{
|
||||
SetupHappyPath();
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Informations personnelles"));
|
||||
|
||||
cut.FindAll("input")[0].Input("");
|
||||
cut.FindAll("form")[0].Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Le nom d'affichage est requis"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_ChangerMotDePasse_AfficheSucces()
|
||||
{
|
||||
SetupHappyPath();
|
||||
Handler.On(HttpMethod.Post, "api/auth/change-password", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Changer le mot de passe"));
|
||||
|
||||
cut.Find("input[autocomplete='current-password']").Input("ancien-motdepasse");
|
||||
cut.FindAll("input[autocomplete='new-password']")[0].Input("nouveau-motdepasse-123");
|
||||
cut.FindAll("input[autocomplete='new-password']")[1].Input("nouveau-motdepasse-123");
|
||||
cut.FindAll("form")[1].Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Mot de passe changé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_ChangerMotDePasse_TropCourt_AfficheErreur()
|
||||
{
|
||||
SetupHappyPath();
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Changer le mot de passe"));
|
||||
|
||||
cut.Find("input[autocomplete='current-password']").Input("ancien-motdepasse");
|
||||
cut.FindAll("input[autocomplete='new-password']")[0].Input("court");
|
||||
cut.FindAll("input[autocomplete='new-password']")[1].Input("court");
|
||||
cut.FindAll("form")[1].Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Le nouveau mot de passe doit contenir au moins 12 caractères"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_ChangerMotDePasse_NonCorrespondance_AfficheErreur()
|
||||
{
|
||||
SetupHappyPath();
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Changer le mot de passe"));
|
||||
|
||||
cut.Find("input[autocomplete='current-password']").Input("ancien-motdepasse");
|
||||
cut.FindAll("input[autocomplete='new-password']")[0].Input("nouveau-motdepasse-123");
|
||||
cut.FindAll("input[autocomplete='new-password']")[1].Input("autre-motdepasse-456");
|
||||
cut.FindAll("form")[1].Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Les mots de passe ne correspondent pas"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Profile_EnregistrerNotifications_AfficheSucces()
|
||||
{
|
||||
SetupHappyPath();
|
||||
Handler.On(HttpMethod.Put, "api/notifications/config", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<Profile>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Notifications"));
|
||||
|
||||
// Deux boutons "Enregistrer" : celui du profil (submit) puis celui des notifications
|
||||
cut.FindAll("button").Where(b => b.TextContent.Contains("Enregistrer")).ElementAt(1).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Configuration notifications mise à jour", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
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 SettingsPageTests : PageTestBase
|
||||
{
|
||||
private static readonly Guid SettingId = Guid.NewGuid();
|
||||
|
||||
private static AppSettingItem Setting(
|
||||
string key = "detection.threshold",
|
||||
string value = "0.8",
|
||||
string category = "Detection",
|
||||
string valueType = "number",
|
||||
string? description = "Seuil de détection") =>
|
||||
new(SettingId, key, value, description, category, valueType, null, DateTime.UtcNow.AddDays(-1));
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_AfficheParametresParCategorie()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem>
|
||||
{
|
||||
Setting(),
|
||||
Setting("heartbeat.interval", "30", "Heartbeat", "number", "Intervalle heartbeat")
|
||||
});
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("detection.threshold");
|
||||
cut.Markup.ShouldContain("0.8");
|
||||
cut.Markup.ShouldContain("heartbeat.interval");
|
||||
cut.Markup.ShouldContain("Detection");
|
||||
cut.Markup.ShouldContain("Heartbeat");
|
||||
cut.Markup.ShouldContain("paramètre(s) affiché(s)");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_AucunParametre_AfficheMessage()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem>());
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun paramètre configuré"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/settings", System.Net.HttpStatusCode.InternalServerError);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement de la configuration."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_CreerParametre_AfficheSucces()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting() });
|
||||
Handler.On(HttpMethod.Post, "api/settings", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("detection.threshold"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Nouveau")).Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Clé *"));
|
||||
|
||||
// Dialog create : [0]=clé, [1]=valeur (Immediate=true → Input)
|
||||
// Le champ recherche de la page décale les index globaux → cibler le dialog
|
||||
var dialogInputs = cut.FindAll(".mud-dialog input");
|
||||
dialogInputs[0].Input("recording.retention");
|
||||
dialogInputs[1].Input("7");
|
||||
cut.Find("form").Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Paramètre créé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_CreerParametre_ChampsManquants_AfficheErreur()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting() });
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("detection.threshold"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Nouveau")).Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Clé *"));
|
||||
cut.Find("form").Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Les champs Clé et Valeur sont requis"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_ModifierParametre_AfficheSucces()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("log.level", "info", "Logging", "string", "Niveau de log") });
|
||||
Handler.On(HttpMethod.Put, "api/settings/", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
// Icon-buttons : [0]=refresh (header), [1]=edit, [2]=delete
|
||||
cut.FindAll("button.mud-icon-button")[1].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
cut.FindAll(".mud-dialog input")[0].Input("debug");
|
||||
cut.Find("form").Submit();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Paramètre mis à jour", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_SupprimerParametre_ConfirmeEtSupprime()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("log.level", "info", "Logging", "string") });
|
||||
Handler.On(HttpMethod.Delete, "api/settings/", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[2].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Confirmer la suppression"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Supprimer").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Paramètre supprimé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsPage_RechargerConfig_AfficheSucces()
|
||||
{
|
||||
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting() });
|
||||
Handler.On(HttpMethod.Post, "api/settings/reload", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("detection.threshold"));
|
||||
|
||||
// Le refresh est le premier MudIconButton (header, avant la table)
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Configuration rechargée", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
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 UsersPageTests : PageTestBase
|
||||
{
|
||||
private static UserItem User(
|
||||
string name = "Alice Admin",
|
||||
string email = "alice@heimdall.local",
|
||||
IList<string>? roles = null,
|
||||
bool lockedOut = false) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Email = email,
|
||||
DisplayName = name,
|
||||
Theme = "Auto",
|
||||
Language = "fr",
|
||||
Roles = roles ?? ["Viewer"],
|
||||
TwoFactorEnabled = false,
|
||||
IsLockedOut = lockedOut,
|
||||
EmailConfirmed = true,
|
||||
CreatedAt = DateTime.UtcNow.AddDays(-10)
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_AfficheListeDesUtilisateurs()
|
||||
{
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>(
|
||||
[User("Alice Admin", "alice@heimdall.local", ["Admin", "Viewer"]),
|
||||
User("Bob Viewer", "bob@heimdall.local", ["Viewer"])], 2, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Alice Admin");
|
||||
cut.Markup.ShouldContain("alice@heimdall.local");
|
||||
cut.Markup.ShouldContain("Bob Viewer");
|
||||
cut.Markup.ShouldContain("Admin");
|
||||
cut.Markup.ShouldContain("Viewer");
|
||||
cut.Markup.ShouldContain("✓ Actif");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_AucunUtilisateur_AfficheMessage()
|
||||
{
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([], 0, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucun utilisateur"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_ErreurChargement_AfficheAlerte()
|
||||
{
|
||||
Handler.OnGet("api/users", System.Net.HttpStatusCode.InternalServerError);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Erreur lors du chargement des utilisateurs."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UsersPage_CreerUtilisateur_AfficheSucces()
|
||||
{
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([], 0, 1, 20));
|
||||
Handler.On(HttpMethod.Post, "api/users", User("Nouvel User", "nouveau@heimdall.local", ["Viewer"]));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Nouvel utilisateur"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Nouvel utilisateur")).Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Email *"));
|
||||
|
||||
cut.FindAll("input")[0].Input("nouveau@heimdall.local");
|
||||
cut.FindAll("input")[1].Input("Nouvel User");
|
||||
cut.FindAll("input")[2].Input("MotDePasse-123456");
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Créer").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Utilisateur créé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
|
||||
var post = Handler.Requests.Single(r => r.Method == HttpMethod.Post
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/users"));
|
||||
var body = await post.Content!.ReadAsStringAsync();
|
||||
body.ShouldContain("nouveau@heimdall.local");
|
||||
body.ShouldContain("Viewer");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_CreerUtilisateur_ChampsManquants_AfficheErreur()
|
||||
{
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([], 0, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Nouvel utilisateur"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Nouvel utilisateur")).Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Email *"));
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Créer").Click();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tous les champs sont requis"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_ModifierUtilisateur_MetAJourProfilEtRoles()
|
||||
{
|
||||
var user = User("Alice Admin", "alice@heimdall.local", ["Admin"]);
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([user], 1, 1, 20));
|
||||
Handler.On(HttpMethod.Put, "api/users/", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Admin"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Utilisateur : Alice Admin"));
|
||||
|
||||
cut.FindAll("input")[0].Input("Alice Renommée");
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Enregistrer").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Utilisateur mis à jour", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_ModifierUtilisateur_SansRole_AfficheErreur()
|
||||
{
|
||||
// User sans aucun rôle → tous les checkboxes rôles décochés au chargement du dialog
|
||||
var user = User("Alice SansRole", "alice@heimdall.local", []);
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([user], 1, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice SansRole"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Utilisateur : Alice SansRole"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Enregistrer").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
cut.Markup.ShouldContain("Au moins un rôle doit être sélectionné"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_ReinitialiserMotDePasse_AfficheMotDePasseTemporaire()
|
||||
{
|
||||
var user = User("Alice Admin", "alice@heimdall.local", ["Admin"]);
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([user], 1, 1, 20));
|
||||
Handler.On(HttpMethod.Post, "api/users/", new PasswordResetResult("Temp-12345"));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Admin"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Utilisateur : Alice Admin"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Réinitialiser le mot de passe")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
cut.Markup.ShouldContain("Nouveau mot de passe temporaire");
|
||||
cut.Markup.ShouldContain("Temp-12345");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_VerrouillerCompte_AfficheSucces()
|
||||
{
|
||||
var user = User("Alice Admin", "alice@heimdall.local", ["Admin"]);
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([user], 1, 1, 20));
|
||||
Handler.On(HttpMethod.Post, "api/users/", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Admin"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Verrouiller le compte"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Verrouiller le compte")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Compte verrouillé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_DeverrouillerCompte_AfficheSucces()
|
||||
{
|
||||
var user = User("Alice Admin", "alice@heimdall.local", ["Admin"], lockedOut: true);
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>([user], 1, 1, 20));
|
||||
Handler.On(HttpMethod.Post, "api/users/", System.Net.HttpStatusCode.OK);
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Admin"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Déverrouiller le compte"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Déverrouiller le compte")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Compte déverrouillé", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersPage_Pagination_Suivant_ChargePage2()
|
||||
{
|
||||
Handler.OnGet("api/users", new PagedData<UserItem>(
|
||||
Enumerable.Range(1, 20).Select(i => User($"User {i}")).ToArray(), 25, 1, 20));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<UsersPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Page 1 sur 2"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Suivant")).Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
Handler.Requests.Any(r => r.Method == HttpMethod.Get
|
||||
&& r.RequestUri!.PathAndQuery.Contains("api/users")
|
||||
&& r.RequestUri.Query.Contains("page=2")).ShouldBeTrue());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user