Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Merge pull request #138 Co-authored-by: Arnaud Dartois <admin@tordais.cc>
63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
using System.Net;
|
|
using System.Text.Json;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.E2E.Tests.Pages;
|
|
|
|
[Collection("E2E")]
|
|
public class PwaTests : E2ETestBase
|
|
{
|
|
public PwaTests(TestCommon.PostgreSqlContainerFixture postgres) : base(postgres) { }
|
|
|
|
[Fact]
|
|
public async Task Manifest_and_public_shell_are_available_without_authentication()
|
|
{
|
|
using var http = new HttpClient { BaseAddress = new Uri(BaseUrl) };
|
|
using var manifestResponse = await http.GetAsync("/manifest.webmanifest");
|
|
manifestResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
|
|
|
|
using var manifest = JsonDocument.Parse(await manifestResponse.Content.ReadAsStringAsync());
|
|
manifest.RootElement.GetProperty("start_url").GetString().ShouldBe("/");
|
|
manifest.RootElement.GetProperty("scope").GetString().ShouldBe("/");
|
|
manifest.RootElement.GetProperty("display").GetString().ShouldBe("standalone");
|
|
manifest.RootElement.GetProperty("icons").GetArrayLength().ShouldBeGreaterThanOrEqualTo(3);
|
|
|
|
foreach (var asset in new[] { "/service-worker.js", "/offline.html", "/pwa-icon.svg", "/pwa-icon-180.png", "/pwa-icon-192.png", "/pwa-icon-512.png" })
|
|
{
|
|
using var response = await http.GetAsync(asset);
|
|
response.StatusCode.ShouldBe(HttpStatusCode.OK, asset);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Offline_navigation_serves_only_the_public_offline_page()
|
|
{
|
|
await Page.GotoAsync($"{BaseUrl}/login");
|
|
await Page.EvaluateAsync("async () => await navigator.serviceWorker.ready");
|
|
await Page.GotoAsync($"{BaseUrl}/login");
|
|
await Page.WaitForFunctionAsync("() => !!navigator.serviceWorker.controller");
|
|
|
|
var publicShell = await Page.EvaluateAsync<string[]>(@"async () => {
|
|
const cache = await caches.open('heimdall-public-shell-v1');
|
|
return (await cache.keys()).map(request => new URL(request.url).pathname).sort();
|
|
}");
|
|
publicShell.ShouldBe(new[] {
|
|
"/manifest.webmanifest",
|
|
"/offline.html",
|
|
"/pwa-icon.svg"
|
|
});
|
|
|
|
await Page.Context.SetOfflineAsync(true);
|
|
try
|
|
{
|
|
await Page.GotoAsync($"{BaseUrl}/dashboard", new() { WaitUntil = Microsoft.Playwright.WaitUntilState.Commit });
|
|
(await Page.Locator("h1").InnerTextAsync()).ShouldBe("Connexion au serveur impossible");
|
|
(await Page.Locator("body").InnerTextAsync()).ShouldNotContain("dashboard");
|
|
}
|
|
finally
|
|
{
|
|
await Page.Context.SetOfflineAsync(false);
|
|
}
|
|
}
|
|
}
|