Files
Terminal.Gui/Tests/UnitTestsParallelizable/Views/TreeViewTests.cs
Thomas Nind 0a23df75da Fixes #4027. Add collection search matcher (#4029)
* Add collection search matcher

* Fix naming

* fix naming

* Move FileDialogCollectionNavigator to its own file (no longer private class)
Add class diagram for collectionNavigation

* Add ICollectionNavigator interface

* Move to separate file IListCollectionNavigator

* Update class diagram

* update class diagram

* Add tests for overriding ICollectionNavigatorMatcher

* xmldoc and nullability warning fixes

* Code Cleanup

* Make requested changes to naming and terminology

* Move to seperate namespace

* Update class diagram and change TreeView to reference the interface not concrete class

* Switch to implicit new

* highlight that this class also works with tree view

* Apply tig patch to ensure keybindings get priority over navigator

See: https://github.com/gui-cs/Terminal.Gui/issues/4027#issuecomment-2810020893

* Apply 'keybinding has priority' fix to TreeView too

* Apply 'keybindngs priority over navigation' fix to TableView

* Remove entire branch for selectively returning false now that it is default when there is a keybinding collision

* Make classes internal and remove 'custom' navigator that was configured in UICatlaogToplevel

* Change logging in collection navigator from Trace to Debug

* Switch to NewKeyDownEvent and directly setting HasFocus

* Remove application top dependency

* Remove references to application

* Remove Application

* Move new tests to parallel

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
2025-05-29 14:08:47 -06:00

41 lines
1.4 KiB
C#

using JetBrains.Annotations;
namespace Terminal.Gui.ViewsTests;
[TestSubject (typeof (TreeView))]
public class TreeViewTests
{
[Fact]
public void TreeView_CollectionNavigatorMatcher_KeybindingsOverrideNavigator ()
{
var tree = new TreeView ();
tree.AddObjects ([
new TreeNode(){ Text="apricot" },
new TreeNode(){ Text="arm" },
new TreeNode(){ Text="bat" },
new TreeNode(){ Text="batman" },
new TreeNode(){ Text="bates hotel" },
new TreeNode(){ Text="candle" },
]);
tree.SetFocus ();
tree.KeyBindings.Add (Key.B, Command.Down);
Assert.Equal ("apricot", tree.SelectedObject.Text);
// Keys should be consumed to move down the navigation i.e. to apricot
Assert.True (tree.NewKeyDownEvent (Key.B));
Assert.NotNull (tree.SelectedObject);
Assert.Equal ("arm", tree.SelectedObject.Text);
Assert.True (tree.NewKeyDownEvent (Key.B));
Assert.Equal ("bat", tree.SelectedObject.Text);
// There is no keybinding for Key.C so it hits collection navigator i.e. we jump to candle
Assert.True (tree.NewKeyDownEvent (Key.C));
Assert.Equal ("candle", tree.SelectedObject.Text);
}
}