Browse Source

Merge branch 'master' into feature/lazy-load-resources

pull/8422/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
0da95cbe3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Controls/ListBox.cs
  2. 2
      src/Avalonia.Controls/TreeView.cs
  3. 30
      src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml
  4. 133
      tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs
  5. 89
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  6. 542
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs
  7. 38
      tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

3
src/Avalonia.Controls/ListBox.cs

@ -6,6 +6,7 @@ using Avalonia.Controls.Primitives;
using Avalonia.Controls.Selection; using Avalonia.Controls.Selection;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.VisualTree; using Avalonia.VisualTree;
namespace Avalonia.Controls namespace Avalonia.Controls
@ -157,7 +158,7 @@ namespace Avalonia.Controls
e.Source, e.Source,
true, true,
e.KeyModifiers.HasAllFlags(KeyModifiers.Shift), e.KeyModifiers.HasAllFlags(KeyModifiers.Shift),
e.KeyModifiers.HasAllFlags(KeyModifiers.Control), e.KeyModifiers.HasAllFlags(AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>().CommandModifiers),
point.Properties.IsRightButtonPressed); point.Properties.IsRightButtonPressed);
} }
} }

2
src/Avalonia.Controls/TreeView.cs

@ -529,7 +529,7 @@ namespace Avalonia.Controls
e.Source, e.Source,
true, true,
e.KeyModifiers.HasAllFlags(KeyModifiers.Shift), e.KeyModifiers.HasAllFlags(KeyModifiers.Shift),
e.KeyModifiers.HasAllFlags(KeyModifiers.Control), e.KeyModifiers.HasAllFlags(AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>().CommandModifiers),
point.Properties.IsRightButtonPressed); point.Properties.IsRightButtonPressed);
} }
} }

30
src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

@ -41,13 +41,31 @@
<StreamGeometry x:Key="ButtonSpinnerIncreaseButtonIcon">M0,9 L10,0 20,9 19,10 10,2 1,10 z</StreamGeometry> <StreamGeometry x:Key="ButtonSpinnerIncreaseButtonIcon">M0,9 L10,0 20,9 19,10 10,2 1,10 z</StreamGeometry>
<StreamGeometry x:Key="ButtonSpinnerDecreaseButtonIcon">M0,1 L10,10 20,1 19,0 10,8 1,0 z</StreamGeometry> <StreamGeometry x:Key="ButtonSpinnerDecreaseButtonIcon">M0,1 L10,10 20,1 19,0 10,8 1,0 z</StreamGeometry>
<ControlTheme x:Key="FluentButtonSpinnerRepeatButton" TargetType="RepeatButton" BasedOn="{StaticResource {x:Type RepeatButton}}"> <ControlTheme x:Key="FluentButtonSpinnerRepeatButton" TargetType="RepeatButton">
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="MinWidth" Value="34" /> <Setter Property="MinWidth" Value="34" />
<Setter Property="VerticalAlignment" Value="Stretch" /> <Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource RepeatButtonBackgroundPointerOver}" />
</Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource RepeatButtonBackgroundPressed}" />
</Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" /> <Setter Property="Foreground" Value="{DynamicResource RepeatButtonForegroundDisabled}" />
<Setter Property="Foreground" Value="{DynamicResource RepeatButtonForegroundDisabled}"/>
</Style> </Style>
</ControlTheme> </ControlTheme>
@ -83,7 +101,6 @@
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerLeftThickness}}" BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerLeftThickness}}"
CornerRadius="0"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
@ -99,7 +116,6 @@
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerLeftThickness}}" BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerLeftThickness}}"
CornerRadius="0"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"

133
tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs

