Skip to content

Commit 85cf661

Browse files
BDisptig
andauthored
Fixes #3956. MessageBox doesn't return the index of IsDefault button (#3958)
* Fixes #3956. MessageBox doesn't return the index of IsDefault button * Change to Theory test. * Fix unit test 'Error opening terminal: unknown.' * Remove RunningUnitTests = true because constructor already set it. --------- Co-authored-by: Tig <[email protected]>
1 parent 7162ed8 commit 85cf661

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Terminal.Gui/Views/MessageBox.cs

+4
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ params string [] buttons
374374
{
375375
Clicked = (int)btn.Data!;
376376
}
377+
else
378+
{
379+
Clicked = defaultButton;
380+
}
377381

378382
e.Cancel = true;
379383
Application.RequestStop ();

Tests/UnitTests/Dialogs/MessageBoxTests.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -504,5 +504,25 @@ public void UICatalog_AboutBox ()
504504
Application.Run (top);
505505
top.Dispose ();
506506
}
507-
}
508507

508+
[Theory]
509+
[SetupFakeDriver]
510+
[MemberData (nameof (AcceptingKeys))]
511+
public void Button_IsDefault_True_Return_His_Index_On_Accepting (Key key)
512+
{
513+
Application.Init ();
514+
515+
Application.Iteration += (_, _) => Assert.True (Application.RaiseKeyDownEvent (key));
516+
int res = MessageBox.Query ("hey", "IsDefault", "Yes", "No");
517+
518+
Assert.Equal (0, res);
519+
520+
Application.Shutdown ();
521+
}
522+
523+
public static IEnumerable<object []> AcceptingKeys ()
524+
{
525+
yield return [Key.Enter];
526+
yield return [Key.Space];
527+
}
528+
}

0 commit comments

Comments
 (0)