Files
Heimdall/tests/Heimdall.Web.Tests/Components/Pages/PersonDetailPageTests.cs
Arnaud Dartois 9bc5c1941c feat(ui): add PersonDetailPage (/persons/{id})
- Header with photo, name, category, watchlist badge, notes
- Face carousel (MudCarousel) with thumbnails
- Associated vehicles table
- 30-day FaceRecognized event history (client-filtered by name)
- Edit/Delete actions with PersonFormDialog
- 10 bUnit tests
2026-10-10 17:50:22 +02:00

267 lines
9.4 KiB
C#

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") =>
new(Guid.NewGuid(), CameraId, "FaceRecognized", 0.92, label,
"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");
cut.Markup.ShouldContain("Family");
cut.Markup.ShouldContain("Created");
cut.Markup.ShouldContain("Watchlisted");
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);
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));
LoginAs();
var cut = RenderPage<PersonDetailPage>(p => p.Add(x => x.Id, PersonId));
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Person not found"));
}
[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");
cut.Markup.ShouldContain("Registered faces");
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(() =>
cut.Markup.ShouldContain("No face registered"));
}
[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(() =>
{
cut.Markup.ShouldContain("Associated vehicles");
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(() =>
cut.Markup.ShouldContain("No vehicle associated"));
}
[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(() =>
{
cut.Markup.ShouldContain("Detection history");
// The table displays the label (person name)
cut.Markup.ShouldContain("Alice Dupont");
cut.Markup.ShouldContain("92%");
// The table includes an IconButton with aria-label="View snapshot" if snapshot exists
cut.Markup.ShouldContain("aria-label=\"View snapshot\"");
});
}
[Fact]
public void PersonDetail_HistoriqueFiltreParNom()
{
Handler.OnGet($"api/persons/{PersonId}/faces", new List<KnownFaceClientItem>());
Handler.OnGet("api/vehicles", new List<VehicleClientItem>());
Handler.OnGet("api/events",
new EventPageResult([Ev("Alice Dupont"), Ev("Bob Martin")], 2, 1, 50));
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");
});
}
[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"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Delete")).Click();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Confirm deletion"));
// The confirm dialog's Delete button is inside the dialog actions.
await cut.InvokeAsync(() => cut.FindAll("div.mud-dialog-actions button")
.Single(b => b.TextContent.Trim() == "Delete").Click());
cut.WaitForAssertion(() =>
{
var snackbar = Services.GetRequiredService<ISnackbar>();
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
.ShouldContain(m => m.Contains("deleted", StringComparison.OrdinalIgnoreCase));
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"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Edit")).Click();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Edit Person"));
cut.FindAll("input")[0].Input("Alice Renommee");
await cut.InvokeAsync(() => cut.FindAll("div.mud-dialog-actions button")
.Single(b => b.TextContent.Trim() == "Save").Click());
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() ?? "")
.ShouldContain(m => m.Contains("updated", StringComparison.OrdinalIgnoreCase));
});
}
}