mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Added more nav tests
This commit is contained in:
@@ -69,6 +69,7 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
|
||||
|
||||
if (view.Enabled && view.Visible && view.CanFocus)
|
||||
{
|
||||
// Add will cause the newly added subview to gain focus if it's focusable
|
||||
if (HasFocus)
|
||||
{
|
||||
view.SetFocus ();
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Terminal.Gui.ViewTests;
|
||||
|
||||
public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllViews
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Subview_Gets_Focus ()
|
||||
[Fact]
|
||||
public void Add_First_Subview_Gets_Focus ()
|
||||
{
|
||||
View top = new View ()
|
||||
{
|
||||
@@ -16,24 +16,56 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView
|
||||
top.SetFocus ();
|
||||
Assert.True (top.HasFocus);
|
||||
|
||||
int nEnter = 0;
|
||||
View subView = new View ()
|
||||
{
|
||||
Id = "subView",
|
||||
CanFocus = true
|
||||
};
|
||||
subView.HasFocusChanging += (s, e) => nEnter++;
|
||||
|
||||
top.Add (subView);
|
||||
|
||||
Assert.True (top.HasFocus);
|
||||
Assert.Equal (subView, top.Focused);
|
||||
Assert.True (subView.HasFocus);
|
||||
Assert.Equal (1, nEnter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_Subview_Deepest_Gets_Focus ()
|
||||
public void Add_Subsequent_Subview_Gets_Focus ()
|
||||
{
|
||||
View top = new View ()
|
||||
{
|
||||
Id = "top",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
top.SetFocus ();
|
||||
Assert.True (top.HasFocus);
|
||||
|
||||
View subView = new View ()
|
||||
{
|
||||
Id = "subView",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
top.Add (subView);
|
||||
|
||||
Assert.True (subView.HasFocus);
|
||||
|
||||
View subView2 = new View ()
|
||||
{
|
||||
Id = "subView2",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
top.Add (subView2);
|
||||
|
||||
Assert.True (subView2.HasFocus);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_Nested_Subviews_Deepest_Gets_Focus ()
|
||||
{
|
||||
View top = new View ()
|
||||
{
|
||||
|
||||
@@ -200,6 +200,75 @@ public class AdvanceFocusTests (ITestOutputHelper _output)
|
||||
Assert.Equal (tabStop, view.TabStop);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void AdvanceFocus_Compound_Subview ()
|
||||
{
|
||||
var top = new View () { Id = "top", CanFocus = true };
|
||||
|
||||
var compoundSubview = new View ()
|
||||
{
|
||||
CanFocus = true,
|
||||
Id = "compoundSubview",
|
||||
};
|
||||
var v1 = new View { Id = "v1", CanFocus = true };
|
||||
var v2 = new View { Id = "v2", CanFocus = true };
|
||||
var v3 = new View { Id = "v3", CanFocus = false };
|
||||
|
||||
compoundSubview.Add (v1, v2, v3);
|
||||
|
||||
top.Add (compoundSubview);
|
||||
|
||||
// Cycle through v1 & v2
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
// Add another subview
|
||||
View otherSubview = new ()
|
||||
{
|
||||
CanFocus = true,
|
||||
Id = "otherSubview",
|
||||
};
|
||||
|
||||
top.Add (otherSubview);
|
||||
// Adding a focusable subview causes advancefocus
|
||||
Assert.True (otherSubview.HasFocus);
|
||||
Assert.False (v1.HasFocus);
|
||||
|
||||
// Cycle through v1 & v2
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
Assert.True (otherSubview.HasFocus);
|
||||
// v2 was previously focused down the compoundSubView focus chain
|
||||
top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdvanceFocus_With_CanFocus_Are_All_True ()
|
||||
{
|
||||
|
||||
@@ -733,7 +733,7 @@ public class ColorPickerTests
|
||||
Assert.True (hex.HasFocus);
|
||||
|
||||
// Tab out of the hex field - should wrap to first focusable subview
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Assert.False (hex.HasFocus);
|
||||
Assert.NotSame (hex, cp.Focused);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user