Complete common picker and tree field accessibility

This commit is contained in:
Joseph Doherty
2026-11-13 21:52:00 -05:00
parent 25e78ebe92
commit b990ebe3ea
43 changed files with 2581 additions and 74 deletions
@@ -1,5 +1,10 @@
using AngleSharp.Dom;
using Bunit;
using Bunit.TestDoubles;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using ZB.MOM.WW.OtOpcUa.AdminUI.Browsing;
using ZB.MOM.WW.OtOpcUa.Security.Auth;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Shouldly;
@@ -13,13 +18,66 @@ namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
[Trait("Category", "Unit")]
public sealed class CommonControlAccessibilityTests : BunitContext
{
private readonly Action _allowBrowse;
private readonly RefusingBrowserProxy _browser;
public CommonControlAccessibilityTests()
{
var auth = this.AddAuthorization(); auth.SetAuthorized("fixture-reader");
_allowBrowse = () => auth.SetPolicies(AdminUiPolicies.DriverOperator);
var browser = DispatchProxy.Create<IBrowserSessionService, RefusingBrowserProxy>();
_browser = (RefusingBrowserProxy)(object)browser;
Services.AddSingleton(browser);
}
[Theory]
[InlineData(typeof(AbCipAddressPickerBody))]
[InlineData(typeof(TwinCATAddressPickerBody))]
[InlineData(typeof(FOCASAddressPickerBody))]
[InlineData(typeof(GalaxyAddressPickerBody))]
[InlineData(typeof(SqlAddressPickerBody))]
[InlineData(typeof(OpcUaClientAddressPickerBody))]
[InlineData(typeof(ModbusAddressPickerBody))]
[InlineData(typeof(AbLegacyAddressPickerBody))]
[InlineData(typeof(S7AddressPickerBody))]
[InlineData(typeof(DriverIdentitySection))]
[InlineData(typeof(DriverResilienceSection))]
public void CommonFields_TwoInstancesHaveResolvedNames(Type type)
{
AssertRelationships(RenderFields(type));
_browser.Calls.ShouldBe(0);
}
/// <summary>Operator-only drafts and conditional address spaces remain named without opening a session.</summary>
[Theory]
[InlineData(typeof(SqlAddressPickerBody), "WideRow")]
[InlineData(typeof(FOCASAddressPickerBody), "Alarm")]
[InlineData(typeof(FOCASAddressPickerBody), "Parameter")]
[InlineData(typeof(FOCASAddressPickerBody), "Macro")]
public void ConditionalPickerFields_RemainNamedWithoutBrowserOperations(Type type,string branch)
{
_allowBrowse();
var cut=RenderFields(type);
cut.Find("select").Change(branch);
AssertRelationships(cut);
if (type == typeof(SqlAddressPickerBody))
{
var label=cut.FindAll("label").First(e=>e.TextContent.Trim()=="Row selector");
cut.FindAll("select").Single(e=>e.Id==label.GetAttribute("for")).Change("Newest");
AssertRelationships(cut);
}
if (type == typeof(FOCASAddressPickerBody) && branch == "Alarm")
{
var label=cut.FindAll("label").First(e=>e.TextContent.Trim()=="Alarms");
var select=cut.FindAll("select").Single(e=>e.Id==label.GetAttribute("for"));
select.Change(select.QuerySelectorAll("option").First(e=>e.GetAttribute("value") is not ("*" or "OTHER")).GetAttribute("value"));
AssertRelationships(cut);
cut.FindAll("label").ShouldContain(e=>e.TextContent.Contains("Through number"));
}
_browser.Calls.ShouldBe(0);
}
private IRenderedComponent<CascadingValue<EditContext>> RenderFields(Type type)
{
var cut = Render<CascadingValue<EditContext>>(p => p.Add(x => x.Value,new EditContext(new object()))
.Add(x => x.ChildContent,(RenderFragment)(builder =>
@@ -35,7 +93,7 @@ public sealed class CommonControlAccessibilityTests : BunitContext
builder.CloseComponent();
}
})));
AssertRelationships(cut);
return cut;
}
private static void AssertRelationships(IRenderedComponent<CascadingValue<EditContext>> cut)
@@ -55,4 +113,16 @@ public sealed class CommonControlAccessibilityTests : BunitContext
foreach(var label in cut.FindAll("label[for]"))Find(cut,label.GetAttribute("for")!).ShouldNotBeNull();
}
private static IElement Find(IRenderedComponent<CascadingValue<EditContext>> cut,string id)=>cut.FindAll("[id]").Single(e=>e.Id==id);
/// <summary>No browse session or external connection may be opened by a field fixture.</summary>
public class RefusingBrowserProxy : DispatchProxy
{
public int Calls { get; private set; }
protected override object? Invoke(MethodInfo? method, object?[]? args)
{
if (method?.Name == nameof(IBrowserSessionService.CanBrowse)) return true; // Static capability only; no session/connection.
Calls++;
throw new NotSupportedException("Field fixture refuses browser operations: " + method?.Name);
}
}
}