|
@@ -1,8 +1,4 @@
|
|
|
-using System.Diagnostics;
|
|
|
-using Moq;
|
|
|
-using Xunit.Abstractions;
|
|
|
-using Terminal.Gui;
|
|
|
-using Terminal.Gui.ViewTests;
|
|
|
+using Xunit.Abstractions;
|
|
|
|
|
|
namespace Terminal.Gui.ApplicationTests.NavigationTests;
|
|
|
|
|
@@ -10,173 +6,102 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
|
|
{
|
|
|
private readonly ITestOutputHelper _output = output;
|
|
|
|
|
|
- [Fact]
|
|
|
- public void Focused_Change_Raises_FocusedChanged ()
|
|
|
+ [Theory]
|
|
|
+ [InlineData (TabBehavior.NoStop)]
|
|
|
+ [InlineData (TabBehavior.TabStop)]
|
|
|
+ [InlineData (TabBehavior.TabGroup)]
|
|
|
+ public void Begin_SetsFocus_On_Deepest_Focusable_View (TabBehavior behavior)
|
|
|
{
|
|
|
- bool raised = false;
|
|
|
-
|
|
|
- Application.Navigation = new ApplicationNavigation ();
|
|
|
-
|
|
|
- Application.Navigation.FocusedChanged += ApplicationNavigationOnFocusedChanged;
|
|
|
-
|
|
|
- Application.Navigation.SetFocused (new View ());
|
|
|
-
|
|
|
- Assert.True (raised);
|
|
|
-
|
|
|
- Application.Navigation.GetFocused ().Dispose ();
|
|
|
- Application.Navigation.SetFocused (null);
|
|
|
+ Application.Init (new FakeDriver ());
|
|
|
|
|
|
- Application.Navigation.FocusedChanged -= ApplicationNavigationOnFocusedChanged;
|
|
|
+ var top = new Toplevel
|
|
|
+ {
|
|
|
+ TabStop = behavior
|
|
|
+ };
|
|
|
+ Assert.False (top.HasFocus);
|
|
|
|
|
|
- Application.Navigation = null;
|
|
|
+ View subView = new ()
|
|
|
+ {
|
|
|
+ CanFocus = true,
|
|
|
+ TabStop = behavior
|
|
|
+ };
|
|
|
+ top.Add (subView);
|
|
|
|
|
|
- return;
|
|
|
+ View subSubView = new ()
|
|
|
+ {
|
|
|
+ CanFocus = true,
|
|
|
+ TabStop = TabBehavior.NoStop
|
|
|
+ };
|
|
|
+ subView.Add (subSubView);
|
|
|
|
|
|
- void ApplicationNavigationOnFocusedChanged (object sender, EventArgs e) { raised = true; }
|
|
|
- }
|
|
|
+ RunState rs = Application.Begin (top);
|
|
|
+ Assert.True (top.HasFocus);
|
|
|
+ Assert.True (subView.HasFocus);
|
|
|
+ Assert.True (subSubView.HasFocus);
|
|
|
|
|
|
- [Fact]
|
|
|
- public void GetDeepestFocusedSubview_ShouldReturnNull_WhenViewIsNull ()
|
|
|
- {
|
|
|
- // Act
|
|
|
- var result = ApplicationNavigation.GetDeepestFocusedSubview (null);
|
|
|
+ top.Dispose ();
|
|
|
|
|
|
- // Assert
|
|
|
- Assert.Null (result);
|
|
|
+ Application.Shutdown ();
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void GetDeepestFocusedSubview_ShouldReturnSameView_WhenNoSubviewsHaveFocus ()
|
|
|
+ public void Begin_SetsFocus_On_Top ()
|
|
|
{
|
|
|
- // Arrange
|
|
|
- var view = new View () { Id = "view", CanFocus = true };
|
|
|
- ;
|
|
|
+ Application.Init (new FakeDriver ());
|
|
|
|
|
|
- // Act
|
|
|
- var result = ApplicationNavigation.GetDeepestFocusedSubview (view);
|
|
|
+ var top = new Toplevel ();
|
|
|
+ Assert.False (top.HasFocus);
|
|
|
|
|
|
- // Assert
|
|
|
- Assert.Equal (view, result);
|
|
|
- }
|
|
|
+ RunState rs = Application.Begin (top);
|
|
|
+ Assert.True (top.HasFocus);
|
|
|
|
|
|
- [Fact]
|
|
|
- public void GetDeepestFocusedSubview_ShouldReturnFocusedSubview ()
|
|
|
- {
|
|
|
- // Arrange
|
|
|
- var parentView = new View () { Id = "parentView", CanFocus = true };
|
|
|
- ;
|
|
|
- var childView1 = new View () { Id = "childView1", CanFocus = true };
|
|
|
- ;
|
|
|
- var childView2 = new View () { Id = "childView2", CanFocus = true };
|
|
|
- ;
|
|
|
- var grandChildView = new View () { Id = "grandChildView", CanFocus = true };
|
|
|
- ;
|
|
|
-
|
|
|
- parentView.Add (childView1, childView2);
|
|
|
- childView2.Add (grandChildView);
|
|
|
-
|
|
|
- grandChildView.SetFocus ();
|
|
|
-
|
|
|
- // Act
|
|
|
- var result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
|
|
-
|
|
|
- // Assert
|
|
|
- Assert.Equal (grandChildView, result);
|
|
|
+ top.Dispose ();
|
|
|
+ Application.Shutdown ();
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void GetDeepestFocusedSubview_ShouldReturnDeepestFocusedSubview ()
|
|
|
+ public void Focused_Change_Raises_FocusedChanged ()
|
|
|
{
|
|
|
- // Arrange
|
|
|
- var parentView = new View () { Id = "parentView", CanFocus = true };
|
|
|
- ;
|
|
|
- var childView1 = new View () { Id = "childView1", CanFocus = true };
|
|
|
- ;
|
|
|
- var childView2 = new View () { Id = "childView2", CanFocus = true };
|
|
|
- ;
|
|
|
- var grandChildView = new View () { Id = "grandChildView", CanFocus = true };
|
|
|
- ;
|
|
|
- var greatGrandChildView = new View () { Id = "greatGrandChildView", CanFocus = true };
|
|
|
- ;
|
|
|
-
|
|
|
- parentView.Add (childView1, childView2);
|
|
|
- childView2.Add (grandChildView);
|
|
|
- grandChildView.Add (greatGrandChildView);
|
|
|
-
|
|
|
- grandChildView.SetFocus ();
|
|
|
-
|
|
|
- // Act
|
|
|
- var result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
|
|
-
|
|
|
- // Assert
|
|
|
- Assert.Equal (greatGrandChildView, result);
|
|
|
-
|
|
|
- // Arrange
|
|
|
- greatGrandChildView.CanFocus = false;
|
|
|
- grandChildView.SetFocus ();
|
|
|
-
|
|
|
- // Act
|
|
|
- result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
|
|
-
|
|
|
- // Assert
|
|
|
- Assert.Equal (grandChildView, result);
|
|
|
- }
|
|
|
+ var raised = false;
|
|
|
|
|
|
- [Fact]
|
|
|
- public void GetFocused_Returns_Null_If_No_Focused_View ()
|
|
|
- {
|
|
|
Application.Navigation = new ();
|
|
|
|
|
|
- Application.Current = new Toplevel()
|
|
|
- {
|
|
|
- Id = "top",
|
|
|
- CanFocus = true
|
|
|
- };
|
|
|
+ Application.Navigation.FocusedChanged += ApplicationNavigationOnFocusedChanged;
|
|
|
|
|
|
- View subView1 = new View ()
|
|
|
- {
|
|
|
- Id = "subView1",
|
|
|
- CanFocus = true
|
|
|
- };
|
|
|
+ Application.Navigation.SetFocused (new ());
|
|
|
|
|
|
- Application.Current.Add (subView1);
|
|
|
- Assert.False (Application.Current.HasFocus);
|
|
|
+ Assert.True (raised);
|
|
|
|
|
|
- Application.Current.SetFocus ();
|
|
|
- Assert.True (subView1.HasFocus);
|
|
|
- Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
|
|
+ Application.Navigation.GetFocused ().Dispose ();
|
|
|
+ Application.Navigation.SetFocused (null);
|
|
|
|
|
|
- subView1.HasFocus = false;
|
|
|
- Assert.False (subView1.HasFocus);
|
|
|
- Assert.True (Application.Current.HasFocus);
|
|
|
- Assert.Equal (Application.Current, Application.Navigation.GetFocused ());
|
|
|
+ Application.Navigation.FocusedChanged -= ApplicationNavigationOnFocusedChanged;
|
|
|
|
|
|
- Application.Current.HasFocus = false;
|
|
|
- Assert.False (Application.Current.HasFocus);
|
|
|
- Assert.Null (Application.Navigation.GetFocused ());
|
|
|
+ Application.Navigation = null;
|
|
|
|
|
|
- Application.ResetState ();
|
|
|
- }
|
|
|
+ return;
|
|
|
|
|
|
+ void ApplicationNavigationOnFocusedChanged (object sender, EventArgs e) { raised = true; }
|
|
|
+ }
|
|
|
|
|
|
[Fact]
|
|
|
public void GetFocused_Returns_Focused_View ()
|
|
|
{
|
|
|
Application.Navigation = new ();
|
|
|
|
|
|
- Application.Current = new Toplevel ()
|
|
|
+ Application.Current = new()
|
|
|
{
|
|
|
Id = "top",
|
|
|
CanFocus = true
|
|
|
};
|
|
|
|
|
|
- View subView1 = new View ()
|
|
|
+ var subView1 = new View
|
|
|
{
|
|
|
Id = "subView1",
|
|
|
CanFocus = true
|
|
|
};
|
|
|
|
|
|
- View subView2 = new View ()
|
|
|
+ var subView2 = new View
|
|
|
{
|
|
|
Id = "subView2",
|
|
|
CanFocus = true
|
|
@@ -186,7 +111,7 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
|
|
|
|
|
Application.Current.SetFocus ();
|
|
|
Assert.True (subView1.HasFocus);
|
|
|
- Assert.Equal(subView1, Application.Navigation.GetFocused());
|
|
|
+ Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
|
|
|
|
|
Application.Current.AdvanceFocus (NavigationDirection.Forward, null);
|
|
|
Assert.Equal (subView2, Application.Navigation.GetFocused ());
|
|
@@ -195,55 +120,38 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Begin_SetsFocus_On_Top ()
|
|
|
- {
|
|
|
- Application.Init(new FakeDriver());
|
|
|
-
|
|
|
- var top = new Toplevel ();
|
|
|
- Assert.False (top.HasFocus);
|
|
|
-
|
|
|
- RunState rs = Application.Begin (top);
|
|
|
- Assert.True (top.HasFocus);
|
|
|
-
|
|
|
- top.Dispose ();
|
|
|
- Application.Shutdown();
|
|
|
- }
|
|
|
-
|
|
|
- [Theory]
|
|
|
- [InlineData(TabBehavior.NoStop)]
|
|
|
- [InlineData (TabBehavior.TabStop)]
|
|
|
- [InlineData (TabBehavior.TabGroup)]
|
|
|
- public void Begin_SetsFocus_On_Deepest_Focusable_View (TabBehavior behavior)
|
|
|
+ public void GetFocused_Returns_Null_If_No_Focused_View ()
|
|
|
{
|
|
|
- Application.Init (new FakeDriver ());
|
|
|
+ Application.Navigation = new ();
|
|
|
|
|
|
- var top = new Toplevel ()
|
|
|
+ Application.Current = new()
|
|
|
{
|
|
|
- TabStop = behavior
|
|
|
+ Id = "top",
|
|
|
+ CanFocus = true
|
|
|
};
|
|
|
- Assert.False (top.HasFocus);
|
|
|
|
|
|
- View subView = new ()
|
|
|
+ var subView1 = new View
|
|
|
{
|
|
|
- CanFocus = true,
|
|
|
- TabStop = behavior
|
|
|
+ Id = "subView1",
|
|
|
+ CanFocus = true
|
|
|
};
|
|
|
- top.Add (subView);
|
|
|
|
|
|
- View subSubView = new ()
|
|
|
- {
|
|
|
- CanFocus = true,
|
|
|
- TabStop = TabBehavior.NoStop
|
|
|
- };
|
|
|
- subView.Add (subSubView);
|
|
|
+ Application.Current.Add (subView1);
|
|
|
+ Assert.False (Application.Current.HasFocus);
|
|
|
|
|
|
- RunState rs = Application.Begin (top);
|
|
|
- Assert.True (top.HasFocus);
|
|
|
- Assert.True (subView.HasFocus);
|
|
|
- Assert.True (subSubView.HasFocus);
|
|
|
+ Application.Current.SetFocus ();
|
|
|
+ Assert.True (subView1.HasFocus);
|
|
|
+ Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
|
|
|
|
|
- top.Dispose ();
|
|
|
+ subView1.HasFocus = false;
|
|
|
+ Assert.False (subView1.HasFocus);
|
|
|
+ Assert.True (Application.Current.HasFocus);
|
|
|
+ Assert.Equal (Application.Current, Application.Navigation.GetFocused ());
|
|
|
|
|
|
- Application.Shutdown ();
|
|
|
+ Application.Current.HasFocus = false;
|
|
|
+ Assert.False (Application.Current.HasFocus);
|
|
|
+ Assert.Null (Application.Navigation.GetFocused ());
|
|
|
+
|
|
|
+ Application.ResetState ();
|
|
|
}
|
|
|
}
|