using Bunit;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
///
/// bUnit tests for TreeView's WAI-ARIA tree keyboard navigation
/// (https://www.w3.org/WAI/ARIA/apg/patterns/treeview/). Covers the roving
/// tabindex (exactly one tabbable treeitem), Arrow/Home/End movement over the
/// flattened visible node order, ArrowRight/ArrowLeft expand-collapse
/// semantics, Enter/Space activation in both selection modes, and the
/// aria-level / aria-posinset / aria-setsize structure.
///
/// bUnit moves no real browser focus, so "focus" is asserted through the rendered
/// tabindex attribute (the roving-tabindex target) and through the
/// selection callbacks, not through a focused element.
///
public class TreeViewKeyboardNavigationTests : BunitContext
{
private record TestNode(string Key, string Label, List Children);
// Alpha (branch)
// ├── Alpha-1 (leaf)
// └── Alpha-2 (branch)
// └── Alpha-2-X (leaf)
// Beta (leaf)
private static List SimpleRoots() => new()
{
new("a", "Alpha", new()
{
new("a1", "Alpha-1", new()),
new("a2", "Alpha-2", new()
{
new("a2x", "Alpha-2-X", new())
})
}),
new("b", "Beta", new()),
};
private IRenderedComponent> RenderTreeView(
List? items = null,
Func? initiallyExpanded = null,
bool selectable = false,
object? selectedKey = null,
Action