- UiErrors : messages métier centralisés (LoadFailed/SaveFailed/DeleteFailed/ OperationFailed) — plus aucun ex.Message brut dans l'UI (48 remplacés sur 19 pages), les détails techniques restent dans les logs. - UiFormat : formatage centralisé des statuts (Online → En ligne, Offline → Hors ligne, Disabled → Désactivée…) et types d'événements ; appliqué aux pages Agents (liste + détail) qui affichaient encore les valeurs brutes. - catch (Exception ex) devenus inutiles → catch simple (46 nettoyés). - Boutons = verbes, validation métier déjà en place (Le nom est requis…) couverte par les tests existants. - Tests : adaptés au message métier (Register) et au statut traduit (Agents). 182 tests Web verts.
81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using Bunit;
|
|
using Bunit.TestDoubles;
|
|
using Heimdall.Web.Components.Pages;
|
|
using Heimdall.Web.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Web.Tests.Components.Pages;
|
|
|
|
public class RegisterTests : PageTestBase
|
|
{
|
|
private static AuthResponse SuccessResponse() => new(
|
|
"access-token", "refresh-token", DateTime.UtcNow.AddHours(1), false,
|
|
new UserInfo(Guid.NewGuid(), "user@heimdall.local", "Nouvel Utilisateur", ["Viewer"]));
|
|
|
|
private BunitNavigationManager Navigate()
|
|
=> Services.GetRequiredService<BunitNavigationManager>();
|
|
|
|
[Fact]
|
|
public void RegisterPage_AfficheFormulaire()
|
|
{
|
|
var cut = RenderPage<Register>();
|
|
|
|
cut.Markup.ShouldContain("Créer un compte");
|
|
cut.Markup.ShouldContain("Nom d'affichage");
|
|
cut.Markup.ShouldContain("Email");
|
|
cut.Markup.ShouldContain("Mot de passe");
|
|
cut.Markup.ShouldContain("S'inscrire");
|
|
cut.FindAll("input").Count.ShouldBe(3);
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterPage_EchecInscription_AfficheErreur()
|
|
{
|
|
Handler.On(HttpMethod.Post, "api/auth/register", System.Net.HttpStatusCode.BadRequest);
|
|
var cut = RenderPage<Register>();
|
|
|
|
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
|
cut.FindAll("input")[1].Input("user@heimdall.local");
|
|
cut.FindAll("input")[2].Input("motdepasse-securise");
|
|
cut.Find("form").Submit();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
cut.Markup.ShouldContain("Erreur lors de l'inscription"));
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterPage_Succes_NavigueVersDashboard()
|
|
{
|
|
Handler.On(HttpMethod.Post, "api/auth/register", SuccessResponse());
|
|
JSInterop.Setup<bool>("heimdallAuth.signIn", _ => true).SetResult(true);
|
|
|
|
var nav = Navigate();
|
|
var cut = RenderPage<Register>();
|
|
|
|
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
|
cut.FindAll("input")[1].Input("user@heimdall.local");
|
|
cut.FindAll("input")[2].Input("motdepasse-securise");
|
|
cut.Find("form").Submit();
|
|
|
|
cut.WaitForAssertion(() => nav.Uri.ShouldBe("http://localhost/dashboard"));
|
|
AuthProvider.Received(1).NotifyLoginAsync(Arg.Any<AuthResponse>());
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterPage_Exception_AfficheErreur()
|
|
{
|
|
Handler.On(HttpMethod.Post, "api/auth/register",
|
|
() => throw new InvalidOperationException("boom"));
|
|
var cut = RenderPage<Register>();
|
|
|
|
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
|
cut.FindAll("input")[1].Input("user@heimdall.local");
|
|
cut.FindAll("input")[2].Input("motdepasse-securise");
|
|
cut.Find("form").Submit();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Erreur lors de l'opération"));
|
|
}
|
|
}
|