Browse Source

Add failing tests

pull/3186/head
Benedikt Schroeder 7 years ago
parent
commit
e2ff454085
  1. 10
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  2. 37
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

10
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -367,17 +367,17 @@ namespace Avalonia.Controls.Primitives
{
if ((container.ContainerControl as ISelectable)?.IsSelected == true)
{
if (SelectionMode.HasFlag(SelectionMode.Multiple))
if (SelectedIndex == -1)
{
SelectedIndex = container.Index;
}
else
{
if (_selection.Add(container.Index))
{
resetSelectedItems = true;
}
}
else
{
SelectedIndex = container.Index;
}
MarkContainerSelected(container.ContainerControl, true);
}

37
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -1185,6 +1185,33 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.MoveSelection(NavigationDirection.Next, true);
}
[Fact]
public void Pre_Selecting_Item_Should_Set_Selection_After_It_Was_Added_When_AlwaysSelected()
{
var target = new TestSelector(SelectionMode.AlwaysSelected)
{
Template = Template()
};
var second = new Item { IsSelected = true };
var items = new AvaloniaList<object>
{
new Item(),
second
};
target.Items = items;
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Equal(second, target.SelectedItem);
Assert.Equal(1, target.SelectedIndex);
}
private FuncControlTemplate Template()
{
return new FuncControlTemplate<SelectingItemsControl>((control, scope) =>
@ -1233,6 +1260,16 @@ namespace Avalonia.Controls.UnitTests.Primitives
private class TestSelector : SelectingItemsControl
{
public TestSelector()
{
}
public TestSelector(SelectionMode selectionMode)
{
SelectionMode = selectionMode;
}
public new bool MoveSelection(NavigationDirection direction, bool wrap)
{
return base.MoveSelection(direction, wrap);

Loading…
Cancel
Save