@ -5,10 +5,12 @@ using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Avalonia.VisualTree; using Avalonia.VisualTree;
using Moq;
using Xunit; using Xunit;
namespace Avalonia.Controls.UnitTests namespace Avalonia.Controls.UnitTests
@ -60,104 +62,123 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Clicking_Item_Should_Select_It() public void Clicking_Item_Should_Select_It()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
}; Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " },
ApplyTemplate(target); };
_mouse.Click(target.Presenter.Panel.Children[0]); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target);
Assert.Equal(0, target.SelectedIndex); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(0, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Clicking_Selected_Item_Should_Not_Deselect_It() public void Clicking_Selected_Item_Should_Not_Deselect_It()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
}; Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " },
ApplyTemplate(target); };
target.SelectedIndex = 0; AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target);
target.SelectedIndex = 0;
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Clicking_Item_Should_Select_It_When_SelectionMode_Toggle() public void Clicking_Item_Should_Select_It_When_SelectionMode_Toggle()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, Template = new FuncControlTemplate(CreateListBoxTemplate),
}; Items = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
ApplyTemplate(target); };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target);
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Clicking_Selected_Item_Should_Deselect_It_When_SelectionMode_Toggle() public void Clicking_Selected_Item_Should_Deselect_It_When_SelectionMode_Toggle()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
SelectionMode = SelectionMode.Toggle, Template = new FuncControlTemplate(CreateListBoxTemplate),
}; Items = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Toggle,
};
ApplyTemplate(target); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.SelectedIndex = 0; ApplyTemplate(target);
target.SelectedIndex = 0;
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(-1, target.SelectedIndex); Assert.Equal(-1, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Clicking_Selected_Item_Should_Not_Deselect_It_When_SelectionMode_ToggleAlwaysSelected() public void Clicking_Selected_Item_Should_Not_Deselect_It_When_SelectionMode_ToggleAlwaysSelected()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected, Template = new FuncControlTemplate(CreateListBoxTemplate),
}; Items = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected,
ApplyTemplate(target); };
target.SelectedIndex = 0; AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target);
target.SelectedIndex = 0;
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Clicking_Another_Item_Should_Select_It_When_SelectionMode_Toggle() public void Clicking_Another_Item_Should_Select_It_When_SelectionMode_Toggle()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, Template = new FuncControlTemplate(CreateListBoxTemplate),
}; Items = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
ApplyTemplate(target); };
target.SelectedIndex = 1; AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target);
target.SelectedIndex = 1;
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
}
} }
[Fact] [Fact]

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

@ -14,6 +14,7 @@ using Avalonia.Controls.Selection;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Markup.Data; using Avalonia.Markup.Data;
using Avalonia.Platform; using Avalonia.Platform;
@ -1115,42 +1116,48 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Setting_SelectedItem_With_Pointer_Should_Set_TabOnceActiveElement() public void Setting_SelectedItem_With_Pointer_Should_Set_TabOnceActiveElement()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz " }, {
}; Template = Template(),
Items = new[] { "Foo", "Bar", "Baz " },
Prepare(target); };
_helper.Down((Interactive)target.Presenter.Panel.Children[1]); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target);
_helper.Down((Interactive)target.Presenter.Panel.Children[1]);
var panel = target.Presenter.Panel; var panel = target.Presenter.Panel;
Assert.Equal( Assert.Equal(
KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel), KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel),
panel.Children[1]); panel.Children[1]);
}
} }
[Fact] [Fact]
public void Removing_SelectedItem_Should_Clear_TabOnceActiveElement() public void Removing_SelectedItem_Should_Clear_TabOnceActiveElement()
{ {
var items = new ObservableCollection<string>(new[] { "Foo", "Bar", "Baz " }); using (UnitTestApplication.Start())
var target = new ListBox
{ {
Template = Template(), var items = new ObservableCollection<string>(new[] { "Foo", "Bar", "Baz " });
Items = items,
};
Prepare(target); var target = new ListBox
{
Template = Template(),
Items = items,
};
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target);
_helper.Down(target.Presenter.Panel.Children[1]); _helper.Down(target.Presenter.Panel.Children[1]);
items.RemoveAt(1); items.RemoveAt(1);
var panel = target.Presenter.Panel; var panel = target.Presenter.Panel;
Assert.Null(KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel)); Assert.Null(KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel));
}
} }
[Fact] [Fact]
@ -1230,31 +1237,37 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Should_Select_Correct_Item_When_Duplicate_Items_Are_Present() public void Should_Select_Correct_Item_When_Duplicate_Items_Are_Present()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
}; Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
Prepare(target); };
_helper.Down((Interactive)target.Presenter.Panel.Children[3]); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target);
_helper.Down((Interactive)target.Presenter.Panel.Children[3]);
Assert.Equal(3, target.SelectedIndex); Assert.Equal(3, target.SelectedIndex);
}
} }
[Fact] [Fact]
public void Should_Apply_Selected_Pseudoclass_To_Correct_Item_When_Duplicate_Items_Are_Present() public void Should_Apply_Selected_Pseudoclass_To_Correct_Item_When_Duplicate_Items_Are_Present()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
}; Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
Prepare(target); };
_helper.Down((Interactive)target.Presenter.Panel.Children[3]); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target);
_helper.Down((Interactive)target.Presenter.Panel.Children[3]);
Assert.Equal(new[] { ":pressed", ":selected" }, target.Presenter.Panel.Children[3].Classes); Assert.Equal(new[] { ":pressed", ":selected" }, target.Presenter.Panel.Children[3].Classes);
}
} }
[Fact] [Fact]

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

