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
This commit is contained in:
1 parent
3ef23aabab
commit
9bc5c1941c
2 files changed
+653
No files matched your search
@@ -0,0 +1,386 @@
|
||||
@page "/persons/{Id:guid}"
|
||||
@attribute [Authorize]
|
||||
@layout MainLayout
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Nav
|
||||
@using Heimdall.Web.Components.Shared
|
||||
@using Heimdall.Web.Services
|
||||
|
||||
@if (_loading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_person is null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning">Person not found</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex justify-space-between align-center mb-6">
|
||||
<div class="d-flex align-center gap-4">
|
||||
@if (!string.IsNullOrEmpty(_person.PhotoUrl))
|
||||
{
|
||||
<img src="@_person.PhotoUrl" alt="@_person.DisplayName"
|
||||
style="width:80px; height:80px; border-radius:50%; object-fit:cover;" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="width:80px; height:80px; border-radius:50%; background: var(--mud-palette-primary);
|
||||
display:flex; align-items:center; justify-content:center;">
|
||||
<i class="fas fa-user" style="font-size:2rem; color:white;"></i>
|
||||
</div>
|
||||
}
|
||||
<div>
|
||||
<MudText Typo="Typo.h1" Class="mb-1">@_person.DisplayName</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
||||
@FormatCategory(_person.Category) · Created @_person.CreatedAt.ToString("d")
|
||||
</MudText>
|
||||
@if (_person.IsWatchlisted)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Warning"
|
||||
Icon="@Icons.Material.Filled.Warning" Class="mt-2">
|
||||
Watchlisted
|
||||
</MudChip>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => _showForm = true)">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Edit" Class="mr-1" /> Edit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@ConfirmDelete">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Delete" Class="mr-1" /> Delete
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_person.Notes))
|
||||
{
|
||||
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">Notes</MudText>
|
||||
<MudText Typo="Typo.body1">@_person.Notes</MudText>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
<MudGrid>
|
||||
@* ─── Faces ─── *@
|
||||
<MudItem xs="12" md="6">
|
||||
<MudPaper Elevation="2" Class="pa-6" Style="border-radius: 12px; height: 100%;">
|
||||
<div class="d-flex justify-space-between align-center mb-4">
|
||||
<MudText Typo="Typo.h6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Portrait" Class="mr-1" />
|
||||
Registered faces (@_faces.Count)
|
||||
</MudText>
|
||||
</div>
|
||||
|
||||
@if (_facesLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_faces.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
No face registered. Add a face to improve recognition.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudCarousel TData="KnownFaceClientItem" @bind-SelectedIndex="_faceIndex">
|
||||
@foreach (var face in _faces)
|
||||
{
|
||||
<MudCarouselItem>
|
||||
<div class="d-flex flex-column align-center gap-2" style="padding: 16px;">
|
||||
@if (!string.IsNullOrEmpty(face.ThumbnailUrl))
|
||||
{
|
||||
<img src="@face.ThumbnailUrl" alt="Face"
|
||||
style="width: 200px; height: 200px; border-radius: 50%; object-fit:cover;
|
||||
border: 4px solid var(--mud-palette-primary);" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="width: 200px; height: 200px; border-radius: 50%;
|
||||
background: var(--mud-palette-grey-800);
|
||||
display:flex; align-items:center; justify-content:center;">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Portrait" Size="Size.Large" Color="Color.Secondary" />
|
||||
</div>
|
||||
}
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
||||
@if (!string.IsNullOrEmpty(face.SourceEventId))
|
||||
{
|
||||
<text>Event: @face.SourceEventId.Substring(0, Math.Min(8, face.SourceEventId.Length))…</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>Face #@face.Id.ToString()[..8]</text>
|
||||
}
|
||||
</MudText>
|
||||
</div>
|
||||
</MudCarouselItem>
|
||||
}
|
||||
</MudCarousel>
|
||||
<div class="d-flex justify-center gap-2 mt-4">
|
||||
@for (int i = 0; i < _faces.Count; i++)
|
||||
{
|
||||
var idx = i;
|
||||
<MudButton Size="Size.Small" Variant="@(i == _faceIndex ? Variant.Filled : Variant.Outlined)"
|
||||
Color="Color.Primary" OnClick="@(() => _faceIndex = idx)"
|
||||
Style="min-width: 32px; height: 32px; padding: 0; border-radius: 50%;">
|
||||
@(i + 1)
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
@* ─── Vehicles ─── *@
|
||||
<MudItem xs="12" md="6">
|
||||
<MudPaper Elevation="2" Class="pa-6" Style="border-radius: 12px; height: 100%;">
|
||||
<MudText Typo="Typo.h6" Class="mb-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.ElectricCar" Class="mr-1" />
|
||||
Associated vehicles (@_vehicles.Count)
|
||||
</MudText>
|
||||
|
||||
@if (_vehiclesLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_vehicles.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
No vehicle associated with this person.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_vehicles" Dense="true" Hover="true">
|
||||
<HeaderContent>
|
||||
<MudTh>Plate</MudTh>
|
||||
<MudTh>Make</MudTh>
|
||||
<MudTh>Model</MudTh>
|
||||
<MudTh>Color</MudTh>
|
||||
<MudTh>Events</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Plate"><code>@context.LicensePlate</code></MudTd>
|
||||
<MudTd DataLabel="Make">@context.Make</MudTd>
|
||||
<MudTd DataLabel="Model">@context.Model</MudTd>
|
||||
<MudTd DataLabel="Color">@context.Color</MudTd>
|
||||
<MudTd DataLabel="Events">@context.EventCount</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@* ─── Event history (30 days) ─── *@
|
||||
<MudPaper Elevation="2" Class="pa-6 mt-6" Style="border-radius: 12px;">
|
||||
<MudText Typo="Typo.h6" Class="mb-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.History" Class="mr-1" />
|
||||
Detection history (last 30 days)
|
||||
</MudText>
|
||||
|
||||
@if (_eventsLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_events.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
No face detection for the last 30 days.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_events" Dense="true" Hover="true">
|
||||
<HeaderContent>
|
||||
<MudTh>Date</MudTh>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh>Camera</MudTh>
|
||||
<MudTh>Confidence</MudTh>
|
||||
<MudTh>Snapshot</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Date">@context.OccurredAt.ToLocalTime().ToString("dd/MM HH:mm")</MudTd>
|
||||
<MudTd DataLabel="Type">
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">
|
||||
Face
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Camera">@context.Label</MudTd>
|
||||
<MudTd DataLabel="Confidence">@((context.Confidence * 100).ToString("0"))%</MudTd>
|
||||
<MudTd DataLabel="Snapshot">
|
||||
@if (!string.IsNullOrEmpty(context.SnapshotUrl))
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small"
|
||||
aria-label="View snapshot" OnClick="@(() => ShowSnapshot(context))" />
|
||||
}
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Default" Class="mt-4"
|
||||
OnClick="@(() => Nav.NavigateTo("/persons"))">
|
||||
← Back to persons
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
@* ─── Edit form ─── *@
|
||||
<PersonFormDialog @bind-Visible="_showForm" Existing="_person" OnSaved="@OnPersonUpdated" />
|
||||
|
||||
@* ─── Confirm delete ─── *@
|
||||
<MudOverlay Visible="_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
||||
<MudDialog @bind-Visible="_confirmDeleteShow">
|
||||
<TitleContent><MudText Typo="Typo.h6">Confirm deletion</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudText>Delete the person "@_person?.DisplayName" ?</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
|
||||
This action is irreversible. The @(_person?.FaceCount) registered face(s) will also be deleted.
|
||||
</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">Cancel</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDelete">Delete</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@* ─── Snapshot dialog ─── *@
|
||||
<MudDialog @bind-Visible="_showSnapshot" Options="_dialogOptions">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Snapshot — @_showSnapshotEvent?.Label</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<img src="@_showSnapshotEvent?.SnapshotUrl" alt="Snapshot" style="width:100%" class="rounded-lg" />
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _showSnapshot = false)">Close</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid Id { get; set; }
|
||||
|
||||
private PersonClientItem? _person;
|
||||
private List<KnownFaceClientItem> _faces = [];
|
||||
private List<VehicleClientItem> _vehicles = [];
|
||||
private List<EventItem> _events = [];
|
||||
|
||||
private bool _loading = true;
|
||||
private bool _facesLoading = true;
|
||||
private bool _vehiclesLoading = true;
|
||||
private bool _eventsLoading = true;
|
||||
|
||||
private bool _showForm;
|
||||
private bool _confirmDeleteShow;
|
||||
private bool _showSnapshot;
|
||||
private int _faceIndex;
|
||||
private EventItem? _showSnapshotEvent;
|
||||
|
||||
private readonly DialogOptions _dialogOptions = new()
|
||||
{
|
||||
FullWidth = true,
|
||||
MaxWidth = MaxWidth.Large,
|
||||
CloseButton = true
|
||||
};
|
||||
|
||||
private DateTime _eventsSince => DateTime.UtcNow.AddDays(-30);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_person = await Api.GetPersonAsync(Id);
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
finally { _loading = false; }
|
||||
|
||||
await LoadFaces();
|
||||
await LoadVehicles();
|
||||
await LoadEvents();
|
||||
}
|
||||
|
||||
private async Task LoadFaces()
|
||||
{
|
||||
_facesLoading = true;
|
||||
try
|
||||
{
|
||||
_faces = (await Api.GetFacesAsync(Id)) ?? [];
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
finally { _facesLoading = false; }
|
||||
}
|
||||
|
||||
private async Task LoadVehicles()
|
||||
{
|
||||
_vehiclesLoading = true;
|
||||
try
|
||||
{
|
||||
var all = await Api.GetVehiclesAsync();
|
||||
_vehicles = (all?.Where(v => v.PersonId == Id).ToList()) ?? [];
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
finally { _vehiclesLoading = false; }
|
||||
}
|
||||
|
||||
private async Task LoadEvents()
|
||||
{
|
||||
_eventsLoading = true;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetEventsAsync(null, null, page: 1, pageSize: 50,
|
||||
type: "FaceRecognized", from: _eventsSince);
|
||||
var all = result?.Items ?? [];
|
||||
var name = _person?.DisplayName;
|
||||
_events = string.IsNullOrEmpty(name)
|
||||
? all
|
||||
: all.Where(e => e.Label?.Contains(name, StringComparison.OrdinalIgnoreCase) == true).ToList();
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
finally { _eventsLoading = false; }
|
||||
}
|
||||
|
||||
private async Task OnPersonUpdated(PersonClientItem person)
|
||||
{
|
||||
_person = person;
|
||||
await LoadFaces();
|
||||
}
|
||||
|
||||
private void ConfirmDelete() => _confirmDeleteShow = true;
|
||||
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
_confirmDeleteShow = false;
|
||||
try
|
||||
{
|
||||
if (await Api.DeletePersonAsync(Id))
|
||||
{
|
||||
Snackbar.Add($"Person \"{_person?.DisplayName}\" deleted", Severity.Success);
|
||||
Nav.NavigateTo("/persons");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Failed to delete person", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
}
|
||||
|
||||
private void ShowSnapshot(EventItem ev)
|
||||
{
|
||||
_showSnapshotEvent = ev;
|
||||
_showSnapshot = true;
|
||||
}
|
||||
|
||||
private static string FormatCategory(string? category) => category switch
|
||||
{
|
||||
"family" => "Family",
|
||||
"employee" => "Employee",
|
||||
"watchlist" => "Watchlist",
|
||||
"unknown" => "Unknown",
|
||||
_ => "—"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user