Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/Pages/CommonTreeAccessibilityTests.cs
T
2026-11-13 21:52:00 -05:00

54 lines
2.8 KiB
C#

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)
};
}
}