Adapt Raw hierarchy density and menu placement to touch layouts
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Native invoker identity distinguishes WebKit keyboard clicks from right-click pointer placement.</summary>
|
||||
[Trait("Category","Unit")]
|
||||
public sealed class ContextMenuPlacementTests : BunitContext
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0,true)]
|
||||
[InlineData(1,false)]
|
||||
public void TriggerClick_WithNonzeroCoordinates_UsesNativeDetail(long detail,bool anchored)
|
||||
{
|
||||
JSInterop.Mode=JSRuntimeMode.Loose;
|
||||
var module=JSInterop.SetupModule("./_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/tree-layout.js");module.Mode=JSRuntimeMode.Loose;
|
||||
var cut=Render<ContextMenu>(p=>p.Add(x=>x.Items,new[]{new ContextMenuItem{Label="Local action"}}));
|
||||
cut.Find(".ctx-ellipsis").Click(new MouseEventArgs{Detail=detail,ClientX=253,ClientY=252});
|
||||
cut.WaitForAssertion(()=>module.Invocations.Count(x=>x.Identifier=="placeMenu").ShouldBe(1));
|
||||
module.Invocations.Single(x=>x.Identifier=="placeMenu").Arguments[2].ShouldBe(anchored);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(88,99)]
|
||||
[InlineData(0,0)]
|
||||
public void RightClick_WithZeroDetail_KeepsPointerPlacementWithoutEllipsis(double x,double y)
|
||||
{
|
||||
JSInterop.Mode=JSRuntimeMode.Loose;
|
||||
var module=JSInterop.SetupModule("./_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/tree-layout.js");module.Mode=JSRuntimeMode.Loose;
|
||||
var cut=Render<ContextMenu>(p=>p.Add(x=>x.Items,new[]{new ContextMenuItem{Label="Local action"}})
|
||||
.Add(x=>x.ShowEllipsis,false).Add(x=>x.ChildContent,(RenderFragment)(builder=>builder.AddContent(0,"Native context surface"))));
|
||||
cut.Find(".ctx-surface").TriggerEvent("oncontextmenu",new MouseEventArgs{Detail=0,Button=2,ClientX=x,ClientY=y});
|
||||
cut.WaitForAssertion(()=>module.Invocations.Count(x=>x.Identifier=="placeMenu").ShouldBe(1));
|
||||
module.Invocations.Single(x=>x.Identifier=="placeMenu").Arguments[2].ShouldBe(false);
|
||||
cut.FindAll("[role=menu]").Count.ShouldBe(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Reflection;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.JSInterop;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Raw;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Pointer observations update the actual virtualization estimate without replacing selection state.</summary>
|
||||
[Trait("Category","Unit")]
|
||||
public sealed class RawTreeDensityTests : BunitContext
|
||||
{
|
||||
public RawTreeDensityTests()
|
||||
{
|
||||
var names=new HashSet<string>{"DriverConfigModal","DeviceModal","RawTagModal","RawManualTagEntryModal","RawCsvImportModal","RawCsvExportModal","RawBrowseModal","RawNameDialog","RawConfirmDialog","RawDriverTypeDialog","RawStubModal"};
|
||||
ComponentFactories.AddStub(type=>names.Contains(type.Name)); // Mutation dialogs have separate lifecycle suites.
|
||||
Services.AddSingleton(DispatchProxy.Create<IRawTreeService,RefusingRawService>());
|
||||
JSInterop.Mode=JSRuntimeMode.Loose;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NewestDensity_UpdatesEstimateAndPreservesSelection()
|
||||
{
|
||||
var module=JSInterop.SetupModule("./_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/tree-layout.js");
|
||||
module.Mode=JSRuntimeMode.Loose;
|
||||
module.Setup<bool>("observeDensity",_=>true).SetResult(false);
|
||||
var selected=new HashSet<string>{"selected"};
|
||||
var cut=Render<RawTree>(p=>p.Add(x=>x.Roots,Roots()).Add(x=>x.PickerMode,true).Add(x=>x.SelectedTagIds,selected));
|
||||
cut.WaitForAssertion(()=>module.Invocations.Count(x=>x.Identifier=="observeDensity").ShouldBe(1));
|
||||
await cut.InvokeAsync(()=>cut.Instance.SetPointerDensity(2,true));
|
||||
cut.FindComponent<Virtualize<RawTreeRow>>().Instance.ItemSize.ShouldBe(44);
|
||||
cut.Find(".raw-tree-rows").GetAttribute("data-density").ShouldBe("touch");
|
||||
await cut.InvokeAsync(()=>cut.Instance.SetPointerDensity(1,false));
|
||||
cut.FindComponent<Virtualize<RawTreeRow>>().Instance.ItemSize.ShouldBe(44);
|
||||
selected.ShouldBe(new[]{"selected"});
|
||||
await cut.InvokeAsync(()=>cut.Instance.SetPointerDensity(3,false));
|
||||
cut.FindComponent<Virtualize<RawTreeRow>>().Instance.ItemSize.ShouldBe(30);
|
||||
selected.ShouldBe(new[]{"selected"});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LateInitialObservation_CannotOverwriteNewerDensity()
|
||||
{
|
||||
var module=JSInterop.SetupModule("./_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/tree-layout.js");
|
||||
module.Mode=JSRuntimeMode.Loose;
|
||||
var observation=module.Setup<bool>("observeDensity",_=>true);
|
||||
var cut=Render<RawTree>(p=>p.Add(x=>x.Roots,Roots()));
|
||||
cut.WaitForAssertion(()=>module.Invocations.Count(x=>x.Identifier=="observeDensity").ShouldBe(1));
|
||||
await cut.InvokeAsync(()=>cut.Instance.SetPointerDensity(2,true));
|
||||
observation.SetResult(false);
|
||||
await cut.InvokeAsync(()=>Task.CompletedTask);
|
||||
cut.FindComponent<Virtualize<RawTreeRow>>().Instance.ItemSize.ShouldBe(44);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Disposal_WaitsForAttemptAndReleasesObserverOnce()
|
||||
{
|
||||
var module=JSInterop.SetupModule("./_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/tree-layout.js");
|
||||
module.Mode=JSRuntimeMode.Loose;
|
||||
var observation=module.Setup<bool>("observeDensity",_=>true);
|
||||
var cut=Render<RawTree>(p=>p.Add(x=>x.Roots,Roots()));
|
||||
cut.WaitForAssertion(()=>module.Invocations.Count(x=>x.Identifier=="observeDensity").ShouldBe(1));
|
||||
var disposal=cut.Instance.DisposeAsync().AsTask();
|
||||
disposal.IsCompleted.ShouldBeFalse();
|
||||
await cut.InvokeAsync(()=>cut.Instance.SetPointerDensity(4,true));
|
||||
observation.SetResult(true);
|
||||
await disposal;
|
||||
await cut.Instance.DisposeAsync();
|
||||
module.Invocations.Count(x=>x.Identifier=="stopDensity").ShouldBe(1);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<RawNode> Roots()=>[new(){Key="tag:selected",EntityId="selected",Kind=RawNodeKind.Tag,DisplayName="Selected tag"}];
|
||||
|
||||
public class RefusingRawService : DispatchProxy
|
||||
{
|
||||
protected override object? Invoke(MethodInfo? method,object?[]? args)=>throw new NotSupportedException("Density fixture refuses "+method?.Name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user