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);
}
}
}
@@ -0,0 +1,53 @@
using Bunit;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Acls;
using ZB.MOM.WW.OtOpcUa.AdminUI.Browsing;
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Acls;
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
using ZB.MOM.WW.OtOpcUa.Commons.Browsing;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
/// <summary>Tree names/states identify the actual scope or driver node without changing lazy loading.</summary>
[Trait("Category","Unit")]
public sealed class CommonTreeAccessibilityTests : BunitContext
{
[Fact]
public void BrowseTree_ExpandedFilterAndLeafHaveContextualNames()
{
Services.AddSingleton(DispatchProxy.Create<IBrowserSessionService,SyntheticBrowser>());
var cut=Render<DriverBrowseTree>(p=>p.Add(x=>x.SessionToken,Guid.NewGuid()).Add(x=>x.MultiSelect,true));
var expand=cut.Find("button.tree-twist");
expand.GetAttribute("aria-label").ShouldBe("Expand Fixture folder");
expand.GetAttribute("aria-expanded").ShouldBe("false");expand.Click();
cut.Find("button.tree-twist").GetAttribute("aria-expanded").ShouldBe("true");
cut.Find("input[type=text]").GetAttribute("aria-label").ShouldBe("Filter children of Fixture folder");
cut.Find("input[type=checkbox]").GetAttribute("aria-label").ShouldBe("Select Fixture leaf");
}
[Fact]
public void ScopeTree_ExpandAndSelectionExposeVisibleNodeState()
{
var node=new AclScopeNode {Key="one",DisplayName="Fixture scope",PathLabel="Fixture scope",Icon="x",ScopeKind=NodeAclScopeKind.Cluster,HasLazyChildren=true};
var cut=Render<AclScopeTree>(p=>p.Add(x=>x.Nodes,new[]{node}).Add(x=>x.SelectedKey,"one"));
cut.Find("button.tree-twist").GetAttribute("aria-label").ShouldBe("Expand Fixture scope");
cut.Find("button[aria-pressed]").GetAttribute("aria-pressed").ShouldBe("true");
cut.Find("button.tree-twist").Click();
cut.Find("button.tree-twist").GetAttribute("aria-expanded").ShouldBe("true");
}
/// <summary>Only synthetic root/child reads are supported; all connection and mutation calls fail.</summary>
public class SyntheticBrowser : DispatchProxy
{
protected override object? Invoke(MethodInfo? method,object?[]? args)=>method?.Name switch
{
nameof(IBrowserSessionService.RootAsync)=>Task.FromResult<IReadOnlyList<BrowseNode>>([new("folder","Fixture folder",BrowseNodeKind.Folder,true)]),
nameof(IBrowserSessionService.ExpandAsync)=>Task.FromResult<IReadOnlyList<BrowseNode>>([new("leaf","Fixture leaf",BrowseNodeKind.Leaf,false)]),
_=>throw new NotSupportedException("Synthetic tree refuses "+method?.Name)
};
}
}