From 9e797adccbf20b36d89806a095dbbacb73c12e06 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 2 May 2022 17:29:29 -0400 Subject: [PATCH 1/2] fix(dragdrop): Make sure to disable dragging on LV's ItemContainer --- .../DragDrop_ListViewReorder_Automated.cs | 27 +++++++++++++++++++ .../DragAndDrop/DragDrop_ListView.xaml | 11 +++++--- .../ListViewBase/ListViewBase.DragDrop.cs | 1 + .../UI/Xaml/DragDrop/DragDropManager.cs | 2 +- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs index ccee6f39da00..9b38b65dbc19 100644 --- a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs +++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs @@ -19,6 +19,33 @@ public partial class DragDrop_ListViewReorder_Automated : SampleControlUITestBas private static float Item(IAppRect sut, int index) => sut.Y + (index * _itemHeight) + 25; + [Test] + [AutoRetry] + [ActivePlatforms(Platform.Browser)] // TODO: support drag-and-drop testing on mobile https://github.com/unoplatform/Uno.UITest/issues/31 + public void When_Disabled() + { + Run("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_ListView", skipInitialScreenshot: true); + + var sut = _app.Marked("SUT"); + var mode = _app.Marked("DragMode"); + + mode.SetDependencyPropertyValue("IsChecked", "False"); + + var before = TakeScreenshot("Before", ignoreInSnapshotCompare: true); + + // Attempt to re-order + var sutBounds = _app.Query(sut).Single().Rect; + var x = sutBounds.X + 50; + var srcY = Item(sutBounds, 1); + var dstY = Item(sutBounds, 3); + + _app.DragCoordinates(x, srcY, x, dstY); + + var after = TakeScreenshot("After", ignoreInSnapshotCompare: true); + + ImageAssert.AreEqual(before, after, sutBounds); + } + [Test] [AutoRetry] [ActivePlatforms(Platform.Browser)] // TODO: support drag-and-drop testing on mobile https://github.com/unoplatform/Uno.UITest/issues/31 diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml index 1ff554f5a136..8ac2d13e3ee3 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml @@ -14,9 +14,9 @@ @@ -29,6 +29,9 @@ - + + + + diff --git a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs index 9e77a6bdefe8..7e7008c49deb 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs @@ -106,6 +106,7 @@ private static void ClearContainerForDragDrop(UIElement itemContainer) return; } + itemContainer.CanDrag = false; itemContainer.DragStarting -= OnItemContainerDragStarting; itemContainer.DropCompleted -= OnItemContainerDragCompleted; diff --git a/src/Uno.UI/UI/Xaml/DragDrop/DragDropManager.cs b/src/Uno.UI/UI/Xaml/DragDrop/DragDropManager.cs index 65f12dd594ca..b4d0b72c9ebb 100644 --- a/src/Uno.UI/UI/Xaml/DragDrop/DragDropManager.cs +++ b/src/Uno.UI/UI/Xaml/DragDrop/DragDropManager.cs @@ -102,7 +102,7 @@ public DataPackageOperation ProcessAborted(IDragEventSource src) => FindOperation(src)?.Aborted(src) ?? DataPackageOperation.None; private DragOperation? FindOperation(IDragEventSource src) - => _dragOperations.FirstOrDefault(drag => drag.Info.SourceId == src.Id); + => _dragOperations.FirstOrDefault(drag => drag.Info.SourceId == src.Id); private void RegisterWindowHandlers() { From b7b421ec0640e0b21340f44c664e4338447eccde Mon Sep 17 00:00:00 2001 From: David Date: Tue, 3 May 2022 09:55:27 -0400 Subject: [PATCH 2/2] test: Fix failing tests on CI due to scrolling kicking-in --- .../DragAndDropTests/DragDrop_ListViewReorder_Automated.cs | 6 ++++-- .../Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs index 9b38b65dbc19..00f278e02d9b 100644 --- a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs +++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_ListViewReorder_Automated.cs @@ -15,7 +15,7 @@ namespace SamplesApp.UITests.Windows_UI_Xaml.DragAndDropTests public partial class DragDrop_ListViewReorder_Automated : SampleControlUITestBase { private static readonly string[] _items = new[] { "#FF0018", "#FFA52C", "#FFFF41", "#008018", "#0000F9", "#86007D" }; - private const int _itemHeight = 100; + private const int _itemHeight = 90; private static float Item(IAppRect sut, int index) => sut.Y + (index * _itemHeight) + 25; @@ -43,7 +43,9 @@ public void When_Disabled() var after = TakeScreenshot("After", ignoreInSnapshotCompare: true); - ImageAssert.AreEqual(before, after, sutBounds); + // note: we test only 100 pixels width to avoid failure due to scrollbar being visible in "after" screenshot + var testBounds = new Rectangle((int)sutBounds.X, (int)sutBounds.Y, 100, (int)sutBounds.Height); + ImageAssert.AreEqual(before, after, testBounds); } [Test] diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml index 8ac2d13e3ee3..5d7a8a5860c7 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_ListView.xaml @@ -22,16 +22,17 @@ x:Name="SUT"> - + - + + + -