2026-10-10 17:50:22 +02:00
|
|
|
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 PersonDetailPageTests : PageTestBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly Guid PersonId = Guid.NewGuid();
|
|
|
|
|
private static readonly Guid CameraId = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
private static PersonClientItem Person() => new()
|
|
|
|
|
{
|
|
|
|
|
Id = PersonId,
|
|
|
|
|
DisplayName = "Alice Dupont",
|
|
|
|
|
Category = "family",
|
|
|
|
|
IsWatchlisted = true,
|
|
|
|
|
Notes = "Member of the family",
|
|
|
|
|
FaceCount = 2,
|
|
|
|
|
CreatedAt = DateTime.UtcNow.AddMonths(-1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static KnownFaceClientItem Face() => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
PersonId = PersonId,
|
|
|
|
|
ThumbnailUrl = "https://example.com/face1.jpg",
|
|
|
|
|
SourceEventId = "evt-12345678"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static VehicleClientItem Vehicle() => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
LicensePlate = "AB-123-CD",
|
|
|
|
|
Make = "Toyota",
|
|
|
|
|
Model = "Prius",
|
|
|
|
|
Color = "Black",
|
|
|
|
|
PersonId = PersonId,
|
|
|
|
|
EventCount = 5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static EventItem Ev(string label = "Alice Dupont") =>
|
2026-10-22 20:56:49 +02:00
|
|
|
new(Guid.NewGuid(), CameraId, PersonId, "FaceRecognized", 0.92, label,
|
2026-10-10 17:50:22 +02:00
|
|
|
"https://example.com/snap.jpg", null,
|
|
|
|
|
DateTime.UtcNow.AddHours(-2), DateTime.UtcNow.AddHours(-2));
|
|
|
|
|
|
|
|
|
|
private void HandlerBase()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
|
|
|
|
|
Handler.OnGet("api/persons/", Person());
|
|
|
|
|
LoginAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AfficheInformationsEtStatut()
|
|
|
|
|
{
|
|
|
|
|
HandlerBase();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Alice Dupont");
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("Famille");
|
|
|
|
|
cut.Markup.ShouldContain("Créée le");
|
|
|
|
|
cut.Markup.ShouldContain("Surveillée");
|
2026-10-10 17:50:22 +02:00
|
|
|
cut.Markup.ShouldContain("Member of the family");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_NotesMasqueesQuandAbsent()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
|
|
|
|
|
var noNotes = Person();
|
|
|
|
|
noNotes.Notes = null;
|
|
|
|
|
Handler.OnGet("api/persons/", noNotes);
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Alice Dupont");
|
|
|
|
|
cut.Markup.ShouldNotContain("Member of the family");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_PersonneIntrouvable_AfficheAlerte()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/persons/", System.Net.HttpStatusCode.NotFound);
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
2026-11-08 13:02:38 +01:00
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Personne introuvable");
|
|
|
|
|
Services.GetRequiredService<ISnackbar>().ShownSnackbars.ShouldBeEmpty();
|
|
|
|
|
Handler.Requests.ShouldHaveSingleItem();
|
|
|
|
|
});
|
2026-10-10 17:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AfficheVisagesCarousel()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem> { Face() });
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
|
|
|
|
|
Handler.OnGet("api/persons/", Person());
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("https://example.com/face1.jpg");
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("visage(s) enregistré(s)");
|
2026-10-10 17:50:22 +02:00
|
|
|
cut.Markup.ShouldContain("evt-1234");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AucunVisage_AfficheMessage()
|
|
|
|
|
{
|
|
|
|
|
HandlerBase();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("Aucun visage enregistré"));
|
2026-10-10 17:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AfficheVehiculesAssocies()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem> { Vehicle() });
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
|
|
|
|
|
Handler.OnGet("api/persons/", Person());
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
2026-10-25 06:19:40 +01:00
|
|
|
cut.Markup.ShouldContain("véhicule(s) associé(s)");
|
2026-10-10 17:50:22 +02:00
|
|
|
cut.Markup.ShouldContain("<code>AB-123-CD</code>");
|
|
|
|
|
cut.Markup.ShouldContain("Toyota");
|
|
|
|
|
cut.Markup.ShouldContain("Prius");
|
|
|
|
|
cut.Markup.ShouldContain("Black");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AucunVehicule_AfficheMessage()
|
|
|
|
|
{
|
|
|
|
|
HandlerBase();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("Aucun véhicule associé à cette personne."));
|
2026-10-10 17:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PersonDetail_AfficheHistoriqueEvenements()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
|
|
|
|
|
Handler.OnGet("api/events", new EventPageResult([Ev()], 1, 1, 50));
|
|
|
|
|
Handler.OnGet("api/persons/", Person());
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("Historique de détection");
|
2026-10-10 17:50:22 +02:00
|
|
|
// The table displays the label (person name)
|
|
|
|
|
cut.Markup.ShouldContain("Alice Dupont");
|
2026-10-25 06:35:00 +01:00
|
|
|
cut.Markup.ShouldContain("92");
|
2026-10-25 06:41:02 +01:00
|
|
|
// The table includes a localized snapshot button when a snapshot exists.
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("aria-label=\"Voir la capture\"");
|
2026-10-10 17:50:22 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-10-23 18:58:06 +02:00
|
|
|
public void PersonDetail_HistoriqueFiltreParPersonId()
|
2026-10-10 17:50:22 +02:00
|
|
|
{
|
|
|
|
|
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
|
|
|
|
|
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
|
2026-10-23 18:58:06 +02:00
|
|
|
Handler.OnGet("api/events", new EventPageResult([Ev("Alice Dupont")], 1, 1, 50));
|
2026-10-10 17:50:22 +02:00
|
|
|
Handler.OnGet("api/persons/", Person());
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
cut.Markup.ShouldContain("Alice Dupont");
|
|
|
|
|
cut.Markup.ShouldNotContain("Bob Martin");
|
2026-10-23 18:58:06 +02:00
|
|
|
Handler.Requests.ShouldContain(r => r.RequestUri!.PathAndQuery.Contains($"personId={PersonId}", StringComparison.OrdinalIgnoreCase));
|
2026-10-10 17:50:22 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task PersonDetail_SupprimerPersonne_ConfirmeEtSupprime()
|
|
|
|
|
{
|
|
|
|
|
HandlerBase();
|
|
|
|
|
Handler.On(HttpMethod.Delete, "api/persons/", System.Net.HttpStatusCode.OK);
|
|
|
|
|
|
|
|
|
|
var nav = Services.GetRequiredService<BunitNavigationManager>();
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Dupont"));
|
|
|
|
|
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Supprimer")).Click();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Confirmer la suppression"));
|
2026-10-10 17:50:22 +02:00
|
|
|
|
|
|
|
|
// The confirm dialog's Delete button is inside the dialog actions.
|
|
|
|
|
await cut.InvokeAsync(() => cut.FindAll("div.mud-dialog-actions button")
|
2026-10-25 06:17:43 +01:00
|
|
|
.Single(b => b.TextContent.Trim() == "Supprimer").Click());
|
2026-10-10 17:50:22 +02:00
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
|
|
|
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
2026-10-25 06:17:43 +01:00
|
|
|
.ShouldContain(m => m.Contains("supprimée", StringComparison.OrdinalIgnoreCase));
|
2026-10-10 17:50:22 +02:00
|
|
|
nav.Uri.ShouldBe("http://localhost/persons");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task PersonDetail_ModifierPersonne_AppellePut()
|
|
|
|
|
{
|
|
|
|
|
HandlerBase();
|
|
|
|
|
Handler.On(HttpMethod.Put, "api/persons/", System.Net.HttpStatusCode.OK);
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Alice Dupont"));
|
|
|
|
|
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Modifier")).Click();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Modifier la personne"));
|
2026-10-10 17:50:22 +02:00
|
|
|
|
|
|
|
|
cut.FindAll("input")[0].Input("Alice Renommee");
|
|
|
|
|
await cut.InvokeAsync(() => cut.FindAll("div.mud-dialog-actions button")
|
2026-10-25 06:17:43 +01:00
|
|
|
.Single(b => b.TextContent.Trim() == "Enregistrer").Click());
|
2026-10-10 17:50:22 +02:00
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
Handler.Requests.Count(r => r.Method == HttpMethod.Put
|
|
|
|
|
&& r.RequestUri!.PathAndQuery.Contains("api/persons")).ShouldBe(1);
|
|
|
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
|
|
|
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
2026-10-25 06:17:43 +01:00
|
|
|
.ShouldContain(m => m.Contains("mise à jour", StringComparison.OrdinalIgnoreCase));
|
2026-10-10 17:50:22 +02:00
|
|
|
});
|
|
|
|
|
}
|
2026-10-22 20:56:49 +02:00
|
|
|
}
|