Après .Input()/.Change() (MudTextField Immediate), le dialog re-rend de manière asynchrone : un FindAll() puis .Click()/.Submit() hors InvokeAsync peut référencer un event handler périmé → bUnit UnknownEventHandlerIdException en CI (flaky, non reproductible en local). Workaround officiel bUnit : wrapper le Find+action dans cut.InvokeAsync(...). Appliqué à tous les patterns Input/Change → Click/Submit des tests de pages (Sites, Cameras, Groups, Users, Settings, Snapshots, Register, Profile, AuditLogs, Login, SiteDetail, Discoveries).
81 lines
2.9 KiB
C#
81 lines
2.9 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 async Task 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");
|
|
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
|
|
|
cut.WaitForAssertion(() =>
|
|
cut.Markup.ShouldContain("Erreur lors de l'inscription"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task 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");
|
|
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
|
|
|
cut.WaitForAssertion(() => nav.Uri.ShouldBe("http://localhost/dashboard"));
|
|
await AuthProvider.Received(1).NotifyLoginAsync(Arg.Any<AuthResponse>());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task 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");
|
|
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Erreur lors de l'opération"));
|
|
}
|
|
}
|