Added low-level Focus tests

This commit is contained in:
Tig
2024-07-26 08:02:18 -04:00
parent 3f19a6f04a
commit 5e28ba1ef9

View File

@@ -83,4 +83,80 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
// Assert
Assert.Equal (grandChildView, result);
}
[Fact]
public void MoveNextView_ShouldMoveFocusToNextView ()
{
// Arrange
var top = new Toplevel ();
var view1 = new View () { Id = "view1", CanFocus = true };
var view2 = new View () { Id = "view2", CanFocus = true };
top.Add (view1, view2);
Application.Top = top;
Application.Current = top;
view1.SetFocus ();
// Act
ApplicationNavigation.MoveNextView ();
// Assert
Assert.True (view2.HasFocus);
}
[Fact]
public void MoveNextViewOrTop_ShouldMoveFocusToNextViewOrTop ()
{
// Arrange
var top = new Toplevel ();
var view1 = new View () { Id = "view1", CanFocus = true };
var view2 = new View () { Id = "view2", CanFocus = true };
top.Add (view1, view2);
Application.Top = top;
Application.Current = top;
view1.SetFocus ();
// Act
ApplicationNavigation.MoveNextViewOrTop ();
// Assert
Assert.True (view2.HasFocus);
}
[Fact]
public void MovePreviousView_ShouldMoveFocusToPreviousView ()
{
// Arrange
var top = new Toplevel ();
var view1 = new View () { Id = "view1", CanFocus = true };
var view2 = new View () { Id = "view2", CanFocus = true };
top.Add (view1, view2);
Application.Top = top;
Application.Current = top;
view2.SetFocus ();
// Act
ApplicationNavigation.MovePreviousView ();
// Assert
Assert.True (view1.HasFocus);
}
[Fact]
public void MovePreviousViewOrTop_ShouldMoveFocusToPreviousViewOrTop ()
{
// Arrange
var top = new Toplevel ();
var view1 = new View () { Id = "view1", CanFocus = true };
var view2 = new View () { Id = "view2", CanFocus = true };
top.Add (view1, view2);
Application.Top = top;
Application.Current = top;
view2.SetFocus ();
// Act
ApplicationNavigation.MovePreviousViewOrTop ();
// Assert
Assert.True (view1.HasFocus);
}
}