42 lines
2.1 KiB
C#
42 lines
2.1 KiB
C#
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);
|
|
}
|
|
}
|