55 lines
2.8 KiB
C#
55 lines
2.8 KiB
C#
using Bunit;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Uns;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
|
|
|
/// <summary>Tree controls expose the rendered node state and retain caller-owned lazy behavior.</summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class TreeAccessibilityTests : BunitContext
|
|
{
|
|
/// <summary>The expansion button follows the real node and raises the original callback.</summary>
|
|
[Fact]
|
|
public void UnsBranch_ExposesNodeNameExpansionAndOriginalCallback()
|
|
{
|
|
var node = new UnsNode { Kind = UnsNodeKind.Equipment, Key = "eq:1", DisplayName = "press-01", HasLazyChildren = true };
|
|
UnsNode? toggled = null;
|
|
var cut = Render<UnsTree>(p => p.Add(x => x.Roots, new[] { node }).Add(x => x.OnToggleExpand, n => toggled = n));
|
|
var button = cut.Find("button[aria-expanded]");
|
|
button.GetAttribute("aria-expanded").ShouldBe("false");
|
|
button.GetAttribute("aria-label")!.ShouldContain("press-01");
|
|
button.Click();
|
|
toggled.ShouldBeSameAs(node);
|
|
node.Expanded.ShouldBeFalse(); // Host, not renderer, owns lazy expansion.
|
|
node.Expanded = true; cut.Render();
|
|
cut.Find("button[aria-expanded]").GetAttribute("aria-expanded").ShouldBe("true");
|
|
}
|
|
|
|
/// <summary>Filter-open ancestors expose their displayed state without mutating stored expansion.</summary>
|
|
[Fact]
|
|
public void UnsFilter_ExpansionStateMatchesDisplayedLoadedPath()
|
|
{
|
|
var root = new UnsNode { Kind = UnsNodeKind.Area, Key = "area:1", DisplayName = "Area", Expanded = false };
|
|
root.Children.Add(new UnsNode { Kind = UnsNodeKind.Equipment, Key = "eq:1", DisplayName = "matched press" });
|
|
var cut = Render<UnsTree>(p => p.Add(x => x.Roots, new[] { root }).Add(x => x.Filter, "matched"));
|
|
cut.Find("button[aria-expanded]").GetAttribute("aria-expanded").ShouldBe("true");
|
|
root.Expanded.ShouldBeFalse();
|
|
cut.Markup.ShouldContain("matched press");
|
|
}
|
|
|
|
/// <summary>Repeated row actions name the owning row and retain its exact callback object.</summary>
|
|
[Fact]
|
|
public void UnsActions_UseContextualNamesAndRetainSelectedNode()
|
|
{
|
|
var first = new UnsNode { Kind = UnsNodeKind.Area, Key = "area:1", DisplayName = "press-01" };
|
|
var second = new UnsNode { Kind = UnsNodeKind.Area, Key = "area:2", DisplayName = "press-02" };
|
|
UnsNode? edited = null;
|
|
var cut = Render<UnsTree>(p => p.Add(x => x.Roots, new[] { first, second }).Add(x => x.OnEdit, n => edited = n));
|
|
cut.Find("button[aria-label='Edit press-02']").Click();
|
|
edited.ShouldBeSameAs(second);
|
|
cut.Find("button[aria-label='Delete press-01']").TextContent.ShouldContain("Delete");
|
|
}
|
|
}
|