Преглед на файлове

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]>
BDisp преди 4 месеца
родител
ревизия
85cf6619ed
променени са 2 файла, в които са добавени 25 реда и са изтрити 1 реда
  1. 4 0
      Terminal.Gui/Views/MessageBox.cs
  2. 21 1
      Tests/UnitTests/Dialogs/MessageBoxTests.cs

+ 4 - 0
Terminal.Gui/Views/MessageBox.cs

@@ -374,6 +374,10 @@ public static class MessageBox
                                        {
                                        {
                                            Clicked = (int)btn.Data!;
                                            Clicked = (int)btn.Data!;
                                        }
                                        }
+                                       else
+                                       {
+                                           Clicked = defaultButton;
+                                       }
 
 
                                        e.Cancel = true;
                                        e.Cancel = true;
                                        Application.RequestStop ();
                                        Application.RequestStop ();

+ 21 - 1
Tests/UnitTests/Dialogs/MessageBoxTests.cs

@@ -504,5 +504,25 @@ public class MessageBoxTests
         Application.Run (top);
         Application.Run (top);
         top.Dispose ();
         top.Dispose ();
     }
     }
-}
 
 
+    [Theory]
+    [SetupFakeDriver]
+    [MemberData (nameof (AcceptingKeys))]
+    public void Button_IsDefault_True_Return_His_Index_On_Accepting (Key key)
+    {
+        Application.Init ();
+
+        Application.Iteration += (_, _) => Assert.True (Application.RaiseKeyDownEvent (key));
+        int res = MessageBox.Query ("hey", "IsDefault", "Yes", "No");
+
+        Assert.Equal (0, res);
+
+        Application.Shutdown ();
+    }
+
+    public static IEnumerable<object []> AcceptingKeys ()
+    {
+        yield return [Key.Enter];
+        yield return [Key.Space];
+    }
+}