From ca02947c3ee9d24782146e2e784c50b84a16ca5c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 18 May 2023 10:35:08 +0200 Subject: [PATCH] Added failing test for VirtualizingStackPanel. --- .../VirtualizingStackPanelTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs b/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs index aa03a77d70..1fddaab910 100644 --- a/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs @@ -657,6 +657,40 @@ namespace Avalonia.Controls.UnitTests root.LayoutManager.ExecuteLayoutPass(); } + [Fact] + public void ScrollIntoView_On_Effectively_Invisible_Panel_Does_Not_Create_Ghost_Elements() + { + var items = new[] { "foo", "bar", "baz" }; + var (target, _, itemsControl) = CreateUnrootedTarget(items: items); + var container = new Decorator { Margin = new Thickness(100), Child = itemsControl }; + var root = new TestRoot(true, container); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // Clear the items and do a layout to recycle all elements. + itemsControl.ItemsSource = null; + root.LayoutManager.ExecuteLayoutPass(); + + // Should have no realized elements and 3 unrealized elements. + Assert.Equal(0, target.GetRealizedElements().Count); + Assert.Equal(3, target.Children.Count); + + // Make the panel effectively invisible and set items. + container.IsVisible = false; + itemsControl.ItemsSource = items; + + // Try to scroll into view while effectively invisible. + target.ScrollIntoView(0); + + // Make the panel visible and layout. + container.IsVisible = true; + root.LayoutManager.ExecuteLayoutPass(); + + // Should have 3 realized elements and no unrealized elements. + Assert.Equal(3, target.GetRealizedElements().Count); + Assert.Equal(3, target.Children.Count); + } + private static IReadOnlyList GetRealizedIndexes(VirtualizingStackPanel target, ItemsControl itemsControl) { return target.GetRealizedElements()