Browse Source

Fixed SelectingItemsControlTests.

`ListBox` now needs a root as it uses a `VirtualizingStackPanel`.
pull/9677/head
Steven Kirk 4 years ago
parent
commit
c1ee26c05a
  1. 136
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs

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

@ -710,14 +710,16 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
var panel = target.Presenter.Panel;
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems); Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target)); Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
} }
@ -733,10 +735,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
@ -787,10 +793,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[1]); _helper.Click((Interactive)target.Presenter.Panel.Children[1]);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
_helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
@ -817,11 +827,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[1]); _helper.Click((Interactive)target.Presenter.Panel.Children[1]);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
@ -845,10 +858,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[3]); _helper.Click((Interactive)target.Presenter.Panel.Children[3]);
_helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
@ -869,10 +886,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[3]); _helper.Click((Interactive)target.Presenter.Panel.Children[3]);
_helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
@ -893,10 +914,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
_helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
@ -917,10 +942,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
@ -966,11 +994,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(new[] { "Foo" }, target.SelectedItems); Assert.Equal(new[] { "Foo" }, target.SelectedItems);
@ -1084,13 +1115,16 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = items, Items = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
target.SelectAll(); target.SelectAll();
items.Insert(0, "Qux"); items.Insert(0, "Qux");
root.LayoutManager.ExecuteLayoutPass();
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
Assert.Equal("Foo", target.SelectedItem); Assert.Equal("Foo", target.SelectedItem);
@ -1146,10 +1180,12 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = items, Items = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
target.SelectAll(); target.SelectAll();
items.RemoveAt(0); items.RemoveAt(0);
@ -1175,10 +1211,12 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
Items = items, Items = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
target.SelectAll(); target.SelectAll();
items[1] = "Qux"; items[1] = "Qux";
@ -1197,10 +1235,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
target.SelectAll(); target.SelectAll();
Assert.Equal(3, target.SelectedItems.Count); Assert.Equal(3, target.SelectedItems.Count);
@ -1224,10 +1265,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate(); var root = new TestRoot(target);
target.Presenter.ApplyTemplate(); root.LayoutManager.ExecuteInitialLayoutPass();
target.SelectAll(); target.SelectAll();
Assert.Equal(3, target.SelectedItems.Count); Assert.Equal(3, target.SelectedItems.Count);
@ -1249,10 +1293,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
_helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift);
@ -1301,10 +1349,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
@ -1324,10 +1376,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
Items = new[] { "Foo", "Bar", "Baz" }, Items = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
}; };
var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);
@ -1526,7 +1582,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
private static IEnumerable<int> SelectedContainers(SelectingItemsControl target) private static IEnumerable<int> SelectedContainers(SelectingItemsControl target)
{ {
return target.Presenter.Panel.Children return target.Presenter.Panel.Children
.Select((x, i) => x.Classes.Contains(":selected") ? i : -1) .Select(x => x.Classes.Contains(":selected") ? target.IndexFromContainer(x) : -1)
.Where(x => x != -1); .Where(x => x != -1);
} }

Loading…
Cancel
Save