test(adminui): migrate AdminUI.Tests to v3 greenfield schema + Batch-1 stubs

Migrate tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests (was 358 build errors) to
the v3 Raw-only Tag schema and the Batch-1 AdminUI stubs. Production untouched.

- Driver-page serialization tests: drop the retired pre-declared Tags editor
  (page *TagRow types + DriverOptions.Tags); multi-device pages keep their
  Devices editor (ToOptions(devices)). Enum-serialization round-trip coverage
  (CpuType/ModbusFamily/MelsecFamily/AbCipPlcFamily/AbLegacyPlcFamily/FocasCncSeries)
  preserved intact.
- UnsTreeTestDb: reseed to v3 (Device->Tag raw slice, no EquipmentId/DriverInstanceId
  on Tag, no Namespace).
- UnsTreeService tag tests: assert Batch-1 stubs (CreateTag/UpdateTag refusal,
  empty tag/tag-driver lists); DeleteTag stays live against a raw Tag.
- Equipment #122 guard retained (validates input driver vs line cluster); drop the
  retired persisted-binding assertions + NamespaceId seeds. Area/Line #122 driver-
  orphan guard retired -> assert cross-cluster move now succeeds.
- DeleteCluster: drop the deleted-Namespace child-check test.
- OpcUaClientTagConfigModel/TagConfigValidator: address key FullName -> nodeId.
- ScriptTagCatalog: project surviving Name/DataType/TagConfig; DriverInstanceId null.
- VirtualTag {{equip}} equipment-tag-derived base is dark -> 3 tests skipped (Batch-3).

