mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Migrate 210 tests to UnitTests.Parallelizable, add CreateFakeDriver helper, prove View.Draw() works in parallel tests, and provide comprehensive performance analysis (#4297)
* Initial plan * Migrate Category A test files to UnitTests.Parallelizable (135 tests) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add 11 ButtonTests to Parallelizable, remove from UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive test migration report Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive performance analysis of UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 2 Autocomplete tests and add Text tests analysis Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add proof-of-concept: TextFormatter.Draw works in parallel tests with local driver Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add CreateFakeDriver helper to ParallelizableBase and migrate 4 TextFormatterTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove proof-of-concept test from AutocompleteTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move Scheme-accessing tests back to UnitTests to fix intermittent failures Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update parallel tests README to document ConfigurationManager/SchemeManager restrictions Co-authored-by: tig <585482+tig@users.noreply.github.com> * Document static member restriction in parallel tests README Co-authored-by: tig <585482+tig@users.noreply.github.com> * Restore accidentally deleted ButtonTests.Accept_Cancel_Event_OnAccept_Returns_True test Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate Accept_Cancel_Event_OnAccept_Returns_True test to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
@@ -144,4 +144,182 @@ public class ButtonTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
Assert.Equal (KeyCode.R, args.NewKey);
|
||||
btn.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HotKeyChange_Works ()
|
||||
{
|
||||
var clicked = false;
|
||||
var btn = new Button { Text = "_Test" };
|
||||
btn.Accepting += (s, e) => clicked = true;
|
||||
|
||||
Assert.Equal (KeyCode.T, btn.HotKey);
|
||||
Assert.False (btn.NewKeyDownEvent (Key.T)); // Button processes, but does not handle
|
||||
Assert.True (clicked);
|
||||
|
||||
clicked = false;
|
||||
Assert.False (btn.NewKeyDownEvent (Key.T.WithAlt)); // Button processes, but does not handle
|
||||
Assert.True (clicked);
|
||||
|
||||
clicked = false;
|
||||
btn.HotKey = KeyCode.E;
|
||||
Assert.False (btn.NewKeyDownEvent (Key.E.WithAlt)); // Button processes, but does not handle
|
||||
Assert.True (clicked);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (false, 0)]
|
||||
[InlineData (true, 1)]
|
||||
public void Space_Fires_Accept (bool focused, int expected)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
Button button = new ();
|
||||
|
||||
button.CanFocus = focused;
|
||||
|
||||
var acceptInvoked = 0;
|
||||
button.Accepting += (s, e) => acceptInvoked++;
|
||||
|
||||
superView.Add (button);
|
||||
button.SetFocus ();
|
||||
Assert.Equal (focused, button.HasFocus);
|
||||
|
||||
superView.NewKeyDownEvent (Key.Space);
|
||||
|
||||
Assert.Equal (expected, acceptInvoked);
|
||||
|
||||
superView.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (false, 0)]
|
||||
[InlineData (true, 1)]
|
||||
public void Enter_Fires_Accept (bool focused, int expected)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
Button button = new ();
|
||||
|
||||
button.CanFocus = focused;
|
||||
|
||||
var acceptInvoked = 0;
|
||||
button.Accepting += (s, e) => acceptInvoked++;
|
||||
|
||||
superView.Add (button);
|
||||
button.SetFocus ();
|
||||
Assert.Equal (focused, button.HasFocus);
|
||||
|
||||
superView.NewKeyDownEvent (Key.Enter);
|
||||
|
||||
Assert.Equal (expected, acceptInvoked);
|
||||
|
||||
superView.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (false, 1)]
|
||||
[InlineData (true, 1)]
|
||||
public void HotKey_Fires_Accept (bool focused, int expected)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
Button button = new ()
|
||||
{
|
||||
HotKey = Key.A
|
||||
};
|
||||
|
||||
button.CanFocus = focused;
|
||||
|
||||
var acceptInvoked = 0;
|
||||
button.Accepting += (s, e) => acceptInvoked++;
|
||||
|
||||
superView.Add (button);
|
||||
button.SetFocus ();
|
||||
Assert.Equal (focused, button.HasFocus);
|
||||
|
||||
superView.NewKeyDownEvent (Key.A);
|
||||
|
||||
Assert.Equal (expected, acceptInvoked);
|
||||
|
||||
superView.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HotKey_Command_Accepts ()
|
||||
{
|
||||
var btn = new Button { Text = "_Test" };
|
||||
var accepted = false;
|
||||
btn.Accepting += (s, e) => accepted = true;
|
||||
|
||||
Assert.Equal (KeyCode.T, btn.HotKey);
|
||||
btn.InvokeCommand (Command.HotKey);
|
||||
Assert.True (accepted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Accept_Event_Returns_True ()
|
||||
{
|
||||
var btn = new Button { Text = "Test" };
|
||||
var acceptInvoked = false;
|
||||
btn.Accepting += (s, e) => { acceptInvoked = true; e.Handled = true; };
|
||||
|
||||
Assert.True (btn.InvokeCommand (Command.Accept));
|
||||
Assert.True (acceptInvoked);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Setting_Empty_Text_Sets_HoKey_To_KeyNull ()
|
||||
{
|
||||
var btn = new Button { Text = "_Test" };
|
||||
|
||||
Assert.Equal (KeyCode.T, btn.HotKey);
|
||||
|
||||
btn.Text = "";
|
||||
|
||||
Assert.Equal (KeyCode.Null, btn.HotKey);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAssignTextToButton ()
|
||||
{
|
||||
var btn = new Button { Text = "_K Ok" };
|
||||
|
||||
Assert.Equal ("_K Ok", btn.Text);
|
||||
|
||||
btn.Text = "_N Btn";
|
||||
|
||||
Assert.Equal ("_N Btn", btn.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Accept_Cancel_Event_OnAccept_Returns_True ()
|
||||
{
|
||||
var button = new Button ();
|
||||
var acceptInvoked = false;
|
||||
|
||||
button.Accepting += ButtonAccept;
|
||||
|
||||
bool? ret = button.InvokeCommand (Command.Accept);
|
||||
Assert.True (ret);
|
||||
Assert.True (acceptInvoked);
|
||||
|
||||
button.Dispose ();
|
||||
|
||||
return;
|
||||
|
||||
void ButtonAccept (object sender, CommandEventArgs e)
|
||||
{
|
||||
acceptInvoked = true;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user