fix(centralui): enable Test Bindings for MxGateway connections

The Test Bindings button was disabled (greyed out) for any attribute bound
to a non-OPC-UA connection. BuildTestableRows() filtered to protocol ==
"OpcUa", a stale gate left over from when OPC UA was the only protocol.
ReadTagValuesCommand is protocol-agnostic (routes through
IDataConnection.ReadBatchAsync, which MxGatewayDataConnection implements),
so the filter only blocked the UI — mirroring the already-fixed IsBrowsable.

Remove the OPC-UA-only filter and update the stale comments. Add a bUnit
regression test (theory over MxGateway + OpcUa) asserting the button is
enabled for a readable-protocol binding.

Verified live: dialog opens for an MxGateway binding and returns a
Good-quality read.
This commit is contained in:
Joseph Doherty
2026-05-29 12:26:46 -04:00
parent 4b6ff49822
commit 4881f9c23c
2 changed files with 72 additions and 9 deletions
@@ -158,9 +158,10 @@
<button class="btn btn-success btn-sm" @onclick="SaveBindings" disabled="@_saving">Save Bindings</button>
@* Test Bindings: one-shot live read of every bound attribute
whose row has a connection picked AND an effective tag
path. Disabled when no testable rows. Currently OPC UA
only — other protocols (none yet) would need their own
wire+adapter support to round-trip through ReadTagValuesCommand. *@
path. Disabled when no testable rows. Protocol-agnostic —
any connection whose adapter implements ReadBatchAsync
(OPC UA and MxGateway today) round-trips through
ReadTagValuesCommand. *@
<button class="btn btn-outline-primary btn-sm"
@onclick="OpenTestBindings"
disabled="@(!HasTestableBindings())">
@@ -612,8 +613,10 @@
/// <summary>
/// Builds the list of testable rows: attributes that have a connection
/// picked AND a non-empty effective tag path AND an OPC UA connection
/// (the only protocol routed through <c>ReadTagValuesCommand</c> today).
/// picked AND a non-empty effective tag path. Protocol-agnostic — every
/// data-connection adapter implements <c>ReadBatchAsync</c>, so the read
/// routes through <c>ReadTagValuesCommand</c> regardless of protocol
/// (OPC UA and MxGateway today).
/// </summary>
private List<TestBindingsDialog.BindingRowToTest> BuildTestableRows()
{
@@ -626,10 +629,11 @@
var conn = _siteConnections.FirstOrDefault(c => c.Id == connId);
if (conn is null) continue;
// OPC UA only — other protocols don't have a site-side
// ReadTagValuesCommand handler wired up yet.
if (!string.Equals(conn.Protocol, "OpcUa", StringComparison.OrdinalIgnoreCase))
continue;
// Protocol-agnostic: ReadTagValuesCommand routes through the
// site-side IDataConnection.ReadBatchAsync contract, which every
// adapter implements (OPC UA and MxGateway today). A not-connected
// or unsupported connection short-circuits to a typed banner in the
// dialog rather than being filtered out here — mirrors IsBrowsable.
var effectivePath = _bindingOverrides.GetValueOrDefault(attr.Name)
?? GetTemplateDefault(attr.Name);
@@ -104,4 +104,63 @@ public class InstanceConfigureAuditDrillinTests : BunitContext
Assert.Contains("Recent audit activity", link.TextContent);
});
}
/// <summary>
/// Regression: the Test Bindings button must be enabled for an attribute
/// bound to an MxGateway connection. The site-side ReadTagValuesCommand
/// path is protocol-agnostic (routes through IDataConnection.ReadBatchAsync,
/// which MxGateway implements), so the UI must not gate the button on
/// protocol == "OpcUa". Previously BuildTestableRows filtered to OPC UA
/// only, leaving the button greyed for MxGateway bindings.
/// </summary>
[Theory]
[InlineData("MxGateway")]
[InlineData("OpcUa")]
public void TestBindingsButton_Enabled_ForReadableProtocol(string protocol)
{
var instance = new Instance("Pump-42")
{
Id = 42,
TemplateId = 1,
SiteId = 1,
State = ZB.MOM.WW.ScadaBridge.Commons.Types.Enums.InstanceState.NotDeployed,
};
_templateRepo.GetInstanceByIdAsync(42, Arg.Any<CancellationToken>()).Returns(instance);
_templateRepo.GetTemplateByIdAsync(1, Arg.Any<CancellationToken>())
.Returns(new Template("Pump") { Id = 1 });
_siteRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
.Returns(new List<Site> { new("Plant A", "plant-a") { Id = 1 } });
_templateRepo.GetAreasBySiteIdAsync(1, Arg.Any<CancellationToken>())
.Returns(new List<Area>());
// One data-sourced attribute (non-empty DataSourceReference => testable row).
_templateRepo.GetAttributesByTemplateIdAsync(1, Arg.Any<CancellationToken>())
.Returns(new List<TemplateAttribute>
{
new("Speed") { Id = 1, DataSourceReference = "TestMachine_001.TestHistoryValue" },
});
// A connection on the attribute's chosen protocol.
_siteRepo.GetDataConnectionsBySiteIdAsync(1, Arg.Any<CancellationToken>())
.Returns(new List<DataConnection> { new("Shared", protocol, 1) { Id = 7 } });
_templateRepo.GetBindingsByInstanceIdAsync(42, Arg.Any<CancellationToken>())
.Returns(new List<InstanceConnectionBinding>
{
new("Speed") { Id = 1, InstanceId = 42, DataConnectionId = 7 },
});
_templateRepo.GetOverridesByInstanceIdAsync(42, Arg.Any<CancellationToken>())
.Returns(new List<InstanceAttributeOverride>());
_templateRepo.GetAlarmsByTemplateIdAsync(1, Arg.Any<CancellationToken>())
.Returns(new List<TemplateAlarm>());
_templateRepo.GetAlarmOverridesByInstanceIdAsync(42, Arg.Any<CancellationToken>())
.Returns(new List<InstanceAlarmOverride>());
var cut = Render<InstanceConfigurePage>(p => p.Add(c => c.Id, 42));
cut.WaitForAssertion(() =>
{
var testButton = cut.FindAll("button").Single(b => b.TextContent.Trim() == "Test Bindings");
Assert.False(testButton.HasAttribute("disabled"),
$"Test Bindings should be enabled for a {protocol} binding.");
});
}
}