TreeViewTests.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using JetBrains.Annotations;
  2. namespace UnitTests_Parallelizable.ViewsTests;
  3. [TestSubject (typeof (TreeView))]
  4. public class TreeViewTests
  5. {
  6. [Fact]
  7. public void TreeView_CollectionNavigatorMatcher_KeybindingsOverrideNavigator ()
  8. {
  9. var tree = new TreeView ();
  10. tree.AddObjects ([
  11. new TreeNode(){ Text="apricot" },
  12. new TreeNode(){ Text="arm" },
  13. new TreeNode(){ Text="bat" },
  14. new TreeNode(){ Text="batman" },
  15. new TreeNode(){ Text="bates hotel" },
  16. new TreeNode(){ Text="candle" },
  17. ]);
  18. tree.SetFocus ();
  19. tree.KeyBindings.Add (Key.B, Command.Down);
  20. Assert.Equal ("apricot", tree.SelectedObject.Text);
  21. // Keys should be consumed to move down the navigation i.e. to apricot
  22. Assert.True (tree.NewKeyDownEvent (Key.B));
  23. Assert.NotNull (tree.SelectedObject);
  24. Assert.Equal ("arm", tree.SelectedObject.Text);
  25. Assert.True (tree.NewKeyDownEvent (Key.B));
  26. Assert.Equal ("bat", tree.SelectedObject.Text);
  27. // There is no keybinding for Key.C so it hits collection navigator i.e. we jump to candle
  28. Assert.True (tree.NewKeyDownEvent (Key.C));
  29. Assert.Equal ("candle", tree.SelectedObject.Text);
  30. }
  31. }