Skip to content

Commit

Permalink
test: add a test with a subclass of an ObserverableCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Aug 6, 2024
1 parent 6ec08e3 commit 54b3ee0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4679,6 +4679,56 @@ public async Task When_UpdateLayout_In_DragDropping()
}
#endif

#if HAS_UNO
[TestMethod]
[RunsOnUIThread]
#if !HAS_INPUT_INJECTOR
[Ignore("InputInjector is only supported on skia")]
#endif
public async Task When_DragDrop_ItemsSource_Is_Subclass_Of_ObservableCollection()
{
var SUT = new ListView
{
AllowDrop = true,
CanDragItems = true,
CanReorderItems = true,
ItemsSource = new SubclassOfObservableCollection
{
"0",
"1",
"2"
}
};

await UITestHelper.Load(SUT);

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

// drag(pick-up) item#0
mouse.MoveTo(SUT.GetAbsoluteBoundsRect().Location + new Point(20, SUT.ActualHeight / 6));
await WindowHelper.WaitForIdle();
mouse.Press();
await WindowHelper.WaitForIdle();

// drop onto item#1
mouse.MoveTo(SUT.GetAbsoluteBoundsRect().Location + new Point(20, SUT.ActualHeight * 2 / 6));
await WindowHelper.WaitForIdle();
mouse.MoveTo(SUT.GetAbsoluteBoundsRect().Location + new Point(20, SUT.ActualHeight * 3 / 6));
await WindowHelper.WaitForIdle();
mouse.Release();
await WindowHelper.WaitForIdle();

var textBlocks = SUT.FindFirstDescendant<ItemsStackPanel>().Children
.Select(c => c.FindFirstDescendant<TextBlock>())
.OrderBy(c => c.GetAbsoluteBoundsRect().Y)
.ToList();
Assert.AreEqual("1", textBlocks[0].Text);
Assert.AreEqual("0", textBlocks[1].Text);
Assert.AreEqual("2", textBlocks[2].Text);
}
#endif

[TestMethod]
[RunsOnUIThread]
public async Task When_ScrollIntoView_FreshlyAddedDefaultItem() // checks against #17695
Expand Down Expand Up @@ -5199,5 +5249,9 @@ public override string ToString()
return Name;
}
}

public class SubclassOfObservableCollection : ObservableCollection<string>
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private void CleanupReordering()
private static bool IsObservableCollection(object src)
{
var type = src.GetType();

while (type != null && type != typeof(object))
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ObservableCollection<>))
Expand Down

0 comments on commit 54b3ee0

Please sign in to comment.