feat(adminui): editable Modbus tag list via CollectionEditor
This commit is contained in:
+47
@@ -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.Modbus;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
|
||||
@@ -14,6 +15,12 @@ public sealed class ModbusDriverPageFormSerializationTests
|
||||
WriteIndented = false,
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions TestJsonOpts = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_PreservesKnownFields()
|
||||
{
|
||||
@@ -104,4 +111,44 @@ public sealed class ModbusDriverPageFormSerializationTests
|
||||
back.ShouldNotBeNull();
|
||||
back.ProbeTimeoutSeconds.ShouldBe(10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TagRow_round_trips_through_definition()
|
||||
{
|
||||
var row = new ModbusDriverPage.ModbusTagRow
|
||||
{
|
||||
Name = "Pump1_Speed", Region = ModbusRegion.HoldingRegisters, Address = 40001,
|
||||
DataType = ModbusDataType.Int16, Writable = true,
|
||||
};
|
||||
var def = row.ToDefinition();
|
||||
var back = ModbusDriverPage.ModbusTagRow.FromDefinition(def);
|
||||
|
||||
back.Name.ShouldBe("Pump1_Speed");
|
||||
back.Address.ShouldBe(40001);
|
||||
back.DataType.ShouldBe(ModbusDataType.Int16);
|
||||
back.Writable.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tag_list_survives_options_serialize_round_trip()
|
||||
{
|
||||
var tags = new List<ModbusTagDefinition>
|
||||
{
|
||||
new("A", ModbusRegion.HoldingRegisters, 1, ModbusDataType.Int16),
|
||||
new("B", ModbusRegion.Coils, 2, ModbusDataType.Bool),
|
||||
};
|
||||
var opts = new ModbusDriverPage.FormModel().ToOptions(tags);
|
||||
var json = JsonSerializer.Serialize(opts, TestJsonOpts);
|
||||
var back = JsonSerializer.Deserialize<ModbusDriverOptions>(json, TestJsonOpts)!;
|
||||
back.Tags.Count.ShouldBe(2);
|
||||
back.Tags[0].Name.ShouldBe("A");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateRow_rejects_duplicate_name()
|
||||
{
|
||||
var rows = new List<ModbusDriverPage.ModbusTagRow> { new() { Name = "A" } };
|
||||
ModbusDriverPage.ModbusTagRow.ValidateRow(new() { Name = "A" }, rows, null)
|
||||
.ShouldNotBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user