Files
Arnaud Dartois 2e45c37925
Heimdall Gitea / Build and tests (pull_request) Successful in 13m17s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 5m13s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m32s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
test(web): align localized page assertions
2026-10-25 05:17:23 +01:00

106 lines
3.8 KiB
C#

using Bunit;
using Heimdall.Web.Components.Layout;
using Heimdall.Web.Components.Pages;
using Heimdall.Web.Services;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
namespace Heimdall.Web.Tests.Components.Pages;
/// <summary>
/// A11y smoke tests (WCAG 2.2) — vérifie les invariants transverses posés
/// par l'issue #41 : un h1 par page (FocusOnNavigate cible h1), skip-link
/// dans le layout, aria-label sur les icon-buttons (le tooltip ne suffit pas).
/// </summary>
public class A11yPageTests : PageTestBase
{
private static readonly Guid SiteId = Guid.NewGuid();
private static readonly Guid CameraId = Guid.NewGuid();
[Fact]
public void EventsPage_AUnSeulH1()
{
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50));
LoginAs();
var cut = RenderPage<EventsPage>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Événements"));
cut.FindAll("h1").Count.ShouldBe(1);
}
[Fact]
public void DashboardPage_AUnSeulH1()
{
Handler.OnGet("api/stats", new StatsResult(0, 0, 0, 0, 0, 0, 0, 0, 0));
Handler.OnGet("api/sites", new PagedData<SiteItem>([], 0, 1, 5));
Handler.OnGet("api/agents", new PagedData<AgentItem>([], 0, 1, 5));
Handler.OnGet("api/events", new EventPageResult([], 0, 1, 10));
LoginAs();
var cut = RenderPage<Dashboard>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tableau de bord"));
cut.FindAll("h1").Count.ShouldBe(1);
// Le titre de page est le seul h1 ; les compteurs de stats restent des h4
cut.FindAll("h4").Count.ShouldBeGreaterThan(0);
}
[Fact]
public void CamerasPage_AUnSeulH1()
{
Handler.OnGet("api/cameras/by-site", new PagedData<CameraItem>([], 0, 1, 20));
LoginAs();
var cut = RenderPage<CamerasPage>(p => p.Add(x => x.SiteId, SiteId));
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Caméras"));
cut.FindAll("h1").Count.ShouldBe(1);
}
[Fact]
public void IconButtons_SansTooltip_OntUnAriaLabel()
{
// Une liste non vide pour que la timeline rende le bouton snapshot applicatif.
Handler.OnGet("api/events", new EventPageResult(
[new(Guid.NewGuid(), Guid.NewGuid(), null, "MotionDetected", 0.9, "Personne",
"/snapshots/1.jpg", null, DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow)], 1, 1, 50));
LoginAs();
var cut = RenderPage<EventsPage>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Événements"));
// Icon-buttons applicatifs uniquement (hors composants internes MudBlazor
// comme le picker du MudDateRangePicker qui portent leurs propres
// mécanismes d'accessibilité).
var buttons = cut.FindAll("button.mud-icon-button")
.Where(b => !b.ClassList.Any(c => c.StartsWith("mud-input-adornment", StringComparison.Ordinal)))
.ToList();
buttons.ShouldNotBeEmpty();
foreach (var btn in buttons)
{
if (!btn.HasAttribute("aria-label"))
{
var html = btn.OuterHtml;
throw new Xunit.Sdk.XunitException(
$"Icon-button sans aria-label : {html[..Math.Min(200, html.Length)]}");
}
}
}
[Fact]
public void MainLayout_ContientSkipLinkVersMainContent()
{
// Le skip-link vit dans MainLayout ; on rend le layout directement
// (RenderPage<T> rend la page sans son layout).
LoginAs();
var cut = Render<MainLayout>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Heimdall"));
cut.Markup.ShouldContain("class=\"skip-link\"");
cut.Markup.ShouldContain("Aller au contenu principal");
cut.Markup.ShouldContain("id=\"main-content\"");
}
}