using Bunit; using Marathon.UI.Components; using Marathon.UI.Services; using Marathon.UI.Tests.Support; namespace Marathon.UI.Tests.Components; public sealed class SeverityBadgeTests : MarathonTestContext { [Theory] [InlineData(0.30, AnomalySeverity.Low)] [InlineData(0.44, AnomalySeverity.Low)] [InlineData(0.45, AnomalySeverity.Medium)] [InlineData(0.59, AnomalySeverity.Medium)] [InlineData(0.60, AnomalySeverity.High)] [InlineData(0.95, AnomalySeverity.High)] public void From_score_buckets_correctly(double score, AnomalySeverity expected) { AnomalySeverityRules.FromScore((decimal)score).Should().Be(expected); } [Fact] public void Renders_high_severity_pill_with_anomaly_class() { var cut = RenderComponent(p => p .Add(b => b.Severity, AnomalySeverity.High) .Add(b => b.Score, 0.72m)); var pill = cut.Find("[data-test=severity-badge]"); pill.GetAttribute("class").Should().Contain("m-severity--high"); cut.Markup.Should().Contain("Anomaly.Severity.High"); cut.Markup.Should().Contain("0.72"); } [Fact] public void Renders_medium_severity_pill_with_amber_accent_class() { var cut = RenderComponent(p => p .Add(b => b.Severity, AnomalySeverity.Medium) .Add(b => b.Score, 0.50m)); var pill = cut.Find("[data-test=severity-badge]"); pill.GetAttribute("class").Should().Contain("m-severity--medium"); cut.Markup.Should().Contain("Anomaly.Severity.Medium"); } [Fact] public void Renders_low_severity_pill_with_neutral_class() { var cut = RenderComponent(p => p .Add(b => b.Severity, AnomalySeverity.Low) .Add(b => b.Score, 0.32m)); var pill = cut.Find("[data-test=severity-badge]"); pill.GetAttribute("class").Should().Contain("m-severity--low"); cut.Markup.Should().Contain("Anomaly.Severity.Low"); } [Fact] public void Hides_score_when_disabled() { var cut = RenderComponent(p => p .Add(b => b.Severity, AnomalySeverity.High) .Add(b => b.Score, 0.81m) .Add(b => b.ShowScore, false)); cut.Markup.Should().NotContain("0.81"); } }