Files
Heimdall/tests/Heimdall.E2E.Tests/Pages/PageRenderTests.cs
T
arnaud.dartois 38647d3623
Heimdall Gitea / Detect CI scope (push) Successful in 5s
Heimdall Gitea / Build and tests (push) Successful in 32m0s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 8m15s
Heimdall Gitea / Build and scan agent image (push) Successful in 9m53s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m42s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 28m29s
Heimdall Gitea / CI policy (push) Successful in 2s
fix(web): render a 404 page for unknown routes (#294)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-08 00:32:22 +01:00

166 lines
5.8 KiB
C#

using Heimdall.TestCommon;
using Microsoft.Playwright;
using Shouldly;
namespace Heimdall.E2E.Tests.Pages;
[Collection("E2E")]
public class PageRenderTests : E2ETestBase
{
public PageRenderTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
[Fact]
public async Task Sites_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/sites", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { /* Protected page may redirect on auth failure */ }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Events_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/events", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Profile_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/profile", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Settings_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/settings", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Admin_groups_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/admin/groups", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Cameras_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/sites/{Guid.NewGuid()}/cameras", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Agents_page_renders()
{
try
{
await Page.GotoAsync($"{BaseUrl}/sites/{Guid.NewGuid()}/agents", new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 15000 });
}
catch { }
await Task.Delay(3000);
var body = Page.Locator("body");
var text = await body.TextContentAsync();
text.ShouldNotBeNull();
}
[Fact]
public async Task Unknown_route_renders_not_found_after_direct_load_and_client_navigation()
{
var directUrl = $"{BaseUrl}/not-a-route-qa";
var directResponseTask = Page.WaitForResponseAsync(response => response.Url == directUrl);
try
{
await Page.GotoAsync(directUrl, new PageGotoOptions
{
WaitUntil = WaitUntilState.DOMContentLoaded,
Timeout = 15000,
});
}
catch (PlaywrightException)
{
// Playwright reports the expected HTTP 404 as a navigation exception.
}
var directResponse = await directResponseTask;
await Page.GetByRole(AriaRole.Heading, new() { Name = "Page introuvable" })
.WaitForAsync(new() { State = WaitForSelectorState.Visible, Timeout = 15000 });
var backLink = Page.GetByRole(AriaRole.Link, new() { Name = "Retour" });
(await backLink.IsVisibleAsync()).ShouldBeTrue();
(await backLink.GetAttributeAsync("href")).ShouldBe("/dashboard");
directResponse.Status.ShouldBe(404);
await Page.GotoAsync($"{BaseUrl}/not-found");
await WaitForBlazorCircuitAsync();
await Page.EvaluateAsync("Blazor.navigateTo('/not-a-route-navigation-qa')");
await Page.WaitForURLAsync("**/not-a-route-navigation-qa");
await Page.GetByRole(AriaRole.Heading, new() { Name = "Page introuvable" })
.WaitForAsync(new() { State = WaitForSelectorState.Visible, Timeout = 15000 });
await LoginViaUiAsync();
var authenticatedResponseTask = Page.WaitForResponseAsync(response =>
response.Url == $"{BaseUrl}/not-a-route-authenticated-qa");
try
{
await Page.GotoAsync($"{BaseUrl}/not-a-route-authenticated-qa");
}
catch (PlaywrightException)
{
// The server returns HTTP 404 while rendering the not-found page.
}
var authenticatedResponse = await authenticatedResponseTask;
authenticatedResponse.Status.ShouldBe(404);
await Page.GetByRole(AriaRole.Heading, new() { Name = "Page introuvable" })
.WaitForAsync(new() { State = WaitForSelectorState.Visible, Timeout = 15000 });
using var apiClient = new HttpClient();
apiClient.DefaultRequestHeaders.Accept.ParseAdd("text/html");
var apiNotFound = await apiClient.GetAsync($"{BaseUrl}/api/not-a-route-qa");
apiNotFound.StatusCode.ShouldBe(System.Net.HttpStatusCode.NotFound);
(await apiNotFound.Content.ReadAsStringAsync()).ShouldNotContain("Page introuvable");
}
}