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).
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 : boom"));
|
|
}
|
|
}
|