feat(adminui): editable TwinCAT device + tag lists via CollectionEditor
This commit is contained in:
+124
-1
@@ -84,7 +84,7 @@ public sealed class TwinCATDriverPageFormSerializationTests
|
||||
|
||||
var form = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.FormModel.FromOptions(opts);
|
||||
var roundTripped = form.ToOptions();
|
||||
var roundTripped = form.ToOptions([], []);
|
||||
|
||||
roundTripped.Timeout.ShouldBe(TimeSpan.FromSeconds(3));
|
||||
roundTripped.UseNativeNotifications.ShouldBeTrue();
|
||||
@@ -95,4 +95,127 @@ public sealed class TwinCATDriverPageFormSerializationTests
|
||||
roundTripped.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(2));
|
||||
roundTripped.ProbeTimeoutSeconds.ShouldBe(15);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_RoundTrip_PreservesEditableFields()
|
||||
{
|
||||
var def = new TwinCATDeviceOptions("192.168.0.1.1.1:851", "PLC1");
|
||||
|
||||
var row = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATDeviceRow.FromDefinition(def);
|
||||
var back = row.ToDefinition();
|
||||
|
||||
back.HostAddress.ShouldBe("192.168.0.1.1.1:851");
|
||||
back.DeviceName.ShouldBe("PLC1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_CarriesThroughUneditedSourceFields()
|
||||
{
|
||||
// Edit only DeviceName; HostAddress on the source must survive the round-trip via _source.
|
||||
var def = new TwinCATDeviceOptions("10.0.0.5.1.1:851", "Original");
|
||||
|
||||
var row = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATDeviceRow.FromDefinition(def);
|
||||
row.DeviceName = "Renamed";
|
||||
var back = row.ToDefinition();
|
||||
|
||||
back.HostAddress.ShouldBe("10.0.0.5.1.1:851");
|
||||
back.DeviceName.ShouldBe("Renamed");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_ValidateRow_RejectsDuplicateHostAddress()
|
||||
{
|
||||
var existing = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATDeviceRow.FromDefinition(new TwinCATDeviceOptions("192.168.0.1.1.1:851"));
|
||||
var dup = new ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATDeviceRow { HostAddress = "192.168.0.1.1.1:851" };
|
||||
|
||||
var all = new[] { existing, dup };
|
||||
var error = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATDeviceRow.ValidateRow(dup, all, editIndex: 1);
|
||||
|
||||
error.ShouldNotBeNull();
|
||||
error.ShouldContain("Duplicate");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_RoundTrip_PreservesEditableFields()
|
||||
{
|
||||
var def = new TwinCATTagDefinition("Speed", "192.168.0.1.1.1:851", "MAIN.rSpeed", TwinCATDataType.Real, Writable: false);
|
||||
|
||||
var row = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATTagRow.FromDefinition(def);
|
||||
var back = row.ToDefinition();
|
||||
|
||||
back.Name.ShouldBe("Speed");
|
||||
back.DeviceHostAddress.ShouldBe("192.168.0.1.1.1:851");
|
||||
back.SymbolPath.ShouldBe("MAIN.rSpeed");
|
||||
back.DataType.ShouldBe(TwinCATDataType.Real);
|
||||
back.Writable.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_CarriesThroughUneditedWriteIdempotent()
|
||||
{
|
||||
// WriteIdempotent is not exposed by the editor; it must survive a load→edit→save via _source.
|
||||
var def = new TwinCATTagDefinition("Cmd", "192.168.0.1.1.1:851", "GVL.Start", TwinCATDataType.Bool,
|
||||
Writable: true, WriteIdempotent: true);
|
||||
|
||||
var row = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATTagRow.FromDefinition(def);
|
||||
row.Name = "CmdRenamed"; // touch an edited field
|
||||
var back = row.ToDefinition();
|
||||
|
||||
back.Name.ShouldBe("CmdRenamed");
|
||||
back.WriteIdempotent.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_ValidateRow_RejectsDuplicateName()
|
||||
{
|
||||
var existing = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATTagRow.FromDefinition(
|
||||
new TwinCATTagDefinition("Speed", "192.168.0.1.1.1:851", "MAIN.rSpeed", TwinCATDataType.Real));
|
||||
var dup = new ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATTagRow { Name = "SPEED" }; // case-insensitive collision
|
||||
|
||||
var all = new[] { existing, dup };
|
||||
var error = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.TwinCATTagRow.ValidateRow(dup, all, editIndex: 1);
|
||||
|
||||
error.ShouldNotBeNull();
|
||||
error.ShouldContain("Duplicate");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormModel_ToOptions_SerializesDeviceAndTagLists()
|
||||
{
|
||||
var form = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.TwinCATDriverPage.FormModel.FromOptions(new TwinCATDriverOptions());
|
||||
|
||||
var devices = new[] { new TwinCATDeviceOptions("192.168.0.1.1.1:851", "PLC1") };
|
||||
var tags = new[]
|
||||
{
|
||||
new TwinCATTagDefinition("Speed", "192.168.0.1.1.1:851", "MAIN.rSpeed", TwinCATDataType.Real,
|
||||
Writable: true, WriteIdempotent: true),
|
||||
};
|
||||
|
||||
var opts = form.ToOptions(devices, tags);
|
||||
var json = JsonSerializer.Serialize(opts, _opts);
|
||||
var back = JsonSerializer.Deserialize<TwinCATDriverOptions>(json, _opts);
|
||||
|
||||
back.ShouldNotBeNull();
|
||||
back.Devices.Count.ShouldBe(1);
|
||||
back.Devices[0].HostAddress.ShouldBe("192.168.0.1.1.1:851");
|
||||
back.Devices[0].DeviceName.ShouldBe("PLC1");
|
||||
back.Tags.Count.ShouldBe(1);
|
||||
back.Tags[0].Name.ShouldBe("Speed");
|
||||
back.Tags[0].DeviceHostAddress.ShouldBe("192.168.0.1.1.1:851");
|
||||
back.Tags[0].SymbolPath.ShouldBe("MAIN.rSpeed");
|
||||
back.Tags[0].DataType.ShouldBe(TwinCATDataType.Real);
|
||||
back.Tags[0].Writable.ShouldBeTrue();
|
||||
back.Tags[0].WriteIdempotent.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user