fix(health-monitoring): resolve HealthMonitoring-015 — nullable LastReportReceivedAt
A heartbeat-registered site that has never sent a full report now has
LastReportReceivedAt = null instead of the year-0001 sentinel. TimestampDisplay
accepts DateTimeOffset? and renders null as a placeholder ('awaiting first
report') rather than a ~2000-year-stale date. Cross-module: HealthMonitoring +
CentralUI.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Bunit;
|
||||
using ScadaLink.CentralUI.Components.Shared;
|
||||
|
||||
namespace ScadaLink.CentralUI.Tests.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for HealthMonitoring-015. A heartbeat-only registered site has
|
||||
/// a <c>null</c> <c>LastReportReceivedAt</c> ("no full report yet"). The health
|
||||
/// dashboard passes that value straight into <see cref="TimestampDisplay"/>, so the
|
||||
/// component's <c>Value</c> must accept <c>DateTimeOffset?</c> and render a
|
||||
/// <c>null</c> as a human-readable placeholder ("never") instead of the
|
||||
/// <c>DateTimeOffset.MinValue</c> year-0001 sentinel. Non-null callers must keep
|
||||
/// rendering the formatted timestamp exactly as before.
|
||||
/// </summary>
|
||||
public class TimestampDisplayTests : BunitContext
|
||||
{
|
||||
[Fact]
|
||||
public void Render_NonNullValue_ShowsFormattedTimestamp()
|
||||
{
|
||||
var value = new DateTimeOffset(2026, 5, 17, 14, 30, 45, TimeSpan.Zero);
|
||||
|
||||
var cut = Render<TimestampDisplay>(parameters => parameters
|
||||
.Add(p => p.Value, (DateTimeOffset?)value)
|
||||
.Add(p => p.Format, "HH:mm:ss"));
|
||||
|
||||
var span = cut.Find("span");
|
||||
Assert.Equal(value.LocalDateTime.ToString("HH:mm:ss"), span.TextContent.Trim());
|
||||
Assert.Contains("2026-05-17 14:30:45 UTC", span.GetAttribute("title")!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Render_NullValue_ShowsNeverPlaceholder()
|
||||
{
|
||||
var cut = Render<TimestampDisplay>(parameters => parameters
|
||||
.Add(p => p.Value, (DateTimeOffset?)null)
|
||||
.Add(p => p.Format, "HH:mm:ss"));
|
||||
|
||||
Assert.Contains("never", cut.Markup, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Render_NullValue_DoesNotRenderYear0001Sentinel()
|
||||
{
|
||||
var cut = Render<TimestampDisplay>(parameters => parameters
|
||||
.Add(p => p.Value, (DateTimeOffset?)null));
|
||||
|
||||
// The year-0001 DateTimeOffset.MinValue sentinel must never reach the UI.
|
||||
Assert.DoesNotContain("0001", cut.Markup);
|
||||
}
|
||||
}
|
||||
@@ -240,6 +240,43 @@ public class CentralHealthAggregatorTests
|
||||
Assert.Equal(now, state.LastHeartbeatAt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regression test for HealthMonitoring-015. A heartbeat-only registered site
|
||||
/// has never processed a full report, so <see cref="SiteHealthState.LastReportReceivedAt"/>
|
||||
/// must be <c>null</c> — not the <c>DateTimeOffset.MinValue</c> (year-0001)
|
||||
/// sentinel that the UI would otherwise render as a ~2000-year-stale timestamp.
|
||||
/// The "no report yet" signal must be an explicit nullable state, consistent
|
||||
/// with <see cref="SiteHealthState.LatestReport"/>.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void MarkHeartbeat_RegistersUnknownSite_WithNullLastReportReceivedAt()
|
||||
{
|
||||
_aggregator.MarkHeartbeat("site-new", _timeProvider.GetUtcNow());
|
||||
|
||||
var state = _aggregator.GetSiteState("site-new");
|
||||
Assert.NotNull(state);
|
||||
Assert.Null(state.LastReportReceivedAt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regression test for HealthMonitoring-015. Once a full report is processed
|
||||
/// for a heartbeat-registered site, <see cref="SiteHealthState.LastReportReceivedAt"/>
|
||||
/// becomes a real (non-null) instant.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ProcessReport_SetsLastReportReceivedAt_ForHeartbeatRegisteredSite()
|
||||
{
|
||||
_aggregator.MarkHeartbeat("site-new", _timeProvider.GetUtcNow());
|
||||
_timeProvider.Advance(TimeSpan.FromSeconds(5));
|
||||
var reportTime = _timeProvider.GetUtcNow();
|
||||
|
||||
_aggregator.ProcessReport(MakeReport("site-new", 1));
|
||||
|
||||
var state = _aggregator.GetSiteState("site-new");
|
||||
Assert.NotNull(state);
|
||||
Assert.Equal(reportTime, state.LastReportReceivedAt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkHeartbeat_KeepsSiteOnline_BetweenReports()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user