@ -10,8 +10,10 @@ using Avalonia.Controls.Selection;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Moq;
using Xunit; using Xunit;
namespace Avalonia.Controls.UnitTests.Primitives namespace Avalonia.Controls.UnitTests.Primitives
@ -701,261 +703,290 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Shift_Selecting_From_No_Selection_Selects_From_Start() public void Shift_Selecting_From_No_Selection_Selects_From_Start()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift); target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var panel = target.Presenter.Panel; _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems); var panel = target.Presenter.Panel;
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
}
} }
[Fact] [Fact]
public void Ctrl_Selecting_Raises_SelectionChanged_Events() public void Ctrl_Selecting_Raises_SelectionChanged_Events()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
target.SelectionChanged += (_, args) => receivedArgs = args; target.SelectionChanged += (_, args) => receivedArgs = args;
void VerifyAdded(string selection) void VerifyAdded(string selection)
{ {
Assert.NotNull(receivedArgs); Assert.NotNull(receivedArgs);
Assert.Equal(new[] { selection }, receivedArgs.AddedItems); Assert.Equal(new[] { selection }, receivedArgs.AddedItems);
Assert.Empty(receivedArgs.RemovedItems); Assert.Empty(receivedArgs.RemovedItems);
} }
void VerifyRemoved(string selection) void VerifyRemoved(string selection)
{ {
Assert.NotNull(receivedArgs); Assert.NotNull(receivedArgs);
Assert.Equal(new[] { selection }, receivedArgs.RemovedItems); Assert.Equal(new[] { selection }, receivedArgs.RemovedItems);
Assert.Empty(receivedArgs.AddedItems); Assert.Empty(receivedArgs.AddedItems);
} }
_helper.Click((Interactive)target.Presenter.Panel.Children[1]); _helper.Click((Interactive)target.Presenter.Panel.Children[1]);
VerifyAdded("Bar"); VerifyAdded("Bar");
receivedArgs = null; receivedArgs = null;
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
VerifyAdded("Baz"); VerifyAdded("Baz");
receivedArgs = null; receivedArgs = null;
_helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
VerifyAdded("Qux"); VerifyAdded("Qux");
receivedArgs = null; receivedArgs = null;
_helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
VerifyRemoved("Bar"); VerifyRemoved("Bar");
}
} }
[Fact] [Fact]
public void Ctrl_Selecting_SelectedItem_With_Multiple_Selection_Active_Sets_SelectedItem_To_Next_Selection() public void Ctrl_Selecting_SelectedItem_With_Multiple_Selection_Active_Sets_SelectedItem_To_Next_Selection()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[1]); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[1]);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
Assert.Equal(1, target.SelectedIndex); _helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
Assert.Equal("Bar", target.SelectedItem);
Assert.Equal(new[] { "Bar", "Baz", "Qux" }, target.SelectedItems); Assert.Equal(1, target.SelectedIndex);
Assert.Equal("Bar", target.SelectedItem);
_helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control); Assert.Equal(new[] { "Bar", "Baz", "Qux" }, target.SelectedItems);
Assert.Equal(2, target.SelectedIndex); _helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
Assert.Equal("Baz", target.SelectedItem);
Assert.Equal(new[] { "Baz", "Qux" }, target.SelectedItems); Assert.Equal(2, target.SelectedIndex);
Assert.Equal("Baz", target.SelectedItem);
Assert.Equal(new[] { "Baz", "Qux" }, target.SelectedItems);
}
} }
[Fact] [Fact]
public void Ctrl_Selecting_Non_SelectedItem_With_Multiple_Selection_Active_Leaves_SelectedItem_The_Same() public void Ctrl_Selecting_Non_SelectedItem_With_Multiple_Selection_Active_Leaves_SelectedItem_The_Same()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
};
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.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);
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
Assert.Equal("Bar", target.SelectedItem); Assert.Equal("Bar", target.SelectedItem);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
Assert.Equal("Bar", target.SelectedItem); Assert.Equal("Bar", target.SelectedItem);
}
} }
[Fact] [Fact]
public void Should_Ctrl_Select_Correct_Item_When_Duplicate_Items_Are_Present() public void Should_Ctrl_Select_Correct_Item_When_Duplicate_Items_Are_Present()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[3]); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[3]);
var panel = target.Presenter.Panel; _helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems); var panel = target.Presenter.Panel;
Assert.Equal(new[] { 3, 4 }, SelectedContainers(target));
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
Assert.Equal(new[] { 3, 4 }, SelectedContainers(target));
}
} }
[Fact] [Fact]
public void Should_Shift_Select_Correct_Item_When_Duplicates_Are_Present() public void Should_Shift_Select_Correct_Item_When_Duplicates_Are_Present()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[3]); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[3]);
var panel = target.Presenter.Panel; _helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems); var panel = target.Presenter.Panel;
Assert.Equal(new[] { 3, 4, 5 }, SelectedContainers(target));
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
Assert.Equal(new[] { 3, 4, 5 }, SelectedContainers(target));
}
} }
[Fact] [Fact]
public void Can_Shift_Select_All_Items_When_Duplicates_Are_Present() public void Can_Shift_Select_All_Items_When_Duplicates_Are_Present()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]);
var panel = target.Presenter.Panel; _helper.Click((Interactive)target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
Assert.Equal(new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, target.SelectedItems); var panel = target.Presenter.Panel;
Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, SelectedContainers(target));
Assert.Equal(new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, target.SelectedItems);
Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, SelectedContainers(target));
}
} }
[Fact] [Fact]
public void Shift_Selecting_Raises_SelectionChanged_Events() public void Shift_Selecting_Raises_SelectionChanged_Events()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
target.SelectionChanged += (_, args) => receivedArgs = args; target.SelectionChanged += (_, args) => receivedArgs = args;
void VerifyAdded(params string[] selection) void VerifyAdded(params string[] selection)
{ {
Assert.NotNull(receivedArgs); Assert.NotNull(receivedArgs);
Assert.Equal(selection, receivedArgs.AddedItems); Assert.Equal(selection, receivedArgs.AddedItems);
Assert.Empty(receivedArgs.RemovedItems); Assert.Empty(receivedArgs.RemovedItems);
} }
void VerifyRemoved(string selection) void VerifyRemoved(string selection)
{ {
Assert.NotNull(receivedArgs); Assert.NotNull(receivedArgs);
Assert.Equal(new[] { selection }, receivedArgs.RemovedItems); Assert.Equal(new[] { selection }, receivedArgs.RemovedItems);
Assert.Empty(receivedArgs.AddedItems); Assert.Empty(receivedArgs.AddedItems);
} }
_helper.Click((Interactive)target.Presenter.Panel.Children[1]); _helper.Click((Interactive)target.Presenter.Panel.Children[1]);
VerifyAdded("Bar"); VerifyAdded("Bar");
receivedArgs = null; receivedArgs = null;
_helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Shift);
VerifyAdded("Baz" ,"Qux"); VerifyAdded("Baz", "Qux");
receivedArgs = null; receivedArgs = null;
_helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift); _helper.Click((Interactive)target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
VerifyRemoved("Qux"); VerifyRemoved("Qux");
}
} }
[Fact] [Fact]
public void Duplicate_Items_Are_Added_To_SelectedItems_In_Order() public void Duplicate_Items_Are_Added_To_SelectedItems_In_Order()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, {
SelectionMode = SelectionMode.Multiple, Template = Template(),
}; Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple,
};
target.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.Presenter.ApplyTemplate(); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(new[] { "Foo" }, target.SelectedItems); Assert.Equal(new[] { "Foo" }, target.SelectedItems);
_helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems); Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
_helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
Assert.Equal(new[] { "Foo", "Bar", "Foo" }, target.SelectedItems); Assert.Equal(new[] { "Foo", "Bar", "Foo" }, target.SelectedItems);
_helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control); _helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
Assert.Equal(new[] { "Foo", "Bar", "Foo", "Bar" }, target.SelectedItems); Assert.Equal(new[] { "Foo", "Bar", "Foo", "Bar" }, target.SelectedItems);
}
} }
[Fact] [Fact]
@ -1158,70 +1189,79 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Left_Click_On_SelectedItem_Should_Clear_Existing_Selection() public void Left_Click_On_SelectedItem_Should_Clear_Existing_Selection()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), Template = Template(),
SelectionMode = SelectionMode.Multiple, Items = new[] { "Foo", "Bar", "Baz" },
}; ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.SelectAll(); target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Equal(3, target.SelectedItems.Count); target.SelectAll();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); Assert.Equal(3, target.SelectedItems.Count);
Assert.Equal(1, target.SelectedItems.Count); _helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(new[] { "Foo", }, target.SelectedItems);
Assert.Equal(new[] { 0 }, SelectedContainers(target)); Assert.Equal(1, target.SelectedItems.Count);
Assert.Equal(new[] { "Foo", }, target.SelectedItems);
Assert.Equal(new[] { 0 }, SelectedContainers(target));
}
} }
[Fact] [Fact]
public void Right_Click_On_SelectedItem_Should_Not_Clear_Existing_Selection() public void Right_Click_On_SelectedItem_Should_Not_Clear_Existing_Selection()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), Template = Template(),
SelectionMode = SelectionMode.Multiple, Items = new[] { "Foo", "Bar", "Baz" },
}; ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.SelectAll(); target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.SelectAll();
Assert.Equal(3, target.SelectedItems.Count); Assert.Equal(3, target.SelectedItems.Count);
_helper.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right); _helper.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right);
Assert.Equal(3, target.SelectedItems.Count); Assert.Equal(3, target.SelectedItems.Count);
}
} }
[Fact] [Fact]
public void Right_Click_On_UnselectedItem_Should_Clear_Existing_Selection() public void Right_Click_On_UnselectedItem_Should_Clear_Existing_Selection()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), Template = Template(),
SelectionMode = SelectionMode.Multiple, Items = new[] { "Foo", "Bar", "Baz" },
}; ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(2, target.SelectedItems.Count); _helper.Click((Interactive)target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift);
_helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right); Assert.Equal(2, target.SelectedItems.Count);
Assert.Equal(1, target.SelectedItems.Count); _helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right);
Assert.Equal(1, target.SelectedItems.Count);
}
} }
[Fact] [Fact]
@ -1253,41 +1293,47 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Shift_Right_Click_Should_Not_Select_Multiple() public void Shift_Right_Click_Should_Not_Select_Multiple()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), Template = Template(),
SelectionMode = SelectionMode.Multiple, Items = new[] { "Foo", "Bar", "Baz" },
}; ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
_helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(1, target.SelectedItems.Count); _helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
Assert.Equal(1, target.SelectedItems.Count);
}
} }
[Fact] [Fact]
public void Ctrl_Right_Click_Should_Not_Select_Multiple() public void Ctrl_Right_Click_Should_Not_Select_Multiple()
{ {
var target = new ListBox using (UnitTestApplication.Start())
{ {
Template = Template(), var target = new ListBox
Items = new[] { "Foo", "Bar", "Baz" }, {
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), Template = Template(),
SelectionMode = SelectionMode.Multiple, Items = new[] { "Foo", "Bar", "Baz" },
}; ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple,
target.ApplyTemplate(); };
target.Presenter.ApplyTemplate(); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
target.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[0]); target.Presenter.ApplyTemplate();
_helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);
_helper.Click((Interactive)target.Presenter.Panel.Children[0]);
Assert.Equal(1, target.SelectedItems.Count); _helper.Click((Interactive)target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);
Assert.Equal(1, target.SelectedItems.Count);
}
} }
[Fact] [Fact]

