fix(web): lightbox snapshots — MudDialog hors @if, Fermer opérant (#117)
This commit is contained in:
1 parent
1f954e67ba
commit
de291b7674
2 files changed
+77
-24
No files matched your search
@@ -55,30 +55,32 @@ else
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (_lightboxEvent is not null)
|
||||
{
|
||||
<MudDialog @bind-Visible="_showLightbox" Options="_lightboxOptions">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
@FormatEventType(_lightboxEvent.Type) · @_lightboxEvent.OccurredAt.ToLocalTime().ToString("g")
|
||||
<MudLink Href="@($"/cameras/{_lightboxEvent.CameraId}")" Typo="Typo.caption" Class="ml-4">Voir la caméra</MudLink>
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<img src="@_lightboxEvent.SnapshotUrl" alt="Snapshot" style="width:100%;height:auto;" class="rounded-lg" />
|
||||
@if (!string.IsNullOrEmpty(_lightboxEvent.Label))
|
||||
{
|
||||
<MudText Color="Color.Primary" Typo="Typo.body2" Class="mt-2">@_lightboxEvent.Label</MudText>
|
||||
}
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
|
||||
Confiance : @_lightboxEvent.Confidence.ToString("P0") · ID : @_lightboxEvent.Id.ToString()[..8]
|
||||
</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => _showLightbox = false)">Fermer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
@* Lightbox toujours rendu : la visibilité est pilotée uniquement par @bind-Visible.
|
||||
Le pattern @if (_lightboxEvent is not null) { <MudDialog ...> } détruisait le composant
|
||||
au lieu de le cacher → dialog orphelin, bouton Fermer inopérant (issue #94).
|
||||
Le contenu n'est rendu que quand le dialog est visible (OpenLightbox définit
|
||||
_lightboxEvent avant de passer _showLightbox à true) — accès via `!`. *@
|
||||
<MudDialog @bind-Visible="_showLightbox" Options="_lightboxOptions">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
@FormatEventType(_lightboxEvent!.Type) · @_lightboxEvent!.OccurredAt.ToLocalTime().ToString("g")
|
||||
<MudLink Href="@($"/cameras/{_lightboxEvent!.CameraId}")" Typo="Typo.caption" Class="ml-4">Voir la caméra</MudLink>
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<img src="@_lightboxEvent!.SnapshotUrl" alt="Snapshot" style="width:100%;height:auto;" class="rounded-lg" />
|
||||
@if (!string.IsNullOrEmpty(_lightboxEvent!.Label))
|
||||
{
|
||||
<MudText Color="Color.Primary" Typo="Typo.body2" Class="mt-2">@_lightboxEvent!.Label</MudText>
|
||||
}
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
|
||||
Confiance : @_lightboxEvent!.Confidence.ToString("P0") · ID : @_lightboxEvent!.Id.ToString()[..8]
|
||||
</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => _showLightbox = false)">Fermer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
|
||||
@@ -95,4 +95,55 @@ public class SnapshotsPageTests : PageTestBase
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Voir la caméra"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SnapshotsPage_FermerLightbox_LeDialogSeFerme()
|
||||
{
|
||||
// Régression issue #94 : le MudDialog était enveloppé dans un @if →
|
||||
// Visible=false détruisait le composant au lieu de le cacher, le dialog
|
||||
// restait orphelin et le bouton Fermer ne répondait plus.
|
||||
Handler.OnGet("api/events", new EventPageResult(
|
||||
[SnapshotEvent("PersonDetected", 0.87, "Personne", "/snapshots/1.jpg")], 1, 1, 100));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SnapshotsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Personne · 87%"));
|
||||
|
||||
// Ouvrir la lightbox.
|
||||
cut.FindAll("div[role=button]")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Voir la caméra"));
|
||||
|
||||
// Cliquer Fermer → le dialog disparaît du markup (le composant reste
|
||||
// rendu mais Visible=false, le MudDialogProvider ne l'affiche plus).
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Fermer")).Click();
|
||||
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldNotContain("Voir la caméra"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SnapshotsPage_LeDialogResteRenduApresFermeture()
|
||||
{
|
||||
// Cœur de la régression issue #94 : le MudDialog ne doit jamais être
|
||||
// détruit par un @if — il reste rendu, Visible piloté par @bind-Visible.
|
||||
// Avec l'ancien pattern, FindComponents<MudDialog>() retournait 0 hors
|
||||
// ouverture (le @if (_lightboxEvent is not null) détruisait le composant).
|
||||
Handler.OnGet("api/events", new EventPageResult(
|
||||
[SnapshotEvent("PersonDetected", 0.87, "Personne", "/snapshots/1.jpg")], 1, 1, 100));
|
||||
LoginAs();
|
||||
|
||||
var cut = RenderPage<SnapshotsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Personne · 87%"));
|
||||
|
||||
// Dialog présent dans l'arbre dès le rendu initial, alors que le
|
||||
// lightbox est fermé (Visible=false).
|
||||
cut.FindComponents<MudDialog>().Count.ShouldBe(1);
|
||||
|
||||
// Ouvrir puis fermer : le composant MudDialog reste dans l'arbre.
|
||||
cut.FindAll("div[role=button]")[0].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Voir la caméra"));
|
||||
cut.FindAll("button").Single(b => b.TextContent.Contains("Fermer")).Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldNotContain("Voir la caméra"));
|
||||
|
||||
cut.FindComponents<MudDialog>().Count.ShouldBe(1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user