Browse Source

Added failing tests for #11119.

pull/11141/head
Steven Kirk 3 years ago
parent
commit
2c9f286db0
  1. 65
      tests/Avalonia.Controls.UnitTests/CarouselTests.cs
  2. 52
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs

65
tests/Avalonia.Controls.UnitTests/CarouselTests.cs

@ -261,6 +261,71 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Can_Move_Forward_Back_Forward()
{
using var app = Start();
var items = new[] { "foo", "bar" };
var target = new Carousel
{
Template = CarouselTemplate(),
ItemsSource = items,
};
Prepare(target);
target.SelectedIndex = 1;
Layout(target);
Assert.Equal(1, target.SelectedIndex);
target.SelectedIndex = 0;
Layout(target);
Assert.Equal(0, target.SelectedIndex);
target.SelectedIndex = 1;
Layout(target);
Assert.Equal(1, target.SelectedIndex);
}
[Fact]
public void Can_Move_Forward_Back_Forward_With_Control_Items()
{
// Issue #11119
using var app = Start();
var items = new[] { new Canvas(), new Canvas() };
var target = new Carousel
{
Template = CarouselTemplate(),
ItemsSource = items,
};
Prepare(target);
target.SelectedIndex = 1;
Layout(target);
Assert.Equal(1, target.SelectedIndex);
target.SelectedIndex = 0;
Layout(target);
Assert.Equal(0, target.SelectedIndex);
target.SelectedIndex = 1;
target.PropertyChanged += (s, e) =>
{
if (e.Property == Carousel.SelectedIndexProperty)
{
}
};
Layout(target);
Assert.Equal(1, target.SelectedIndex);
}
private static IDisposable Start() => UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
private static void Prepare(Carousel target)

52
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs

@ -1024,6 +1024,56 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(new[] { 15 }, SelectedContainers(target));
}
[Fact]
public void Can_Change_Selection_For_Containers_Outside_Of_Viewport()
{
// Issue #11119
using var app = Start();
var items = Enumerable.Range(0, 100).Select(x => new TestContainer
{
Content = $"Item {x}",
Height = 100,
}).ToList();
// Create a SelectingItemsControl with a virtualizing stack panel.
var target = CreateTarget(itemsSource: items, virtualizing: true);
target.AutoScrollToSelectedItem = false;
var panel = Assert.IsType<VirtualizingStackPanel>(target.ItemsPanelRoot);
var scroll = panel.FindAncestorOfType<ScrollViewer>()!;
// Select item 1.
target.SelectedIndex = 1;
// Scroll item 1 and 2 out of view.
scroll.Offset = new(0, 1000);
Layout(target);
Assert.Equal(10, panel.FirstRealizedIndex);
Assert.Equal(19, panel.LastRealizedIndex);
// Select item 2 now that items 1 and 2 are both unrealized.
target.SelectedIndex = 2;
// The selection should be updated.
Assert.Empty(SelectedContainers(target));
Assert.Equal(2, target.SelectedIndex);
Assert.Same(items[2], target.SelectedItem);
Assert.Equal(new[] { 2 }, target.Selection.SelectedIndexes);
Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems);
// Scroll selected item back into view.
scroll.Offset = new(0, 0);
Layout(target);
// The selection should be preserved.
Assert.Equal(new[] { 2 }, SelectedContainers(target));
Assert.Equal(2, target.SelectedIndex);
Assert.Same(items[2], target.SelectedItem);
Assert.Equal(new[] { 2 }, target.Selection.SelectedIndexes);
Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems);
}
[Fact]
public void Selection_State_Change_On_Unrealized_Item_Is_Respected_With_IsSelected_Binding()
{
@ -1197,7 +1247,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{
Setters =
{
new Setter(TreeView.TemplateProperty, CreateTestContainerTemplate()),
new Setter(TestContainer.TemplateProperty, CreateTestContainerTemplate()),
},
};
}

Loading…
Cancel
Save