using Bunit;
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Health;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Monitoring;
/// Gitea #88: failure-counter badges on the Health dashboard site card.
public class SiteWriteFailureBadgesTests : BunitContext
{
private static SiteHealthReport Report(long eventLog = 0, int audit = 0, int redaction = 0) =>
new("site-a", 1, DateTimeOffset.UtcNow,
new Dictionary(),
new Dictionary(),
0, 0, new Dictionary(), 0, 0, 0, 0,
SiteAuditWriteFailures: audit,
AuditRedactionFailure: redaction,
SiteEventLogWriteFailures: eventLog);
private IRenderedComponent Render(SiteHealthReport? report, bool online = true) =>
Render(p => p.Add(c => c.Report, report).Add(c => c.IsOnline, online));
/// All-zero counters render nothing.
[Fact]
public void ZeroCounters_RenderNoBadges() =>
Assert.Empty(Render(Report()).FindAll(".badge"));
/// A missing report renders nothing.
[Fact]
public void NullReport_RendersNoBadges() =>
Assert.Empty(Render(null).FindAll(".badge"));
/// Event-log write failures raise only their own badge.
[Fact]
public void EventLogFailures_ShowOwnBadgeOnly()
{
var cut = Render(Report(eventLog: 3));
Assert.Single(cut.FindAll("[data-test='event-log-write-failures-badge']"));
Assert.Single(cut.FindAll(".badge"));
Assert.Contains("3", cut.Find("[data-test='event-log-write-failures-badge']").GetAttribute("title"));
}
/// Audit write failures raise only their own badge.
[Fact]
public void AuditWriteFailures_ShowOwnBadgeOnly()
{
var cut = Render(Report(audit: 2));
Assert.Single(cut.FindAll("[data-test='audit-write-failures-badge']"));
Assert.Single(cut.FindAll(".badge"));
}
/// Audit redaction failures raise only their own badge.
[Fact]
public void RedactionFailures_ShowOwnBadgeOnly()
{
var cut = Render(Report(redaction: 1));
Assert.Single(cut.FindAll("[data-test='audit-redaction-failures-badge']"));
Assert.Single(cut.FindAll(".badge"));
}
/// All three counters render three badges.
[Fact]
public void AllCounters_ShowThreeBadges() =>
Assert.Equal(3, Render(Report(1, 1, 1)).FindAll(".badge").Count);
/// An offline site renders no warning badges.
[Fact]
public void OfflineSite_ShowsNoBadges() =>
Assert.Empty(Render(Report(1, 1, 1), online: false).FindAll(".badge"));
}