feat(adminui): editable FOCAS device + tag lists via CollectionEditor
This commit is contained in:
+108
-1
@@ -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.FOCAS;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
|
||||
@@ -14,6 +15,12 @@ public sealed class FocasDriverPageFormSerializationTests
|
||||
WriteIndented = false,
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions TestJsonOpts = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_PreservesKnownFields()
|
||||
{
|
||||
@@ -116,7 +123,7 @@ public sealed class FocasDriverPageFormSerializationTests
|
||||
|
||||
var form = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
|
||||
.FocasDriverPage.FormModel.FromOptions(opts);
|
||||
var roundTripped = form.ToOptions();
|
||||
var roundTripped = form.ToOptions([], []);
|
||||
|
||||
roundTripped.Timeout.ShouldBe(TimeSpan.FromSeconds(4));
|
||||
roundTripped.Probe.Enabled.ShouldBeTrue();
|
||||
@@ -132,4 +139,104 @@ public sealed class FocasDriverPageFormSerializationTests
|
||||
roundTripped.FixedTree.ProgramPollInterval.ShouldBe(TimeSpan.FromSeconds(5));
|
||||
roundTripped.FixedTree.TimerPollInterval.ShouldBe(TimeSpan.FromSeconds(45));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_round_trips_through_definition()
|
||||
{
|
||||
var row = new FocasDriverPage.FocasDeviceRow
|
||||
{
|
||||
HostAddress = "192.168.0.10:8193", Series = FocasCncSeries.Thirty_i, DeviceName = "CNC1",
|
||||
};
|
||||
var def = row.ToDefinition();
|
||||
var back = FocasDriverPage.FocasDeviceRow.FromDefinition(def);
|
||||
|
||||
back.HostAddress.ShouldBe("192.168.0.10:8193");
|
||||
back.Series.ShouldBe(FocasCncSeries.Thirty_i);
|
||||
back.DeviceName.ShouldBe("CNC1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeviceRow_preserves_unedited_fields()
|
||||
{
|
||||
var original = new FocasDeviceOptions("192.168.0.10:8193", "CNC1", FocasCncSeries.Thirty_i);
|
||||
var row = FocasDriverPage.FocasDeviceRow.FromDefinition(original);
|
||||
row.HostAddress = "192.168.0.20:8193";
|
||||
|
||||
var back = row.ToDefinition();
|
||||
back.HostAddress.ShouldBe("192.168.0.20:8193");
|
||||
back.DeviceName.ShouldBe("CNC1");
|
||||
back.Series.ShouldBe(FocasCncSeries.Thirty_i);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_round_trips_through_definition()
|
||||
{
|
||||
var row = new FocasDriverPage.FocasTagRow
|
||||
{
|
||||
Name = "MacroVar", DeviceHostAddress = "192.168.0.10:8193", Address = "MACRO:500",
|
||||
DataType = FocasDataType.Float64, Writable = true,
|
||||
};
|
||||
var def = row.ToDefinition();
|
||||
var back = FocasDriverPage.FocasTagRow.FromDefinition(def);
|
||||
|
||||
back.Name.ShouldBe("MacroVar");
|
||||
back.DeviceHostAddress.ShouldBe("192.168.0.10:8193");
|
||||
back.Address.ShouldBe("MACRO:500");
|
||||
back.DataType.ShouldBe(FocasDataType.Float64);
|
||||
back.Writable.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_preserves_unedited_fields()
|
||||
{
|
||||
var original = new FocasTagDefinition(
|
||||
"MacroVar", "192.168.0.10:8193", "MACRO:500", FocasDataType.Float64,
|
||||
Writable: true, WriteIdempotent: true);
|
||||
var row = FocasDriverPage.FocasTagRow.FromDefinition(original);
|
||||
row.Name = "Renamed";
|
||||
|
||||
var back = row.ToDefinition();
|
||||
back.Name.ShouldBe("Renamed");
|
||||
back.WriteIdempotent.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateDeviceRow_rejects_duplicate_host()
|
||||
{
|
||||
var rows = new List<FocasDriverPage.FocasDeviceRow> { new() { HostAddress = "192.168.0.10:8193" } };
|
||||
FocasDriverPage.FocasDeviceRow.ValidateRow(new() { HostAddress = "192.168.0.10:8193" }, rows, null)
|
||||
.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateTagRow_rejects_duplicate_name()
|
||||
{
|
||||
var rows = new List<FocasDriverPage.FocasTagRow> { new() { Name = "MacroVar" } };
|
||||
FocasDriverPage.FocasTagRow.ValidateRow(new() { Name = "MacroVar" }, rows, null)
|
||||
.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Device_and_tag_lists_survive_options_serialize_round_trip()
|
||||
{
|
||||
var devices = new List<FocasDeviceOptions>
|
||||
{
|
||||
new("192.168.0.10:8193", "CNC1", FocasCncSeries.Thirty_i),
|
||||
new("192.168.0.20:8193", "CNC2", FocasCncSeries.Zero_i_F),
|
||||
};
|
||||
var tags = new List<FocasTagDefinition>
|
||||
{
|
||||
new("MacroVar", "192.168.0.10:8193", "MACRO:500", FocasDataType.Float64),
|
||||
new("Flag", "192.168.0.20:8193", "X0.0", FocasDataType.Bit),
|
||||
};
|
||||
var opts = new FocasDriverPage.FormModel().ToOptions(devices, tags);
|
||||
var json = JsonSerializer.Serialize(opts, TestJsonOpts);
|
||||
var back = JsonSerializer.Deserialize<FocasDriverOptions>(json, TestJsonOpts)!;
|
||||
back.Devices.Count.ShouldBe(2);
|
||||
back.Devices[0].HostAddress.ShouldBe("192.168.0.10:8193");
|
||||
back.Devices[0].Series.ShouldBe(FocasCncSeries.Thirty_i);
|
||||
back.Tags.Count.ShouldBe(2);
|
||||
back.Tags[0].Name.ShouldBe("MacroVar");
|
||||
back.Tags[0].Address.ShouldBe("MACRO:500");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user