using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Deployment; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Deployment; /// /// MES reportable (tri-state) on the Instance Configure alarm-override editor. /// /// The instance-level override is a bool?: null means "inherit the /// template alarm's IsMesReportable", true/false pin it. The modal surfaces /// that as a three-option select (Inherited / Reportable / Not reportable). /// /// InstanceConfigure is a heavyweight page (~7 injected services with /// their own graphs), so — consistent with the rest of this suite's coverage of it /// (see InstanceConfigureListOverrideTests) — the markup half is a structural /// assertion over the component source. The half that carries the real risk is the /// save-time delta rule, which is extracted as a pure helper and pinned directly: /// the page DELETES the override when it sees no delta, so a reportable-only /// override would be silently dropped on save if the new term were missing. /// public class InstanceConfigureMesReportableTests { private static string DeploymentComponentsRoot { get { var dir = AppContext.BaseDirectory; for (var i = 0; i < 6 && dir is not null; i++) dir = Directory.GetParent(dir)?.FullName; return Path.Combine(dir!, "src", "ZB.MOM.WW.ScadaBridge.CentralUI", "Components", "Pages", "Deployment"); } } private static string InstanceConfigureMarkup => File.ReadAllText(Path.Combine(DeploymentComponentsRoot, "InstanceConfigure.razor")); [Fact] public void OverrideModal_HasTriStateMesReportableSelect() { var markup = InstanceConfigureMarkup; Assert.Contains("data-test=\"alarm-mes-select\"", markup); // Three options: Inherited (empty value) / Reportable (true) / Not reportable (false). var selectStart = markup.IndexOf("data-test=\"alarm-mes-select\"", StringComparison.Ordinal); var selectEnd = markup.IndexOf("", selectStart, StringComparison.Ordinal); Assert.True(selectEnd > selectStart, "MES reportable select is not closed."); // Label mirrors the adjacent "Priority override" control. Assert.Contains("MES reportable override", markup); var selectBody = markup[selectStart..selectEnd]; var optionCount = selectBody.Split(" Assert.True(InstanceConfigure.HasOverrideDelta(overrideJson, priority, mesReportable)); [Theory] [InlineData(null, null, null)] [InlineData("", null, null)] [InlineData(" ", null, null)] public void HasOverrideDelta_NothingSet_IsNotADelta( string? overrideJson, int? priority, bool? mesReportable) => Assert.False(InstanceConfigure.HasOverrideDelta(overrideJson, priority, mesReportable)); [Theory] [InlineData("{\"hi\":70}", null, null)] [InlineData(null, 750, null)] public void HasOverrideDelta_ExistingTermsStillCount( string? overrideJson, int? priority, bool? mesReportable) => Assert.True(InstanceConfigure.HasOverrideDelta(overrideJson, priority, mesReportable)); }