Moved Window Test. Application.Begin behvior

This commit is contained in:
Tig
2024-08-20 13:47:23 -06:00
parent 66f4bef512
commit 3360c5ba89
3 changed files with 28 additions and 24 deletions

View File

@@ -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 ();

View File

@@ -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]

View File

@@ -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 ();
}
}