38
tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

@ -18,6 +18,7 @@ using Avalonia.LogicalTree;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using JetBrains.Annotations; using JetBrains.Annotations;
using Moq;
using Xunit; using Xunit;
namespace Avalonia.Controls.UnitTests namespace Avalonia.Controls.UnitTests
@ -885,28 +886,31 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Right_Click_On_SelectedItem_Should_Not_Clear_Existing_Selection() public void Right_Click_On_SelectedItem_Should_Not_Clear_Existing_Selection()
{ {
var tree = CreateTestTreeData(); using (UnitTestApplication.Start())
var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), var tree = CreateTestTreeData();
Items = tree, var target = new TreeView
SelectionMode = SelectionMode.Multiple, {
}; Template = CreateTreeViewTemplate(),
Items = tree,
var visualRoot = new TestRoot(); SelectionMode = SelectionMode.Multiple,
visualRoot.Child = target; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
var visualRoot = new TestRoot();
visualRoot.Child = target;
CreateNodeDataTemplate(target); CreateNodeDataTemplate(target);
ApplyTemplates(target); ApplyTemplates(target);
target.ExpandSubTree((TreeViewItem)target.Presenter.Panel.Children[0]); target.ExpandSubTree((TreeViewItem)target.Presenter.Panel.Children[0]);
target.SelectAll(); target.SelectAll();
AssertChildrenSelected(target, tree[0]); AssertChildrenSelected(target, tree[0]);
Assert.Equal(5, target.SelectedItems.Count); Assert.Equal(5, target.SelectedItems.Count);
_mouse.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right); _mouse.Click((Interactive)target.Presenter.Panel.Children[0], MouseButton.Right);
Assert.Equal(5, target.SelectedItems.Count); Assert.Equal(5, target.SelectedItems.Count);
}
} }
[Fact] [Fact]

Loading…
Cancel
Save