From 62e7dbded926a33415b5c2d636dced2203f4b4aa Mon Sep 17 00:00:00 2001 From: Deadpikle Date: Wed, 13 May 2020 11:51:22 -0400 Subject: [PATCH] Add more tests for selection adjustments --- .../SelectionModelTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs b/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs index 60fe9f3674..9d795f6247 100644 --- a/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs @@ -1762,6 +1762,18 @@ namespace Avalonia.Controls.UnitTests Assert.Empty(target.SelectedIndices); } + [Fact] + public void Assigning_Source_With_Less_Items_Than_Previous_Clears_Selection() + { + var data = new[] { "foo", "bar", "baz", "boo", "hoo" }; + var smallerData = new[] { "foo", "bar", "baz" }; + var target = new SelectionModel { RetainSelectionOnReset = true }; + target.Source = data; + target.SelectedIndex = new IndexPath(4); + target.Source = smallerData; + Assert.Empty(target.SelectedIndices); + } + [Fact] public void Assigning_Source_With_Less_Items_Than_Selection_Trims_Selection() { @@ -1772,6 +1784,18 @@ namespace Avalonia.Controls.UnitTests Assert.Empty(target.SelectedIndices); } + [Fact] + public void Assigning_Source_With_Less_Items_Than_Multiple_Selection_Trims_Selection() + { + var data = new[] { "foo", "bar", "baz" }; + var target = new SelectionModel { RetainSelectionOnReset = true }; + target.Select(4); + target.Select(2); + target.Source = data; + Assert.Equal(1, target.SelectedIndices.Count); + Assert.Equal(new IndexPath(2), target.SelectedIndices.First()); + } + private int GetSubscriberCount(AvaloniaList list) { return ((INotifyCollectionChangedDebug)list).GetCollectionChangedSubscribers()?.Length ?? 0;