feat(adminui): editable AbCip device + tag lists via CollectionEditor
This commit is contained in:
+113
@@ -2,6 +2,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
|
||||
@@ -14,6 +15,12 @@ public sealed class AbCipDriverPageFormSerializationTests
|
||||
WriteIndented = false,
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions TestJsonOpts = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_PreservesKnownFields()
|
||||
{
|
||||
@@ -78,4 +85,110 @@ public sealed class AbCipDriverPageFormSerializationTests
|
||||
back.ShouldNotBeNull();
|
||||
back.ProbeTimeoutSeconds.ShouldBe(10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_round_trips_through_definition()
|
||||
{
|
||||
var row = new AbCipDriverPage.AbCipDeviceRow
|
||||
{
|
||||
HostAddress = "ab://10.0.0.1/1,0", PlcFamily = AbCipPlcFamily.CompactLogix, DeviceName = "PLC-A",
|
||||
};
|
||||
var def = row.ToDefinition();
|
||||
var back = AbCipDriverPage.AbCipDeviceRow.FromDefinition(def);
|
||||
|
||||
back.HostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
||||
back.PlcFamily.ShouldBe(AbCipPlcFamily.CompactLogix);
|
||||
back.DeviceName.ShouldBe("PLC-A");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_preserves_unedited_fields()
|
||||
{
|
||||
var original = new AbCipDeviceOptions(
|
||||
"ab://10.0.0.1/1,0", AbCipPlcFamily.ControlLogix, "PLC-A",
|
||||
AllowPacking: true, ConnectionSize: 4002);
|
||||
var row = AbCipDriverPage.AbCipDeviceRow.FromDefinition(original);
|
||||
row.HostAddress = "ab://10.0.0.2/1,0";
|
||||
|
||||
var back = row.ToDefinition();
|
||||
back.HostAddress.ShouldBe("ab://10.0.0.2/1,0");
|
||||
back.AllowPacking.ShouldBe(true);
|
||||
back.ConnectionSize.ShouldBe(4002);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_round_trips_through_definition()
|
||||
{
|
||||
var row = new AbCipDriverPage.AbCipTagRow
|
||||
{
|
||||
Name = "Speed", DeviceHostAddress = "ab://10.0.0.1/1,0", TagPath = "Motor1.Speed",
|
||||
DataType = AbCipDataType.Real, Writable = true,
|
||||
};
|
||||
var def = row.ToDefinition();
|
||||
var back = AbCipDriverPage.AbCipTagRow.FromDefinition(def);
|
||||
|
||||
back.Name.ShouldBe("Speed");
|
||||
back.DeviceHostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
||||
back.TagPath.ShouldBe("Motor1.Speed");
|
||||
back.DataType.ShouldBe(AbCipDataType.Real);
|
||||
back.Writable.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_preserves_unedited_fields()
|
||||
{
|
||||
var original = new AbCipTagDefinition(
|
||||
"Speed", "ab://10.0.0.1/1,0", "Motor1.Speed", AbCipDataType.Structure,
|
||||
Writable: true, WriteIdempotent: true,
|
||||
Members: [new AbCipStructureMember("Sub", AbCipDataType.DInt)],
|
||||
SafetyTag: true);
|
||||
var row = AbCipDriverPage.AbCipTagRow.FromDefinition(original);
|
||||
row.Name = "Renamed";
|
||||
|
||||
var back = row.ToDefinition();
|
||||
back.Name.ShouldBe("Renamed");
|
||||
back.WriteIdempotent.ShouldBeTrue();
|
||||
back.SafetyTag.ShouldBeTrue();
|
||||
back.Members.ShouldNotBeNull();
|
||||
back.Members!.Count.ShouldBe(1);
|
||||
back.Members[0].Name.ShouldBe("Sub");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateDeviceRow_rejects_duplicate_host()
|
||||
{
|
||||
var rows = new List<AbCipDriverPage.AbCipDeviceRow> { new() { HostAddress = "ab://10.0.0.1/1,0" } };
|
||||
AbCipDriverPage.AbCipDeviceRow.ValidateRow(new() { HostAddress = "ab://10.0.0.1/1,0" }, rows, null)
|
||||
.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateTagRow_rejects_duplicate_name()
|
||||
{
|
||||
var rows = new List<AbCipDriverPage.AbCipTagRow> { new() { Name = "Speed" } };
|
||||
AbCipDriverPage.AbCipTagRow.ValidateRow(new() { Name = "Speed" }, rows, null)
|
||||
.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Device_and_tag_lists_survive_options_serialize_round_trip()
|
||||
{
|
||||
var devices = new List<AbCipDeviceOptions>
|
||||
{
|
||||
new("ab://10.0.0.1/1,0", AbCipPlcFamily.ControlLogix, "PLC-1"),
|
||||
new("ab://10.0.0.2/1,0", AbCipPlcFamily.CompactLogix, "PLC-2"),
|
||||
};
|
||||
var tags = new List<AbCipTagDefinition>
|
||||
{
|
||||
new("Speed", "ab://10.0.0.1/1,0", "Motor1.Speed", AbCipDataType.Real),
|
||||
new("Run", "ab://10.0.0.2/1,0", "Motor2.Run", AbCipDataType.Bool),
|
||||
};
|
||||
var opts = new AbCipDriverPage.FormModel().ToOptions(devices, tags);
|
||||
var json = JsonSerializer.Serialize(opts, TestJsonOpts);
|
||||
var back = JsonSerializer.Deserialize<AbCipDriverOptions>(json, TestJsonOpts)!;
|
||||
back.Devices.Count.ShouldBe(2);
|
||||
back.Devices[0].HostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
||||
back.Tags.Count.ShouldBe(2);
|
||||
back.Tags[0].Name.ShouldBe("Speed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user