feat(centralui): Site Call KPI tiles on the Health dashboard
This commit is contained in:
@@ -9,6 +9,7 @@ using NSubstitute;
|
||||
using ScadaLink.CentralUI.Services;
|
||||
using ScadaLink.Commons.Entities.Sites;
|
||||
using ScadaLink.Commons.Interfaces.Repositories;
|
||||
using ScadaLink.Commons.Messages.Audit;
|
||||
using ScadaLink.Commons.Messages.Notification;
|
||||
using ScadaLink.Commons.Types;
|
||||
using ScadaLink.Communication;
|
||||
@@ -37,6 +38,13 @@ public class HealthPageTests : BunitContext
|
||||
new("k", true, null, QueueDepth: 12, StuckCount: 4, ParkedCount: 3,
|
||||
DeliveredLastInterval: 88, OldestPendingAge: TimeSpan.FromMinutes(6));
|
||||
|
||||
// Site Call Audit (#22) Task 7 — mutable scripted Site Call KPI reply. Tests
|
||||
// that target the Site Call tiles override this before rendering.
|
||||
private SiteCallKpiResponse _siteCallKpiReply =
|
||||
new("k", true, null, BufferedCount: 9, ParkedCount: 2, FailedLastInterval: 1,
|
||||
DeliveredLastInterval: 40, OldestPendingAge: TimeSpan.FromMinutes(3),
|
||||
StuckCount: 5);
|
||||
|
||||
public HealthPageTests()
|
||||
{
|
||||
_comms = new CommunicationService(
|
||||
@@ -45,6 +53,9 @@ public class HealthPageTests : BunitContext
|
||||
|
||||
var outbox = _system.ActorOf(Props.Create(() => new ScriptedOutboxActor(this)));
|
||||
_comms.SetNotificationOutbox(outbox);
|
||||
|
||||
var siteCallAudit = _system.ActorOf(Props.Create(() => new ScriptedSiteCallAuditActor(this)));
|
||||
_comms.SetSiteCallAudit(siteCallAudit);
|
||||
Services.AddSingleton(_comms);
|
||||
|
||||
var aggregator = Substitute.For<ICentralHealthAggregator>();
|
||||
@@ -133,6 +144,53 @@ public class HealthPageTests : BunitContext
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Renders_SiteCallKpiTiles_WithValues()
|
||||
{
|
||||
var cut = Render<HealthPage>();
|
||||
|
||||
// KPI data arrives via an async actor Ask after first render.
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
Assert.Contains("Site Calls", cut.Markup);
|
||||
// The three Site Call tiles render at the documented data-test selectors.
|
||||
Assert.Contains("data-test=\"site-call-kpi-buffered\"", cut.Markup);
|
||||
Assert.Contains("data-test=\"site-call-kpi-stuck\"", cut.Markup);
|
||||
Assert.Contains("data-test=\"site-call-kpi-parked\"", cut.Markup);
|
||||
// KPI numeric values surface in the tiles.
|
||||
Assert.Contains(">9<", cut.Markup); // BufferedCount
|
||||
Assert.Contains(">5<", cut.Markup); // StuckCount
|
||||
Assert.Contains(">2<", cut.Markup); // ParkedCount
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RendersLinkToTheSiteCallsReportPage()
|
||||
{
|
||||
var cut = Render<HealthPage>();
|
||||
var link = cut.Find("a[href='/site-calls/report']");
|
||||
Assert.Contains("View details", link.TextContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteCallKpiFailure_ShowsGracefulFallback()
|
||||
{
|
||||
_siteCallKpiReply = new SiteCallKpiResponse(
|
||||
"k", false, "site call repository unavailable", 0, 0, 0, 0, null, 0);
|
||||
|
||||
var cut = Render<HealthPage>();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
// Failure must not crash the page; tiles fall back to a dash and the
|
||||
// inline error message surfaces.
|
||||
Assert.Contains("Site Calls", cut.Markup);
|
||||
Assert.Contains("Site Call KPIs unavailable", cut.Markup);
|
||||
Assert.Contains("site call repository unavailable", cut.Markup);
|
||||
Assert.Contains(">—<", cut.Markup);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OutboxKpiFailure_ShowsGracefulFallback()
|
||||
{
|
||||
@@ -170,4 +228,16 @@ public class HealthPageTests : BunitContext
|
||||
Receive<NotificationKpiRequest>(_ => Sender.Tell(test._kpiReply));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stand-in for the Site Call Audit actor. Replies to the KPI request with
|
||||
/// the test's currently-scripted response.
|
||||
/// </summary>
|
||||
private sealed class ScriptedSiteCallAuditActor : ReceiveActor
|
||||
{
|
||||
public ScriptedSiteCallAuditActor(HealthPageTests test)
|
||||
{
|
||||
Receive<SiteCallKpiRequest>(_ => Sender.Tell(test._siteCallKpiReply));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user