Validate audit windows and isolate dashboard count reads
This commit is contained in:
+71
-14
@@ -57,6 +57,63 @@ public class AuditFilterBarTests : BunitContext
|
||||
Services.AddSingleton(_auditLogQueryService);
|
||||
}
|
||||
|
||||
/// <summary>UTC-labelled custom picks are identical in every process timezone.</summary>
|
||||
[Theory]
|
||||
[InlineData("2026-11-12T10:00", "2026-11-12T11:00")]
|
||||
[InlineData("2026-03-08T01:30", "2026-03-08T02:30")]
|
||||
[InlineData("2026-11-01T01:30", "2026-11-01T02:30")]
|
||||
public void CustomUtcWindow_PreservesLiteralInstantsAndInputText(string from, string to)
|
||||
{
|
||||
AuditLogQueryFilter? captured = null;
|
||||
var cut = Render<AuditFilterBar>(p => p.Add(c => c.OnFilterChanged, f => captured = f));
|
||||
cut.Find("#audit-time-range").Change(AuditTimeRangePreset.Custom.ToString());
|
||||
cut.Find("#audit-from").Change(from); cut.Find("#audit-to").Change(to);
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(DateTime.SpecifyKind(DateTime.Parse(from, System.Globalization.CultureInfo.InvariantCulture), DateTimeKind.Utc), captured.FromUtc);
|
||||
Assert.Equal(DateTime.SpecifyKind(DateTime.Parse(to, System.Globalization.CultureInfo.InvariantCulture), DateTimeKind.Utc), captured.ToUtc);
|
||||
Assert.Equal(from, cut.Find("#audit-from").GetAttribute("value"));
|
||||
Assert.Equal(to, cut.Find("#audit-to").GetAttribute("value"));
|
||||
}
|
||||
|
||||
/// <summary>Intentional nullable bounds retain the existing open-ended query contract.</summary>
|
||||
[Theory]
|
||||
[InlineData("", "2026-11-12T11:00")]
|
||||
[InlineData("2026-11-12T10:00", "")]
|
||||
[InlineData("", "")]
|
||||
public void CustomUtcWindow_EmptyBoundsRemainIntentional(string from, string to)
|
||||
{
|
||||
AuditLogQueryFilter? captured = null;
|
||||
var cut = Render<AuditFilterBar>(p => p.Add(c => c.OnFilterChanged, f => captured = f));
|
||||
cut.Find("#audit-time-range").Change(AuditTimeRangePreset.Custom.ToString());
|
||||
cut.Find("#audit-from").Change(from); cut.Find("#audit-to").Change(to);
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(string.IsNullOrEmpty(from), captured.FromUtc is null);
|
||||
Assert.Equal(string.IsNullOrEmpty(to), captured.ToUtc is null);
|
||||
}
|
||||
|
||||
/// <summary>Bad ranges retain correction text without emitting a broader query.</summary>
|
||||
[Theory]
|
||||
[InlineData("not-a-date", "2026-11-12T11:00")]
|
||||
[InlineData("2026-11-12T12:00", "2026-11-12T11:00")]
|
||||
public void InvalidCustomWindow_DoesNotQueryUntilCorrected(string from, string to)
|
||||
{
|
||||
var queries = 0;
|
||||
var cut = Render<AuditFilterBar>(p => p.Add(c => c.OnFilterChanged, _ => queries++));
|
||||
cut.Find("#audit-time-range").Change(AuditTimeRangePreset.Custom.ToString());
|
||||
cut.Find("#audit-from").Change(from); cut.Find("#audit-to").Change(to);
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.Equal(0, queries);
|
||||
Assert.Equal(from, cut.Find("#audit-from").GetAttribute("value"));
|
||||
Assert.Equal("true", cut.Find("#audit-from").GetAttribute("aria-invalid"));
|
||||
Assert.NotEmpty(cut.Find("#" + cut.Find("#audit-from").GetAttribute("aria-describedby")).TextContent);
|
||||
cut.Find("#audit-from").Change("2026-11-12T10:00");
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.Equal(1, queries);
|
||||
Assert.Null(cut.Find("#audit-from").GetAttribute("aria-invalid"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the filter bar renders all ten filter elements plus the errors-only toggle.</summary>
|
||||
[Fact]
|
||||
public void Render_AllTenElements_Plus_ErrorsOnlyToggle_Present()
|
||||
@@ -99,7 +156,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
// Drive UI: pick a Channel, type in the Target search box, click Apply.
|
||||
cut.Find("[data-test=\"filter-channel-select\"]").Change("ApiOutbound");
|
||||
cut.Find("[data-test=\"filter-target\"] input").Change("Plant-A-OPC");
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(new[] { AuditChannel.ApiOutbound }, captured!.Channels);
|
||||
@@ -118,14 +175,14 @@ public class AuditFilterBarTests : BunitContext
|
||||
|
||||
cut.Find("[data-test=\"filter-channel-select\"]").Change("ApiOutbound");
|
||||
cut.Find("[data-test=\"filter-channel-select\"]").Change("Notification");
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(new[] { AuditChannel.Notification }, captured!.Channels);
|
||||
|
||||
// Selecting "All channels" clears the channel filter entirely.
|
||||
cut.Find("[data-test=\"filter-channel-select\"]").Change(string.Empty);
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.Null(captured!.Channels);
|
||||
}
|
||||
|
||||
@@ -164,7 +221,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
|
||||
// Toggle Errors-only ON, leaving Status chips empty.
|
||||
cut.Find("[data-test=\"filter-errors-only\"] input").Change(true);
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
// Errors-only targets the full non-success set {Failed, Parked, Discarded}.
|
||||
@@ -176,7 +233,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
|
||||
// Now pin an explicit Status option — Errors-only must yield (explicit wins).
|
||||
cut.Find("[data-test=\"filter-status-ms-opt-Delivered\"]").Change(true);
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.Equal(new[] { AuditStatus.Delivered }, captured!.Statuses);
|
||||
}
|
||||
@@ -199,7 +256,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
Assert.Contains("data-test=\"filter-node-ms-opt-central-b\"", cut.Markup);
|
||||
|
||||
cut.Find("[data-test=\"filter-node-ms-opt-central-a\"]").Change(true);
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.NotNull(captured!.SourceNodes);
|
||||
@@ -218,7 +275,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
|
||||
cut.Find("[data-test=\"filter-status-ms-opt-Delivered\"]").Change(true);
|
||||
cut.Find("[data-test=\"filter-status-ms-opt-Failed\"]").Change(true);
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.NotNull(captured!.Statuses);
|
||||
@@ -239,7 +296,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
.Add(c => c.OnFilterChanged, EventCallback.Factory.Create<AuditLogQueryFilter>(this, f => captured = f)));
|
||||
|
||||
cut.Find("[data-test=\"filter-execution-id\"] input").Change(executionId.ToString());
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(executionId, captured!.ExecutionId);
|
||||
@@ -255,13 +312,13 @@ public class AuditFilterBarTests : BunitContext
|
||||
.Add(c => c.OnFilterChanged, EventCallback.Factory.Create<AuditLogQueryFilter>(this, f => captured = f)));
|
||||
|
||||
// Blank — never typed into.
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.NotNull(captured);
|
||||
Assert.Null(captured!.ExecutionId);
|
||||
|
||||
// Unparseable paste — still dropped, no error.
|
||||
cut.Find("[data-test=\"filter-execution-id\"] input").Change("not-a-guid");
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.Null(captured!.ExecutionId);
|
||||
}
|
||||
|
||||
@@ -277,7 +334,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
.Add(c => c.OnFilterChanged, EventCallback.Factory.Create<AuditLogQueryFilter>(this, f => captured = f)));
|
||||
|
||||
cut.Find("[data-test=\"filter-parent-execution-id\"] input").Change(parentExecutionId.ToString());
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(parentExecutionId, captured!.ParentExecutionId);
|
||||
@@ -293,13 +350,13 @@ public class AuditFilterBarTests : BunitContext
|
||||
.Add(c => c.OnFilterChanged, EventCallback.Factory.Create<AuditLogQueryFilter>(this, f => captured = f)));
|
||||
|
||||
// Blank — never typed into.
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.NotNull(captured);
|
||||
Assert.Null(captured!.ParentExecutionId);
|
||||
|
||||
// Unparseable paste — still dropped, no error.
|
||||
cut.Find("[data-test=\"filter-parent-execution-id\"] input").Change("not-a-guid");
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
Assert.Null(captured!.ParentExecutionId);
|
||||
}
|
||||
|
||||
@@ -313,7 +370,7 @@ public class AuditFilterBarTests : BunitContext
|
||||
|
||||
// LastHour is the default preset; clicking Apply must collapse it to FromUtc.
|
||||
var before = DateTime.UtcNow;
|
||||
cut.Find("[data-test=\"filter-apply\"]").Click();
|
||||
cut.Find("form[data-test=audit-filter-bar]").Submit();
|
||||
var after = DateTime.UtcNow;
|
||||
|
||||
Assert.NotNull(captured);
|
||||
|
||||
Reference in New Issue
Block a user