Heimdall Gitea / Build and tests (pull_request) Failing after 11m41s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
194 lines
6.8 KiB
C#
194 lines
6.8 KiB
C#
using Bunit;
|
|
using Heimdall.Web.Components.Pages;
|
|
using Heimdall.Web.Components.Shared;
|
|
using Heimdall.Web.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MudBlazor;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Web.Tests.Components.Pages;
|
|
|
|
public class PersonsListPageTests : PageTestBase
|
|
{
|
|
private static readonly Guid PersonId = Guid.NewGuid();
|
|
|
|
private static PersonClientItem Person(string name = "Alice", string category = "family", int faces = 2) =>
|
|
new()
|
|
{
|
|
Id = PersonId,
|
|
DisplayName = name,
|
|
Category = category,
|
|
IsWatchlisted = false,
|
|
FaceCount = faces,
|
|
CreatedAt = DateTime.UtcNow.AddMonths(-1)
|
|
};
|
|
|
|
private static PersonClientItem UnknownPerson() =>
|
|
new()
|
|
{
|
|
Id = Guid.Parse("11111111-1111-1111-1111-111111111111"),
|
|
DisplayName = "Unknown #1",
|
|
Category = "unknown",
|
|
IsWatchlisted = false,
|
|
FaceCount = 1,
|
|
CreatedAt = DateTime.UtcNow.AddMonths(-1)
|
|
};
|
|
|
|
[Fact]
|
|
public void PersonsListPage_AfficheListeDesPersonnes()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem> { Person(), Person("Bob", "employee", 1) });
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Alice");
|
|
cut.Markup.ShouldContain("Bob");
|
|
cut.Markup.ShouldContain("Famille");
|
|
cut.Markup.ShouldContain("Employé");
|
|
cut.Markup.ShouldContain("2 visage(s)");
|
|
cut.Markup.ShouldContain("1 visage(s)");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_AucunePersonne_AfficheMessage()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem>());
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Aucune personne enregistrée");
|
|
cut.Markup.ShouldContain("Ajouter une personne");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_ErreurChargement_AfficheAlerte()
|
|
{
|
|
Handler.OnGet("api/persons", System.Net.HttpStatusCode.InternalServerError);
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
cut.Markup.ShouldContain("Impossible de charger les personnes."));
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_FiltreConnu_TransmetCategorieALApi()
|
|
{
|
|
// MudSelect interaction is fragile in bUnit (popover) — test the
|
|
// client API directly: GetPersonsAsync(category) must send the
|
|
// category query parameter (same approach as EventsPageTests).
|
|
Handler.OnGet("api/persons", new List<PersonClientItem>());
|
|
LoginAs();
|
|
|
|
var api = Services.GetRequiredService<HeimdallApiClient>();
|
|
_ = api.GetPersonsAsync("family");
|
|
|
|
Handler.Requests.ShouldContain(r => r.Method == HttpMethod.Get
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/persons")
|
|
&& r.RequestUri.Query.Contains("category=family", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_FiltreInconnu_TransmetCategorieALApi()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem>());
|
|
LoginAs();
|
|
|
|
var api = Services.GetRequiredService<HeimdallApiClient>();
|
|
_ = api.GetPersonsAsync("unknown");
|
|
|
|
Handler.Requests.ShouldContain(r => r.Method == HttpMethod.Get
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/persons")
|
|
&& r.RequestUri.Query.Contains("category=unknown", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_RechercheParNom_Filtre()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem> { Person("Alice"), Person("Bob") });
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice"));
|
|
|
|
cut.FindAll("input")[0].Input("Bob");
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Bob");
|
|
cut.Markup.ShouldNotContain("Alice");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_RechercheAucunResultat()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem> { Person("Alice") });
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice"));
|
|
|
|
cut.FindAll("input")[0].Input("zzz");
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Aucune personne ne correspond aux filtres"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PersonsListPage_CreationPersonne_Reussi()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem>());
|
|
Handler.On(HttpMethod.Post, "api/persons",
|
|
() => RoutedHandler.JsonResponse(System.Net.HttpStatusCode.OK,
|
|
new PersonClientItem { Id = PersonId, DisplayName = "New Person", Category = "family" }));
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Ajouter une personne"));
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Ajouter une personne")).Click();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Nom *"));
|
|
|
|
// The dialog content renders in the host markup (MudDialogProvider),
|
|
// so interact via the host's elements directly.
|
|
cut.FindAll("input")[0].Input("New Person");
|
|
await cut.InvokeAsync(() => cut.FindAll("button").Single(b => b.TextContent.Trim() == "Créer").Click());
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.Count(r => r.Method == HttpMethod.Post
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/persons")).ShouldBe(1);
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "").ShouldContain("Personne créée");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void PersonsListPage_CreationPersonne_SansNom_Erreur()
|
|
{
|
|
Handler.OnGet("api/persons", new List<PersonClientItem>());
|
|
LoginAs();
|
|
|
|
var cut = RenderPage<PersonsListPage>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Ajouter une personne"));
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Ajouter une personne")).Click();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Nom *"));
|
|
|
|
// Find+Click in InvokeAsync: a direct Click may use a stale
|
|
// event handler reference after the dialog re-rendered.
|
|
cut.InvokeAsync(() => cut.FindAll("button").Single(b => b.TextContent.Trim() == "Créer").Click());
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Le nom est obligatoire"));
|
|
}
|
|
}
|