e6cba4bc18
- RawTagRowRules: the ONE driver-dispatched authority on Tag-ROW rules (access level / Tag.DataType). RawTreeService's save path, the CSV import's staged review grid (RawTagCsvMapper) and the manual-entry grid all call it; no call site names a driver. A ReadWrite or mistyped Heidenhain row is now invalid IN THE PREVIEW instead of only at Commit. - Manual-entry grid + tag modal: when the driver dictates the data type for the row's address (RawTagRowDefaults.DictatedDataType), the field is a locked read-only value instead of a select that commit silently replaced; the grid runs the row rule client-side and no longer rewrites the row at commit. - Driver/device modals: the credential refusal is shown once (the modal's save-gate notice); HeidenhainDriverFormModel / HeidenhainDeviceModel.Validate report only ranges / endpoint. - docs/drivers/Heidenhain.md: #831 alarm conditions + rediscovery, #830 authoring behaviour. Tests: HeidenhainAuthoringUxTests (CSV preview == ImportTagsAsync row-for-row, dictated type is what the save path accepts, single credential surface, ALARM: seeding, CSV alarm rows, AlarmMs round-trip); HeidenhainAuthoringTests updated for the single-notice rule.
126 lines
5.8 KiB
C#
126 lines
5.8 KiB
C#
using System.Text.Json.Nodes;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.DeviceForms;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Forms;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
|
|
|
/// <summary>
|
|
/// lmxopcua#803: the Heidenhain authoring surfaces (driver form, device form, tag editor, CSV, browse commit)
|
|
/// write exactly what the driver factory and the deploy gate accept — the "registered but unauthorable" and
|
|
/// "numerically-serialized enum" defect classes.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class HeidenhainAuthoringTests
|
|
{
|
|
[Fact]
|
|
public void Every_authoring_seam_is_registered()
|
|
{
|
|
DriverConfigFormMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(HeidenhainDriverForm));
|
|
DeviceFormMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(HeidenhainDeviceForm));
|
|
TagConfigEditorMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(Components.Shared.Uns.TagEditors.HeidenhainTagConfigEditor));
|
|
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, "{}").ShouldNotBeNull();
|
|
CsvColumnMap.Resolve(DriverTypeNames.Heidenhain).ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_default_driver_form_save_is_accepted_by_the_factory_and_preserves_devices()
|
|
{
|
|
var authored = """{"Devices":[{"Host":"10.0.0.5","DeviceName":"m1"}],"Custom":42}""";
|
|
var m = HeidenhainDriverFormModel.FromJson(authored);
|
|
m.Validate().ShouldBeNull();
|
|
m.InspectPassword = "secret:heidenhain/inspect";
|
|
m.TimersEnabled = true;
|
|
var json = m.ToJson();
|
|
var o = HeidenhainOptionsParser.Parse(json);
|
|
HeidenhainOptionsParser.Validate(o).ShouldBeEmpty(); // the factory's ParseOptions gate
|
|
o.Devices.Single().Host.ShouldBe("10.0.0.5");
|
|
o.Access.InspectPassword.ShouldBe("secret:heidenhain/inspect");
|
|
o.Polling.TimersEnabled.ShouldBeTrue();
|
|
JsonNode.Parse(json)!["Custom"]!.GetValue<int>().ShouldBe(42);
|
|
// no field is ever written as a number where the parser expects a name — there are no enums at all
|
|
HeidenhainDriverFormModel.FromJson(json).ToJson().ShouldBe(json);
|
|
}
|
|
|
|
[Fact]
|
|
public void Driver_form_refuses_literal_passwords_and_out_of_range_values()
|
|
{
|
|
var m = HeidenhainDriverFormModel.FromJson("{}");
|
|
m.DncPassword = "hunter2";
|
|
// #830: the credential refusal is the hosting modal's (the save gate), reported once — not the form's too.
|
|
var refusal = DriverConfigSaveGate.Validate(DriverTypeNames.Heidenhain, m.ToJson());
|
|
refusal.ShouldNotBeNull();
|
|
refusal.ShouldNotContain("hunter2");
|
|
m.DncPassword = null;
|
|
m.StatusMs = 10;
|
|
m.Validate().ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Device_form_round_trips_and_validates_with_the_driver_rule()
|
|
{
|
|
var d = HeidenhainDeviceModel.FromJson("""{"Host":"cnc-7","Note":"keep"}""");
|
|
d.Port.ShouldBe(19000);
|
|
d.Validate().ShouldBeNull();
|
|
d.DataPassword = "plain";
|
|
DriverConfigSaveGate.Validate(DriverTypeNames.Heidenhain, d.ToJson()).ShouldNotBeNull(); // #830: the modal's gate
|
|
d.DataPassword = "env:OTOPCUA_HEIDENHAIN_DATA";
|
|
var json = d.ToJson();
|
|
JsonNode.Parse(json)!["Note"]!.GetValue<string>().ShouldBe("keep");
|
|
var opts = HeidenhainOptionsParser.Parse($$"""{"Devices":[{{json}}]}""");
|
|
opts.Devices.Single().DataPassword.ShouldBe("env:OTOPCUA_HEIDENHAIN_DATA");
|
|
HeidenhainDeviceModel.FromJson("{}").Validate().ShouldNotBeNull(); // host required
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Axes/Positions")]
|
|
[InlineData("Alarms/Messages")]
|
|
[InlineData("Status/ExecutionState")]
|
|
[InlineData("Capabilities/DncLogin")]
|
|
public void Catalog_addresses_derive_type_and_rank_so_the_driver_accepts_them(string address)
|
|
{
|
|
var json = new HeidenhainTagConfigModel { Address = address }.ToJson();
|
|
HeidenhainTagDefinitionFactory.TryFromTagConfig("p", "d", json, out var def, out var error).ShouldBeTrue(error);
|
|
HeidenhainCatalog.TryGet(address, out var e).ShouldBeTrue();
|
|
def!.DataType.ShouldBe(e!.DataType);
|
|
def.IsArray.ShouldBe(e.IsArray);
|
|
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, json).ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Editor_writes_the_data_type_as_a_name_and_drops_a_stray_writable_flag()
|
|
{
|
|
var m = HeidenhainTagConfigModel.FromJson("""{"address":"PLC:WORD:2","dataType":"Int64","writable":true,"isHistorized":true}""");
|
|
m.Validate().ShouldNotBeNull(); // as loaded: the driver refuses writable:true
|
|
var json = m.ToJson();
|
|
var o = JsonNode.Parse(json)!.AsObject();
|
|
o["dataType"]!.GetValue<string>().ShouldBe("Int64");
|
|
o.ContainsKey("writable").ShouldBeFalse();
|
|
o["isHistorized"]!.GetValue<bool>().ShouldBeTrue();
|
|
HeidenhainTagConfigModel.FromJson(json).Validate().ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Editor_refuses_a_narrowing_binding()
|
|
{
|
|
var m = new HeidenhainTagConfigModel { Address = "PLC:DWORD:0", DataType = DriverDataType.Int16 };
|
|
m.Validate().ShouldNotBeNull();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Status/ExecutionState")]
|
|
[InlineData("Axes/Names")]
|
|
public void Browse_committed_leaves_open_in_the_editor_and_pass_the_driver_gate(string address)
|
|
{
|
|
var json = RawBrowseCommitMapper.BuildTagConfig(DriverTypeNames.Heidenhain, address);
|
|
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, json).ShouldBeNull();
|
|
HeidenhainTagConfigModel.FromJson(json).Address.ShouldBe(address);
|
|
}
|
|
}
|