123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using Moq;
- using Xunit.Abstractions;
- using Terminal.Gui;
- namespace Terminal.Gui.ApplicationTests.NavigationTests;
- public class ApplicationNavigationTests (ITestOutputHelper output)
- {
- private readonly ITestOutputHelper _output = output;
- [Fact]
- public void Focused_Change_Raises_FocusedChanged ()
- {
- 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.Navigation.FocusedChanged -= ApplicationNavigationOnFocusedChanged;
- Application.Navigation = null;
- return;
- void ApplicationNavigationOnFocusedChanged (object sender, EventArgs e)
- {
- raised = true;
- }
- }
- [Fact]
- public void GetDeepestFocusedSubview_ShouldReturnNull_WhenViewIsNull ()
- {
- // Act
- var result = ApplicationNavigation.GetDeepestFocusedSubview (null);
- // Assert
- Assert.Null (result);
- }
- [Fact]
- public void GetDeepestFocusedSubview_ShouldReturnSameView_WhenNoSubviewsHaveFocus ()
- {
- // Arrange
- var view = new View () { Id = "view", CanFocus = true }; ;
- // Act
- var result = ApplicationNavigation.GetDeepestFocusedSubview (view);
- // Assert
- Assert.Equal (view, result);
- }
- [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);
- }
- [Fact]
- public void GetDeepestFocusedSubview_ShouldReturnDeepestFocusedSubview ()
- {
- // 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);
- }
- //[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);
- // top.Dispose ();
- //}
- //[Fact]
- //public void MovePreviousViewOrTop_ShouldMoveFocusToPreviousViewOrTop ()
- //{
- // // Arrange
- // var top = new Toplevel ();
- // var view1 = new View () { Id = "view1", CanFocus = true, TabStop = TabBehavior.TabGroup };
- // var view2 = new View () { Id = "view2", CanFocus = true, TabStop = TabBehavior.TabGroup };
- // top.Add (view1, view2);
- // Application.Top = top;
- // Application.Current = top;
- // view2.SetFocus ();
- // // Act
- // ApplicationNavigation.MovePreviousViewOrTop ();
- // // Assert
- // Assert.True (view1.HasFocus);
- // top.Dispose ();
- //}
- }
|