Result: build green; 507 passed / 3 skipped / 0 failed.
This commit is contained in:
Joseph Doherty
2026-07-15 21:50:48 -04:00
parent aaba2ebd66
commit 6a616a1ab2
22 changed files with 266 additions and 1029 deletions
@@ -7,6 +7,12 @@ using ZB.MOM.WW.OtOpcUa.Driver.S7;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
// v3 Batch-1 migration: the S7 driver page dropped its pre-declared Tags editor — tags now live in
// the Raw tree (/raw, Batch 2), and S7DriverOptions.Tags (the typed S7TagDefinition list) +
// S7DriverPage.S7TagRow were retired (the driver now consumes RawTags). The former tag-editor and
// tag-serialization tests (S7TagRow_*, TagList_SerializeRoundTrip_PreservesTags, and the tag legs of
// the round-trip tests) were removed. The connection/protocol-field + enum-serialization round-trip
// coverage (CpuType, S7DataType) is retained below unchanged.
public sealed class S7DriverPageFormSerializationTests
{
private static readonly JsonSerializerOptions _opts = new()
@@ -33,7 +39,6 @@ public sealed class S7DriverPageFormSerializationTests
Timeout = TimeSpan.FromSeconds(3),
},
ProbeTimeoutSeconds = 30,
Tags = [],
};
var json = JsonSerializer.Serialize(original, _opts);
@@ -51,7 +56,6 @@ public sealed class S7DriverPageFormSerializationTests
back.Probe.Interval.ShouldBe(TimeSpan.FromSeconds(15));
back.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(3));
back.ProbeTimeoutSeconds.ShouldBe(30);
back.Tags.ShouldBeEmpty();
}
[Fact]
@@ -70,12 +74,6 @@ public sealed class S7DriverPageFormSerializationTests
[Fact]
public void FormModel_RoundTrip_PreservesEditableFields()
{
var tags = new[]
{
new S7TagDefinition("Speed", "DB1.DBD0", S7DataType.Float32, Writable: true),
new S7TagDefinition("Status", "DB1.DBW4", S7DataType.Int16, Writable: false),
};
var opts = new S7DriverOptions
{
Host = "192.168.1.50",
@@ -91,15 +89,10 @@ public sealed class S7DriverPageFormSerializationTests
Timeout = TimeSpan.FromSeconds(4),
},
ProbeTimeoutSeconds = 20,
Tags = tags,
};
var form = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers
.S7DriverPage.FormModel.FromOptions(opts);
var tagRows = opts.Tags
.Select(ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers.S7DriverPage.S7TagRow.FromDefinition)
.ToList();
var roundTripped = form.ToOptions(tagRows.Select(r => r.ToDefinition()).ToList());
var form = S7DriverPage.FormModel.FromOptions(opts);
var roundTripped = form.ToOptions();
roundTripped.Host.ShouldBe("192.168.1.50");
roundTripped.Port.ShouldBe(102);
@@ -111,104 +104,5 @@ public sealed class S7DriverPageFormSerializationTests
roundTripped.Probe.Interval.ShouldBe(TimeSpan.FromSeconds(8));
roundTripped.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(4));
roundTripped.ProbeTimeoutSeconds.ShouldBe(20);
// Tags must survive the FormModel round-trip unchanged (regression guard for the
// Tags = [] data-loss bug fixed in this PR).
roundTripped.Tags.Count.ShouldBe(2);
roundTripped.Tags[0].Name.ShouldBe("Speed");
roundTripped.Tags[0].Address.ShouldBe("DB1.DBD0");
roundTripped.Tags[0].DataType.ShouldBe(S7DataType.Float32);
roundTripped.Tags[1].Name.ShouldBe("Status");
roundTripped.Tags[1].Writable.ShouldBeFalse();
}
[Fact]
public void S7TagRow_RoundTrip_PreservesEditableFields()
{
var def = new S7TagDefinition("Speed", "DB1.DBD0", S7DataType.Float32, Writable: true, StringLength: 80);
var row = S7DriverPage.S7TagRow.FromDefinition(def);
var back = row.ToDefinition();
back.Name.ShouldBe("Speed");
back.Address.ShouldBe("DB1.DBD0");
back.DataType.ShouldBe(S7DataType.Float32);
back.Writable.ShouldBeTrue();
back.StringLength.ShouldBe(80);
}
[Fact]
public void S7TagRow_CarriesThroughUneditedFields()
{
// WriteIdempotent is not exposed by the editor; it must survive FromDefinition→edit→ToDefinition.
var def = new S7TagDefinition("Setpoint", "DB10.DBD0", S7DataType.Float32, Writable: true, WriteIdempotent: true);
var row = S7DriverPage.S7TagRow.FromDefinition(def);
row.Name = "SetpointRenamed";
row.Writable = false;
var back = row.ToDefinition();
back.Name.ShouldBe("SetpointRenamed");
back.Writable.ShouldBeFalse();
// Un-edited field carried through via _source.
back.WriteIdempotent.ShouldBeTrue();
}
[Fact]
public void S7TagRow_ValidateRow_RejectsDuplicateNames()
{
var all = new List<S7DriverPage.S7TagRow>
{
S7DriverPage.S7TagRow.FromDefinition(new S7TagDefinition("Speed", "DB1.DBD0", S7DataType.Float32)),
S7DriverPage.S7TagRow.FromDefinition(new S7TagDefinition("Status", "DB1.DBW4", S7DataType.Int16)),
};
// Editing index 1 to a name that case-insensitively collides with index 0.
var edited = all[1].Clone();
edited.Name = "speed";
S7DriverPage.S7TagRow.ValidateRow(edited, all, editIndex: 1)
.ShouldBe("Duplicate tag name 'speed'.");
// Required-name guard.
var blank = new S7DriverPage.S7TagRow();
S7DriverPage.S7TagRow.ValidateRow(blank, all, editIndex: null)
.ShouldBe("Name is required.");
// Unique name passes.
var ok = all[1].Clone();
ok.Name = "Torque";
S7DriverPage.S7TagRow.ValidateRow(ok, all, editIndex: 1).ShouldBeNull();
}
[Fact]
public void TagList_SerializeRoundTrip_PreservesTags()
{
var opts = new S7DriverOptions
{
Host = "10.1.1.1",
Tags =
[
new S7TagDefinition("Speed", "DB1.DBD0", S7DataType.Float32, Writable: true),
new S7TagDefinition("Name", "DB2.DBB0", S7DataType.String, Writable: false, StringLength: 32),
],
};
var optsSkip = new JsonSerializerOptions(_opts)
{
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
};
var json = JsonSerializer.Serialize(opts, optsSkip);
var back = JsonSerializer.Deserialize<S7DriverOptions>(json, optsSkip);
back.ShouldNotBeNull();
back.Tags.Count.ShouldBe(2);
back.Tags[0].Name.ShouldBe("Speed");
back.Tags[0].Address.ShouldBe("DB1.DBD0");
back.Tags[0].DataType.ShouldBe(S7DataType.Float32);
back.Tags[0].Writable.ShouldBeTrue();
back.Tags[1].Name.ShouldBe("Name");
back.Tags[1].DataType.ShouldBe(S7DataType.String);
back.Tags[1].StringLength.ShouldBe(32);
back.Tags[1].Writable.ShouldBeFalse();
}
}