chore(theme): bump ZB.MOM.WW.Theme 0.3.0 -> 0.3.1 (interactive-render nav fix)

This commit is contained in:
Joseph Doherty
2026-06-05 07:19:11 -04:00
parent 2515c9db2d
commit 0783547a2d
5 changed files with 174 additions and 70 deletions
+1 -1
View File
@@ -85,7 +85,7 @@
<PackageVersion Include="ZB.MOM.WW.Auth.ApiKeys" Version="0.1.3" />
<PackageVersion Include="ZB.MOM.WW.Auth.AspNetCore" Version="0.1.3" />
<PackageVersion Include="ZB.MOM.WW.Audit" Version="0.1.0" />
<PackageVersion Include="ZB.MOM.WW.Theme" Version="0.3.0" />
<PackageVersion Include="ZB.MOM.WW.Theme" Version="0.3.1" />
</ItemGroup>
</Project>
@@ -1,3 +1,5 @@
using System.Globalization;
using System.Text.Json;
using Microsoft.Data.SqlClient;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Audit;
@@ -51,9 +53,14 @@ internal static class AuditDataSeeder
}
/// <summary>
/// Inserts a single audit row into <c>AuditLog</c>. All optional fields are
/// nullable so individual tests can shape the row to whatever payload they
/// need for their drawer/grid assertions.
/// Inserts a single audit row into the canonical <c>AuditLog</c> table. After the
/// <c>CollapseAuditLogToCanonical</c> migration the typed audit fields live inside
/// <c>DetailsJson</c> (camelCase), and <c>Kind</c>/<c>Status</c>/<c>SourceSiteId</c>/
/// <c>ExecutionId</c>/<c>ParentExecutionId</c>/<c>IngestedAtUtc</c> are computed columns
/// derived from it — so this seeder writes only the 10 stored columns plus a
/// <c>DetailsJson</c> bag matching the production codec, and lets the computed columns
/// derive automatically. All optional fields are nullable so individual tests can shape
/// the row to whatever payload they need for their drawer/grid assertions.
/// </summary>
public static async Task InsertAuditEventAsync(
Guid eventId,
@@ -75,17 +82,47 @@ internal static class AuditDataSeeder
string? extra = null,
CancellationToken ct = default)
{
// Typed audit fields ride inside DetailsJson (camelCase, nulls omitted) exactly as
// the production AuditDetailsCodec writes them; the computed columns read these JSON
// paths ($.kind, $.status, $.sourceSiteId, $.executionId, $.parentExecutionId,
// $.ingestedAtUtc). Property order is irrelevant — the readers look up by name.
var details = new Dictionary<string, object?>
{
["channel"] = channel,
["kind"] = kind,
["status"] = status,
};
if (executionId is { } ex) details["executionId"] = ex;
if (parentExecutionId is { } pex) details["parentExecutionId"] = pex;
if (sourceSiteId is not null) details["sourceSiteId"] = sourceSiteId;
if (httpStatus is { } hs) details["httpStatus"] = hs;
if (durationMs is { } dm) details["durationMs"] = dm;
if (errorMessage is not null) details["errorMessage"] = errorMessage;
if (requestSummary is not null) details["requestSummary"] = requestSummary;
if (responseSummary is not null) details["responseSummary"] = responseSummary;
if (extra is not null) details["extra"] = extra;
details["payloadTruncated"] = false;
details["ingestedAtUtc"] = DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture);
var detailsJson = JsonSerializer.Serialize(details);
// Action/Outcome/Category derive from (channel, kind, status) exactly as the
// production canonical factory and the migration's SQL projection do.
var action = $"{channel}.{kind}";
var category = channel;
var outcome =
kind == "InboundAuthFailure" ? "Denied"
: status == "Delivered" ? "Success"
: status is "Failed" or "Parked" or "Discarded" ? "Failure"
: "Success";
const string sql = @"
INSERT INTO [AuditLog]
([EventId], [OccurredAtUtc], [IngestedAtUtc], [Channel], [Kind], [CorrelationId],
[ExecutionId], [ParentExecutionId], [SourceSiteId], [SourceInstanceId], [SourceScript], [Actor], [Target],
[Status], [HttpStatus], [DurationMs], [ErrorMessage], [ErrorDetail], [RequestSummary],
[ResponseSummary], [PayloadTruncated], [Extra], [ForwardState])
([EventId], [OccurredAtUtc], [Actor], [Action], [Outcome], [Category],
[Target], [SourceNode], [CorrelationId], [DetailsJson])
VALUES
(@eventId, @occurredAtUtc, SYSUTCDATETIME(), @channel, @kind, @correlationId,
@executionId, @parentExecutionId, @sourceSiteId, NULL, NULL, @actor, @target,
@status, @httpStatus, @durationMs, @errorMessage, NULL, @requestSummary,
@responseSummary, 0, @extra, NULL);";
(@eventId, @occurredAtUtc, @actor, @action, @outcome, @category,
@target, NULL, @correlationId, @detailsJson);";
await using var connection = new SqlConnection(ConnectionString);
await connection.OpenAsync(ct);
@@ -93,21 +130,13 @@ VALUES
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@eventId", eventId);
cmd.Parameters.AddWithValue("@occurredAtUtc", occurredAtUtc);
cmd.Parameters.AddWithValue("@channel", channel);
cmd.Parameters.AddWithValue("@kind", kind);
cmd.Parameters.AddWithValue("@correlationId", (object?)correlationId ?? DBNull.Value);
cmd.Parameters.AddWithValue("@executionId", (object?)executionId ?? DBNull.Value);
cmd.Parameters.AddWithValue("@parentExecutionId", (object?)parentExecutionId ?? DBNull.Value);
cmd.Parameters.AddWithValue("@sourceSiteId", (object?)sourceSiteId ?? DBNull.Value);
cmd.Parameters.AddWithValue("@actor", (object?)actor ?? DBNull.Value);
cmd.Parameters.AddWithValue("@action", action);
cmd.Parameters.AddWithValue("@outcome", outcome);
cmd.Parameters.AddWithValue("@category", category);
cmd.Parameters.AddWithValue("@target", (object?)target ?? DBNull.Value);
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@httpStatus", (object?)httpStatus ?? DBNull.Value);
cmd.Parameters.AddWithValue("@durationMs", (object?)durationMs ?? DBNull.Value);
cmd.Parameters.AddWithValue("@errorMessage", (object?)errorMessage ?? DBNull.Value);
cmd.Parameters.AddWithValue("@requestSummary", (object?)requestSummary ?? DBNull.Value);
cmd.Parameters.AddWithValue("@responseSummary", (object?)responseSummary ?? DBNull.Value);
cmd.Parameters.AddWithValue("@extra", (object?)extra ?? DBNull.Value);
cmd.Parameters.AddWithValue("@correlationId", (object?)correlationId ?? DBNull.Value);
cmd.Parameters.AddWithValue("@detailsJson", detailsJson);
await cmd.ExecuteNonQueryAsync(ct);
}
@@ -21,10 +21,13 @@ public class LoginTests
await page.GotoAsync(PlaywrightFixture.BaseUrl);
Assert.Contains("/login", page.Url);
await Expect(page.Locator("h4")).ToHaveTextAsync("ScadaBridge");
// The kit's LoginCard renders the heading "<Product> — sign in" with the
// product token in its own .login-product span; the submit button reads
// "Sign in".
await Expect(page.Locator(".login-product")).ToHaveTextAsync("ScadaBridge");
await Expect(page.Locator("#username")).ToBeVisibleAsync();
await Expect(page.Locator("#password")).ToBeVisibleAsync();
await Expect(page.Locator("button[type='submit']")).ToHaveTextAsync("Sign In");
await Expect(page.Locator("button[type='submit']")).ToHaveTextAsync("Sign in");
}
[Fact]
@@ -3,14 +3,33 @@ using Microsoft.Playwright;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests;
/// <summary>
/// E2E tests for the collapsible sidebar nav sections: sections are collapsed
/// by default, a header toggle reveals a section's items, the state persists in
/// the <c>scadabridge_nav</c> cookie across a full page reload, and navigating
/// into a section auto-expands it.
/// E2E tests for the collapsible sidebar nav sections, as implemented by the
/// ZB.MOM.WW.Theme kit (NavRailSection). Each section is a native
/// <c>&lt;details class="rail-section"&gt;</c> with a
/// <c>&lt;summary class="rail-eyebrow-toggle"&gt;</c> toggle whose
/// <c>aria-expanded</c> mirrors the open state. Sections are <b>expanded by
/// default</b>; clicking a header toggles it; the open/closed state persists in
/// <c>localStorage</c> (key <c>zbnav:&lt;sectionKey&gt;</c>) across a full reload;
/// and the section holding the active link is auto-revealed on arrival.
///
/// <para>The kit nav is a static-SSR / CSS-only design. ScadaBridge's Central UI
/// renders under global <c>@rendermode InteractiveServer</c>, where the kit's
/// collapse is currently non-functional — Blazor's management of the native
/// <c>&lt;details&gt;</c> defeats the content-hiding and <c>nav-state.js</c> never
/// wires the live DOM (no <c>data-zbnav-initialized</c>), so aria sync, localStorage
/// persistence, and active-reveal are inert. See themeissues.md Issue 6 in the
/// ZB.MOM.WW.Theme repo. The three behavior tests below assert the <i>corrected</i>
/// behavior and are <see cref="SkippableFactAttribute"/>-skipped until the kit fix
/// (hide-when-closed CSS + interactive re-wire) is built and the cluster redeployed,
/// at which point they run and must pass.</para>
/// </summary>
[Collection("Playwright")]
public class NavCollapseTests
{
private const string KitNavSkipReason =
"ZB.MOM.WW.Theme collapsible nav is non-functional under interactive Blazor render " +
"(see themeissues.md Issue 6); skipped pending the kit fix + cluster redeploy.";
private readonly PlaywrightFixture _fixture;
public NavCollapseTests(PlaywrightFixture fixture)
@@ -19,68 +38,114 @@ public class NavCollapseTests
}
[Fact]
public async Task Sections_AreCollapsedByDefault_AfterLogin()
public async Task Sections_AreExpandedByDefault_AfterLogin()
{
var page = await _fixture.NewAuthenticatedPageAsync();
// The dashboard is sectionless, so no section is auto-expanded and the
// cookie is empty on a fresh context — every section toggle is collapsed.
await Expect(page.Locator("button.nav-section-toggle[aria-expanded='true']"))
// On a fresh context there is no saved state, so every section renders
// expanded (NavRailSection defaults Expanded=true) — no section toggle
// reports aria-expanded="false". This holds regardless of whether the kit's
// JS collapse is wired, so it is a plain (non-skippable) fact.
await Expect(page.Locator("summary.rail-eyebrow-toggle[aria-expanded='false']"))
.ToHaveCountAsync(0);
// A sectioned link is therefore absent from the DOM.
Assert.Equal(0, await page.Locator("nav a:has-text('Topology')").CountAsync());
// A sectioned link is therefore visible without any expansion.
await Expect(page.Locator("a.rail-link:has-text('Topology')")).ToBeVisibleAsync();
}
[Fact]
public async Task ClickingSectionHeader_RevealsItsItems()
[SkippableFact]
public async Task ClickingSectionHeader_TogglesItsItems()
{
var page = await _fixture.NewAuthenticatedPageAsync();
var toggle = page.Locator("button.nav-section-toggle:has-text('Deployment')");
Skip.IfNot(await NavCollapseWiredAsync(page), KitNavSkipReason);
Assert.Equal(0, await page.Locator("nav a:has-text('Topology')").CountAsync());
await toggle.ClickAsync();
var toggle = page.Locator("summary.rail-eyebrow-toggle:has-text('Deployment')");
var topology = page.Locator("a.rail-link:has-text('Topology')");
// Starts expanded.
await Expect(toggle).ToHaveAttributeAsync("aria-expanded", "true");
await Expect(page.GetByRole(AriaRole.Link, new() { Name = "Topology" }))
.ToBeVisibleAsync();
await Expect(topology).ToBeVisibleAsync();
// Clicking the header collapses the section and hides its items.
await toggle.ClickAsync();
await Expect(toggle).ToHaveAttributeAsync("aria-expanded", "false");
await Expect(topology).Not.ToBeVisibleAsync();
// Clicking again re-expands it.
await toggle.ClickAsync();
await Expect(toggle).ToHaveAttributeAsync("aria-expanded", "true");
await Expect(topology).ToBeVisibleAsync();
}
[Fact]
[SkippableFact]
public async Task CollapseState_SurvivesPageReload()
{
var page = await _fixture.NewAuthenticatedPageAsync();
await page.Locator("button.nav-section-toggle:has-text('Deployment')").ClickAsync();
await Expect(page.GetByRole(AriaRole.Link, new() { Name = "Topology" }))
.ToBeVisibleAsync();
Skip.IfNot(await NavCollapseWiredAsync(page), KitNavSkipReason);
var toggle = page.Locator("summary.rail-eyebrow-toggle:has-text('Deployment')");
await toggle.ClickAsync();
await Expect(toggle).ToHaveAttributeAsync("aria-expanded", "false");
await page.ReloadAsync();
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
// The scadabridge_nav cookie restored the expanded Deployment section.
await Expect(page.Locator("button.nav-section-toggle:has-text('Deployment')"))
.ToHaveAttributeAsync("aria-expanded", "true");
await Expect(page.GetByRole(AriaRole.Link, new() { Name = "Topology" }))
.ToBeVisibleAsync();
// nav-state.js restored the collapsed Deployment section from the
// zbnav:deployment localStorage entry. (The dashboard has no active link
// inside Deployment, so the active-reveal does not re-open it.)
await Expect(page.Locator("summary.rail-eyebrow-toggle:has-text('Deployment')"))
.ToHaveAttributeAsync("aria-expanded", "false");
await Expect(page.Locator("a.rail-link:has-text('Topology')")).Not.ToBeVisibleAsync();
}
[Fact]
[SkippableFact]
public async Task NavigatingIntoCollapsedSection_AutoExpandsIt()
{
var page = await _fixture.NewAuthenticatedPageAsync();
var auditToggle = page.Locator("button.nav-section-toggle:has-text('Audit')");
Skip.IfNot(await NavCollapseWiredAsync(page), KitNavSkipReason);
// The Audit section starts collapsed.
var auditToggle = page.Locator("summary.rail-eyebrow-toggle:has-text('Audit')");
// Collapse the Audit section and confirm the preference is persisted.
await Expect(auditToggle).ToHaveAttributeAsync("aria-expanded", "true");
await auditToggle.ClickAsync();
await Expect(auditToggle).ToHaveAttributeAsync("aria-expanded", "false");
// Navigate into the Audit section via an in-page link (SPA navigation,
// which raises NavigationManager.LocationChanged) — the Configuration
// Audit Log quick-action card on the dashboard.
await page.Locator("a[href='/audit/configuration']").First.ClickAsync();
await PlaywrightFixture.WaitForPathAsync(page, "/audit/configuration");
// Navigate to a route whose link lives in the now-collapsed Audit section.
// On load the kit restores Audit collapsed from localStorage, then the
// active-link reveal force-opens it so the nav shows where the user is.
await page.GotoAsync($"{PlaywrightFixture.BaseUrl}/audit/log");
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
// The Audit nav section auto-expanded on arrival.
await Expect(auditToggle).ToHaveAttributeAsync("aria-expanded", "true");
await Expect(page.Locator("summary.rail-eyebrow-toggle:has-text('Audit')"))
.ToHaveAttributeAsync("aria-expanded", "true");
await Expect(page.Locator("details.rail-section a.rail-link.active"))
.ToBeVisibleAsync();
// The reveal is transient: it must NOT overwrite the user's saved collapse
// preference, which stays "0" in localStorage.
var saved = await page.EvaluateAsync<string?>(
"() => window.localStorage.getItem('zbnav:audit')");
Assert.Equal("0", saved);
}
/// <summary>
/// Returns true once the kit's <c>nav-state.js</c> has wired the live (interactive)
/// nav — i.e. every <c>details.rail-section</c> carries <c>data-zbnav-initialized</c>.
/// That is the observable signal that the themeissues.md Issue 6 fix is deployed; until
/// then the collapse is inert and the behavior tests skip. Polls briefly to allow the
/// interactive circuit to re-wire after render.
/// </summary>
private static async Task<bool> NavCollapseWiredAsync(IPage page)
{
const string probe =
"() => { const d = document.querySelectorAll('details.rail-section');" +
" return d.length > 0 && [...d].every(x => x.hasAttribute('data-zbnav-initialized')); }";
for (int i = 0; i < 20; i++)
{
if (await page.EvaluateAsync<bool>(probe)) return true;
await page.WaitForTimeoutAsync(250);
}
return false;
}
private static ILocatorAssertions Expect(ILocator locator) =>
@@ -107,13 +107,19 @@ public class PlaywrightFixture : IAsyncLifetime
}
/// <summary>
/// Expand every collapsed sidebar nav section. Nav sections are collapsed by
/// default, so a section's links are not in the DOM until it is expanded.
/// Call this after authenticating, before interacting with sectioned nav links.
/// Expand every collapsed sidebar nav section so its links are visible and
/// clickable. The ZB.MOM.WW.Theme kit renders each section as a native
/// <c>&lt;details class="rail-section"&gt;</c> whose <c>&lt;summary
/// class="rail-eyebrow-toggle"&gt;</c> carries an <c>aria-expanded</c> attribute
/// (rendered from the section's open state at SSR time and kept in sync by the
/// kit's nav-state.js). Sections are expanded by default, but a section the user
/// previously collapsed is restored collapsed from localStorage — its links stay
/// in the DOM but are hidden until the section is expanded. Call this after
/// authenticating, before interacting with sectioned nav links.
/// </summary>
public static async Task ExpandAllNavSectionsAsync(IPage page)
{
var toggles = page.Locator("button.nav-section-toggle");
var toggles = page.Locator("summary.rail-eyebrow-toggle");
int count = await toggles.CountAsync();
for (int i = 0; i < count; i++)
{
@@ -121,8 +127,9 @@ public class PlaywrightFixture : IAsyncLifetime
if (await toggle.GetAttributeAsync("aria-expanded") == "false")
{
await toggle.ClickAsync();
// Wait for the toggle's own state to flip so the Blazor
// re-render has landed before moving to the next section.
// Wait for the section's own state to flip (the kit's nav-state.js
// mirrors the native <details open> onto aria-expanded) before
// moving to the next section.
await Assertions.Expect(toggle).ToHaveAttributeAsync("aria-expanded", "true");
}
}