using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections; using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.DataConnections; /// H4 diagnostics display (plan §6) and the X0 dropped-bit rendering (#919) on the data-connections page. [Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H4")] public sealed class GrpcDataHistoryDiagnosticsDisplayTests { private static DataConnectionDiagnosticsSnapshot Row() => new("link", 1, "ready", null, null, 0, 0, 1, "artifact", DateTime.UtcNow); [Fact] public void Negotiated_features_distinguish_unavailable_v1_and_history() { DataConnectionDiagnostics.Features(null).ShouldBe("unavailable"); DataConnectionDiagnostics.Features(DataFeatures.None).ShouldBe("none (v1 behaviour)"); DataConnectionDiagnostics.Features(DataFeatures.History).ShouldBe("History"); DataConnectionDiagnostics.Features(DataFeatures.History | DataFeatures.Conditions).ShouldBe("History, Conditions"); } [Fact] public void Origin_history_shows_the_advertised_variants_and_aggregate_count() { DataConnectionDiagnostics.HistoryServed(Row()).ShouldBe("not advertised"); DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = [] }).ShouldBe("advertised, no variant granted"); DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = ["raw", "processed", "attime"], HistoryAggregateCount = 12 }) .ShouldBe("raw, processed, attime (12 aggregates)"); } [Fact] public void History_counts_by_status_class_are_unavailable_from_an_older_node_not_zero() { DataConnectionDiagnostics.HistoryCounts(null, null, null).ShouldBe("unavailable"); DataConnectionDiagnostics.HistoryCounts(5, 0, 2).ShouldBe("good 5 · uncertain 0 · bad 2"); } [Fact] public void Dropped_bits_are_named_when_known_and_hex_when_not() { DataConnectionDiagnostics.DroppedBits(null).ShouldBe("unavailable"); DataConnectionDiagnostics.DroppedBits(DataOperations.None).ShouldBe("none"); DataConnectionDiagnostics.DroppedBits(DataOperations.HistoryRead | DataOperations.AlarmSubscribe).ShouldBe("HistoryRead, AlarmSubscribe"); DataConnectionDiagnostics.DroppedBits((DataOperations)(1 << 20)).ShouldBe("0x100000"); } [Fact] public void The_older_build_hint_shows_only_when_something_was_dropped() { DataConnectionDiagnostics.HasDrops(null).ShouldBeFalse(); DataConnectionDiagnostics.HasDrops(DataOperations.None, 0).ShouldBeFalse(); DataConnectionDiagnostics.HasDrops(DataOperations.HistoryRead).ShouldBeTrue(); DataConnectionDiagnostics.HasDrops(DataOperations.None, 2).ShouldBeTrue("a mapping's drop counts even when the connection dropped none"); } }