Pārlūkot izejas kodu

Moved Window Test. Application.Begin behvior

Tig 11 mēneši atpakaļ
vecāks
revīzija
3360c5ba89

+ 6 - 4
Terminal.Gui/Application/Application.Run.cs

@@ -186,11 +186,13 @@ public static partial class Application // Run (Begin, Run, End, Stop)
 
         toplevel.LayoutSubviews ();
         toplevel.PositionToplevels ();
-        // Try to set initial focus to any TabGroup
-        if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup))
+
+        // TODO: Should this use FindDeepestFocusableView instead?
+        // Try to set initial focus to any TabStop
+        if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop))
         {
-            // That didn't work. Try TabStop.
-            toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
+            // That didn't work. Try TabGroup.
+            toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
         }
         ApplicationOverlapped.BringOverlappedTopToFront ();
 

+ 22 - 0
UnitTests/View/Navigation/NavigationTests.cs

@@ -604,6 +604,28 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
         Application.Shutdown ();
     }
 
+
+    [Fact]
+    [AutoInitShutdown]
+    public void Application_Begin_FocusesDeepest ()
+    {
+        var win1 = new Window { Id = "win1", Width = 10, Height = 1 };
+        var view1 = new View { Id = "view1", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
+        var win2 = new Window { Id = "win2", Y = 6, Width = 10, Height = 1 };
+        var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
+        win2.Add (view2);
+        win1.Add (view1, win2);
+
+        Application.Begin (win1);
+
+        Assert.True (win1.HasFocus);
+        Assert.True (view1.HasFocus);
+        Assert.False (win2.HasFocus);
+        Assert.False (view2.HasFocus);
+        win1.Dispose ();
+    }
+
+
 #if V2_NEW_FOCUS_IMPL // bogus test - Depends on auto setting of CanFocus
     [Fact]
     [AutoInitShutdown]

+ 0 - 20
UnitTests/Views/WindowTests.cs

@@ -201,24 +201,4 @@ public class WindowTests
         Assert.Null (windowWithFrame1234.MostFocused);
         Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrame1234.TextDirection);
     }
-
-    [Fact]
-    [AutoInitShutdown]
-    public void OnCanFocusChanged_Only_Must_ContentView_Forces_SetFocus_After_IsInitialized_Is_True ()
-    {
-        var win1 = new Window { Id = "win1", Width = 10, Height = 1 };
-        var view1 = new View { Id = "view1", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
-        var win2 = new Window { Id = "win2", Y = 6, Width = 10, Height = 1 };
-        var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
-        win2.Add (view2);
-        win1.Add (view1, win2);
-
-        Application.Begin (win1);
-
-        Assert.True (win1.HasFocus);
-        Assert.True (view1.HasFocus);
-        Assert.False (win2.HasFocus);
-        Assert.False (view2.HasFocus);
-        win1.Dispose ();
-    }
 }