Skip to content

Commit

Permalink
test: add When_DragDrop_AcceptedOperation_None
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Nov 15, 2024
1 parent 373fd45 commit d974132
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Windows.UI;
using Windows.ApplicationModel.Appointments;
using Microsoft.UI.Xaml.Hosting;
using Uno.UI.Helpers.Xaml;
using Uno.UI.Toolkit.Extensions;

#if __IOS__
Expand Down Expand Up @@ -1682,6 +1683,68 @@ public async Task When_ScaleTransform_HitTest(bool addClip)
#if HAS_UNO
#region Drag and Drop

[TestMethod]
[RunsOnUIThread]
[UnoWorkItem("https://github.com/unoplatform/uno/issues/18770")]
[DataRow(true)]
[DataRow(false)]
#if !HAS_INPUT_INJECTOR
[Ignore("InputInjector is not supported on this platform.")]
#endif
public async Task When_DragDrop_AcceptedOperation_None(bool setAcceptedOperation)
{
if (TestServices.WindowHelper.IsXamlIsland)
{
Assert.Inconclusive("Drag and drop doesn't work in Uno islands.");
}

var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector");
using var mouse = injector.GetMouse();

var dropCount = 0;
Rectangle source, target;
var sp = new StackPanel
{
(source = new Rectangle
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(Microsoft.UI.Colors.LightCoral),
CanDrag = true
}),
(target = new Rectangle
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(Microsoft.UI.Colors.LightCoral),
AllowDrop = true
}.GenericApply(rect =>
{
rect.Drop += (_, _) => dropCount++;
if (setAcceptedOperation)
{
rect.DragOver += (_, e) => e.AcceptedOperation = DataPackageOperation.Copy;
}
}))
};

await UITestHelper.Load(sp);

mouse.MoveTo(source.GetAbsoluteBoundsRect().GetCenter());
await TestServices.WindowHelper.WaitForIdle();
mouse.Press();
await TestServices.WindowHelper.WaitForIdle();
for (int i = 1; i <= 10; i++)
{
mouse.MoveBy(0, (target.GetAbsoluteBoundsRect().GetMidY() - source.GetAbsoluteBoundsRect().GetMidY()) * 0.1);
await TestServices.WindowHelper.WaitForIdle();
}
mouse.Release();
await TestServices.WindowHelper.WaitForIdle();

Assert.AreEqual(setAcceptedOperation ? 1 : 0, dropCount);
}

[TestMethod]
[RunsOnUIThread]
[DataRow(true)]
Expand Down

0 comments on commit d974132

Please sign in to comment.