Files
Terminal.Gui/UnitTests/View/ViewKeyBindingTests.cs
Tig d2ad11248f Fixes #3127 - View Layout improvements - Redefines how LayoutStyle works. Fixes AutoSize etc... (#3130)
* Removes CheckAbsoulte and updates unit tests to match

* Fixed code that was dependent on ToString behavior vs. direct test for null

* Dim/Pos != null WIP

* Moved AutoSize specific tests out of Pos/Dim tests

* Broke out AutoSize = false tests to new file

* Commented test TODOs

* New test

* Removed unused API and cleaned up code

* Removed unused API and cleaned up code

* Cleaned up code

* Cleaned up code

* reorg'd Toplevel tests

* Fixed Create and related unit tests

* Added test from #3136

* Removed TopLevel.Create

* Fixed SetCurrentOverlappedAsTop

* Updated pull request template

* Updated pull request template

* Revert "Updated pull request template"

This reverts commit d807190dd9.

* reverting

* re-reverting

* Fixed every thing but autosize scenarios??

* Fixed hexview

* Fixed contextmenu

* Fixed more minor issues in tests

* Fixed more minor issues in tests

* Debugging Dialog test failure

* Fixed bad Dialog test. Was cleary invalid

* Fixed OnResizeNeeded bug

* Fixed OnResizeNeeded bug

* Fixed UICatalog to not eat exceptions

* Fixed TextView

* Removed Frame overrides

* Made Frame non-virtual

* Fixed radioGroup

* Fixed TabView

* Hcked ScrolLBarView unit tests to pass

* All AutoSize tests pass!

* All tests pass!!!!!!!

* Updated API docs. Cleaned up code.

* Fixed ColorPicker

* Added 'Bounds =' unit tests

* Refactored TextFormatter.Size setting logic

* Cleaned up OnResizeNeeded (api docs and usages)

* Merges in #3019 changes. Makes OnResizeNeeded non-virtual. If we find a use-case where someone wants to override it we can change this back.

* Fixed FileDialog bounds warning

* Removed resharper settings from editorconfig

* Added Pos.Center test to AllViewsTests.cs.
Modernized RadioGroup.
Fixed ProgressBar.

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Reverted formatting
2024-01-12 17:43:35 -07:00

148 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewTests;
public class ViewKeyBindingTests {
readonly ITestOutputHelper _output;
public ViewKeyBindingTests (ITestOutputHelper output)
{
this._output = output;
}
// tests that test KeyBindingScope.Focus and KeyBindingScope.HotKey (tests for KeyBindingScope.Application are in Application/KeyboardTests.cs)
public class ScopedKeyBindingView : View {
public bool ApplicationCommand { get; set; }
public bool HotKeyCommand { get; set; }
public bool FocusedCommand { get; set; }
public ScopedKeyBindingView ()
{
AddCommand (Command.Save, () => ApplicationCommand = true);
AddCommand (Command.Default, () => HotKeyCommand = true);
AddCommand (Command.Left, () => FocusedCommand = true);
KeyBindings.Add (KeyCode.A, KeyBindingScope.Application, Command.Save);
HotKey = KeyCode.H;
KeyBindings.Add (KeyCode.F, KeyBindingScope.Focused, Command.Left);
}
}
[Fact]
[AutoInitShutdown]
public void Focus_KeyBinding ()
{
var view = new ScopedKeyBindingView ();
var invoked = false;
view.InvokingKeyBindings += (s, e) => invoked = true;
Application.Top.Add (view);
Application.Begin (Application.Top);
Application.OnKeyDown (new (KeyCode.A));
Assert.True (invoked);
invoked = false;
Application.OnKeyDown (new (KeyCode.H));
Assert.True (invoked);
invoked = false;
Assert.False (view.HasFocus);
Application.OnKeyDown (new (KeyCode.F));
Assert.False (invoked);
Assert.False (view.FocusedCommand);
invoked = false;
view.CanFocus = true;
view.SetFocus ();
Assert.True (view.HasFocus);
Application.OnKeyDown (new (KeyCode.F));
Assert.True (invoked);
Assert.True (view.ApplicationCommand);
Assert.True (view.HotKeyCommand);
Assert.True (view.FocusedCommand);
}
[Fact]
[AutoInitShutdown]
public void Focus_KeyBinding_Negative ()
{
var view = new ScopedKeyBindingView ();
var invoked = false;
view.InvokingKeyBindings += (s, e) => invoked = true;
Application.Top.Add (view);
Application.Begin (Application.Top);
Application.OnKeyDown (new (KeyCode.Z));
Assert.False (invoked);
Assert.False (view.ApplicationCommand);
Assert.False (view.HotKeyCommand);
Assert.False (view.FocusedCommand);
invoked = false;
Assert.False (view.HasFocus);
Application.OnKeyDown (new (KeyCode.F));
Assert.False (invoked);
Assert.False (view.ApplicationCommand);
Assert.False (view.HotKeyCommand);
Assert.False (view.FocusedCommand);
}
[Fact]
[AutoInitShutdown]
public void HotKey_KeyBinding ()
{
var view = new ScopedKeyBindingView ();
var invoked = false;
view.InvokingKeyBindings += (s, e) => invoked = true;
Application.Top.Add (view);
Application.Begin (Application.Top);
invoked = false;
Application.OnKeyDown (new (KeyCode.H));
Assert.True (invoked);
Assert.True (view.HotKeyCommand);
view.HotKey = KeyCode.Z;
invoked = false;
view.HotKeyCommand = false;
Application.OnKeyDown (new (KeyCode.H)); // old hot key
Assert.False (invoked);
Assert.False (view.HotKeyCommand);
Application.OnKeyDown (new (KeyCode.Z)); // new hot key
Assert.True (invoked);
Assert.True (view.HotKeyCommand);
}
[Fact]
[AutoInitShutdown]
public void HotKey_KeyBinding_Negative ()
{
var view = new ScopedKeyBindingView ();
var invoked = false;
view.InvokingKeyBindings += (s, e) => invoked = true;
Application.Top.Add (view);
Application.Begin (Application.Top);
Application.OnKeyDown (new (KeyCode.Z));
Assert.False (invoked);
Assert.False (view.HotKeyCommand);
invoked = false;
Application.OnKeyDown (new (KeyCode.F));
Assert.False (view.HotKeyCommand);
}
}