feat(central-ui): Notification report accepts ?correlationId= and opens the notification's detail
Claude-Session: https://claude.ai/code/session_01NcMG6xXdsJbmD2wYAgkK29
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Security.Claims;
|
||||
using Akka.Actor;
|
||||
using Bunit;
|
||||
using Bunit.TestDoubles;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -46,7 +48,9 @@ public class NotificationReportPageTests : BunitContext
|
||||
DeliveredAt: DateTimeOffset.UtcNow.AddHours(-2), IsStuck: false),
|
||||
}, TotalCount: 2);
|
||||
|
||||
// Records the most recent retry/discard requests the actor received.
|
||||
// Records every outbox query the page issued (filter assertions) and the
|
||||
// most recent retry/discard requests the actor received.
|
||||
private readonly List<NotificationOutboxQueryRequest> _queryRequests = new();
|
||||
private readonly List<RetryNotificationRequest> _retryRequests = new();
|
||||
private readonly List<DiscardNotificationRequest> _discardRequests = new();
|
||||
|
||||
@@ -237,6 +241,91 @@ public class NotificationReportPageTests : BunitContext
|
||||
Assert.Contains("View audit history", link.TextContent);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// Flow Debugger follow-ups (register row 111, plan D2): ?correlationId=
|
||||
// seeds a read-only Notification pill filter, rides the query as
|
||||
// NotificationIdFilter, and auto-opens the detail when exactly one row
|
||||
// with that id comes back.
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void NotificationReport_CorrelationIdQuery_SeedsTheNotificationFilterAndAutoOpensDetail()
|
||||
{
|
||||
const string id = "notif-aaaaaaaa-1111";
|
||||
_queryReply = new NotificationOutboxQueryResponse(
|
||||
"q", true, null, new List<NotificationSummary>
|
||||
{
|
||||
new(id, "Email", "Ops On-Call", "Pump fault at Plant-A",
|
||||
"Parked", RetryCount: 3, LastError: "SMTP timeout", SourceSiteId: "plant-a",
|
||||
SourceInstanceId: "Pump-001", CreatedAt: DateTimeOffset.UtcNow.AddMinutes(-30),
|
||||
DeliveredAt: null, IsStuck: true),
|
||||
}, TotalCount: 1);
|
||||
|
||||
var nav = (BunitNavigationManager)Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo($"/notifications/report?correlationId={id}");
|
||||
|
||||
var cut = Render<NotificationReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
// The very first fetch already carries the exact-match filter.
|
||||
Assert.Single(_queryRequests);
|
||||
Assert.Equal(id, _queryRequests[0].NotificationIdFilter);
|
||||
|
||||
// The read-only pill names the notification by its short id.
|
||||
var pill = cut.Find("[data-test='notif-filter-notification']");
|
||||
Assert.Contains("Notification", pill.TextContent);
|
||||
Assert.Contains(id[..12], pill.TextContent);
|
||||
|
||||
// Exactly one matching row came back → the detail modal is open on it.
|
||||
var modal = cut.Find(".modal.show");
|
||||
Assert.Contains("Pump fault at Plant-A", modal.TextContent);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearFilters_DropsTheNotificationFilter()
|
||||
{
|
||||
var nav = (BunitNavigationManager)Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo("/notifications/report?correlationId=notif-aaaaaaaa-1111");
|
||||
|
||||
var cut = Render<NotificationReportPage>();
|
||||
cut.WaitForState(() => cut.FindAll("[data-test='notif-filter-notification']").Count == 1);
|
||||
|
||||
// The pill alone makes the filter set "active" — Clear is enabled.
|
||||
var clear = cut.FindAll("button").First(b => b.TextContent.Trim() == "Clear");
|
||||
Assert.False(clear.HasAttribute("disabled"));
|
||||
|
||||
clear.Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Empty(cut.FindAll("[data-test='notif-filter-notification']"));
|
||||
var clearAfter = cut.FindAll("button").First(b => b.TextContent.Trim() == "Clear");
|
||||
Assert.True(clearAfter.HasAttribute("disabled"));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotificationFilterPill_Clear_DropsTheFilterAndRequeries()
|
||||
{
|
||||
var nav = (BunitNavigationManager)Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo("/notifications/report?correlationId=notif-aaaaaaaa-1111");
|
||||
|
||||
var cut = Render<NotificationReportPage>();
|
||||
cut.WaitForState(() => cut.FindAll("[data-test='notif-filter-notification-clear']").Count == 1);
|
||||
|
||||
cut.Find("[data-test='notif-filter-notification-clear']").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Empty(cut.FindAll("[data-test='notif-filter-notification']"));
|
||||
// The × re-runs the query without the id filter.
|
||||
Assert.Equal(2, _queryRequests.Count);
|
||||
Assert.Null(_queryRequests[1].NotificationIdFilter);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
@@ -254,7 +343,24 @@ public class NotificationReportPageTests : BunitContext
|
||||
{
|
||||
public ScriptedOutboxActor(NotificationReportPageTests test)
|
||||
{
|
||||
Receive<NotificationOutboxQueryRequest>(_ => Sender.Tell(test._queryReply));
|
||||
Receive<NotificationOutboxQueryRequest>(req =>
|
||||
{
|
||||
test._queryRequests.Add(req);
|
||||
Sender.Tell(test._queryReply with { CorrelationId = req.CorrelationId });
|
||||
});
|
||||
// The ?correlationId= auto-open path fetches the row's full detail;
|
||||
// reply with a minimal detail so the modal settles instead of the
|
||||
// Ask timing out.
|
||||
Receive<NotificationDetailRequest>(r => Sender.Tell(new NotificationDetailResponse(
|
||||
r.CorrelationId, true, null,
|
||||
new NotificationDetail(
|
||||
r.NotificationId, "Email", "Ops On-Call", "Pump fault at Plant-A",
|
||||
"Body", "Parked", RetryCount: 3, LastError: "SMTP timeout",
|
||||
ResolvedTargets: null, TypeData: null, SourceSiteId: "plant-a",
|
||||
SourceInstanceId: "Pump-001", SourceScript: null,
|
||||
SiteEnqueuedAt: DateTimeOffset.UtcNow.AddMinutes(-31),
|
||||
CreatedAt: DateTimeOffset.UtcNow.AddMinutes(-30),
|
||||
LastAttemptAt: null, NextAttemptAt: null, DeliveredAt: null))));
|
||||
Receive<RetryNotificationRequest>(r =>
|
||||
{
|
||||
test._retryRequests.Add(r);
|
||||
|
||||
@@ -19,10 +19,12 @@ using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Audit;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Notification;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Communication;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using NotificationReportPage = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Notifications.NotificationReport;
|
||||
using SiteCallsReportPage = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.SiteCalls.SiteCallsReport;
|
||||
using TransportImportPage = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Design.TransportImport;
|
||||
|
||||
@@ -104,6 +106,75 @@ public sealed class QueryStringDrillInTests
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// SiteCallsReport — ?correlationId= (Flow Debugger / Audit Log deep link, D2)
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void SiteCallsReport_CorrelationIdQuery_SeedsTheOperationFilter()
|
||||
{
|
||||
// A well-formed GUID rides on the first query as the exact-match
|
||||
// TrackedOperationIdFilter and renders the read-only Operation pill.
|
||||
var op = Guid.Parse("44444444-4444-4444-4444-444444444444");
|
||||
using var ctx = new SiteCallsReportFixture();
|
||||
var nav = (BunitNavigationManager)ctx.Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo($"/site-calls/report?correlationId={op}");
|
||||
|
||||
var cut = ctx.Render<SiteCallsReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Single(ctx.QueryRequests);
|
||||
Assert.Equal(op, ctx.QueryRequests[0].TrackedOperationIdFilter);
|
||||
var pill = cut.Find("[data-test='site-calls-filter-operation']");
|
||||
Assert.Contains(op.ToString("N")[..12], pill.TextContent);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteCallsReport_CorrelationIdQuery_Malformed_IsIgnored()
|
||||
{
|
||||
// Lax parsing, like ?status= — a value that is not a GUID leaves the
|
||||
// filter null and renders no pill, so a hand-crafted bad URL loads the
|
||||
// page unfiltered instead of breaking it.
|
||||
using var ctx = new SiteCallsReportFixture();
|
||||
var nav = (BunitNavigationManager)ctx.Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo("/site-calls/report?correlationId=nope");
|
||||
|
||||
var cut = ctx.Render<SiteCallsReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Single(ctx.QueryRequests);
|
||||
Assert.Null(ctx.QueryRequests[0].TrackedOperationIdFilter);
|
||||
});
|
||||
Assert.Empty(cut.FindAll("[data-test='site-calls-filter-operation']"));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// NotificationReport — ?correlationId= (Flow Debugger follow-ups, D2)
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void NotificationReport_CorrelationIdQuery_Blank_IsIgnored()
|
||||
{
|
||||
// A blank/whitespace ?correlationId= is dropped: the first query carries
|
||||
// no NotificationIdFilter and no pill renders, so a hand-crafted empty
|
||||
// deep link degrades to the plain unfiltered page.
|
||||
using var ctx = new NotificationReportFixture();
|
||||
var nav = (BunitNavigationManager)ctx.Services.GetRequiredService<NavigationManager>();
|
||||
nav.NavigateTo("/notifications/report?correlationId=%20");
|
||||
|
||||
var cut = ctx.Render<NotificationReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Single(ctx.QueryRequests);
|
||||
Assert.Null(ctx.QueryRequests[0].NotificationIdFilter);
|
||||
Assert.Empty(cut.FindAll("[data-test='notif-filter-notification']"));
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// TransportImport — no query-string parameters on this route
|
||||
// -----------------------------------------------------------------
|
||||
@@ -209,6 +280,67 @@ public sealed class QueryStringDrillInTests
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class NotificationReportFixture : BunitContext
|
||||
{
|
||||
private readonly ActorSystem _system = ActorSystem.Create("qs-drillin-notif-tests");
|
||||
public readonly CommunicationService Comms;
|
||||
public readonly List<NotificationOutboxQueryRequest> QueryRequests = new();
|
||||
|
||||
public NotificationReportFixture()
|
||||
{
|
||||
Comms = new CommunicationService(
|
||||
Options.Create(new CommunicationOptions()),
|
||||
NullLogger<CommunicationService>.Instance);
|
||||
|
||||
var outbox = _system.ActorOf(Props.Create(() => new ScriptedNotificationOutboxActor(this)));
|
||||
Comms.SetNotificationOutbox(outbox);
|
||||
|
||||
Services.AddSingleton(Comms);
|
||||
Services.AddSingleton<IDialogService>(new AlwaysConfirmDialogService());
|
||||
|
||||
var siteRepo = Substitute.For<ISiteRepository>();
|
||||
siteRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Site>>(new List<Site>
|
||||
{
|
||||
new("Plant A", "plant-a") { Id = 1 },
|
||||
}));
|
||||
Services.AddSingleton(siteRepo);
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "tester"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
};
|
||||
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
||||
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(user));
|
||||
Services.AddAuthorizationCore();
|
||||
Services.AddScoped<ZB.MOM.WW.ScadaBridge.CentralUI.Auth.SiteScopeService>();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_system.Terminate().Wait(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ScriptedNotificationOutboxActor : ReceiveActor
|
||||
{
|
||||
public ScriptedNotificationOutboxActor(NotificationReportFixture fixture)
|
||||
{
|
||||
Receive<NotificationOutboxQueryRequest>(req =>
|
||||
{
|
||||
fixture.QueryRequests.Add(req);
|
||||
Sender.Tell(new NotificationOutboxQueryResponse(
|
||||
req.CorrelationId, true, null,
|
||||
new List<NotificationSummary>(), TotalCount: 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AlwaysConfirmDialogService : IDialogService
|
||||
{
|
||||
public Task<bool> ConfirmAsync(string title, string message, bool danger = false, string? confirmLabel = null)
|
||||
|
||||
Reference in New Issue
Block a user