mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
WIP: More refining
This commit is contained in:
@@ -21,7 +21,7 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
public void GetDeepestFocusedSubview_ShouldReturnSameView_WhenNoSubviewsHaveFocus ()
|
||||
{
|
||||
// Arrange
|
||||
var view = new View () { Id = "view", CanFocus = true };;
|
||||
var view = new View () { Id = "view", CanFocus = true }; ;
|
||||
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (view);
|
||||
@@ -34,10 +34,10 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
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 };;
|
||||
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);
|
||||
@@ -55,17 +55,17 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
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 };;
|
||||
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();
|
||||
grandChildView.SetFocus ();
|
||||
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
||||
@@ -152,8 +152,8 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
{
|
||||
// Arrange
|
||||
var top = new Toplevel ();
|
||||
var view1 = new View () { Id = "view1", CanFocus = true };
|
||||
var view2 = new View () { Id = "view2", CanFocus = true };
|
||||
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;
|
||||
|
||||
@@ -516,7 +516,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.False (win.HasFocus);
|
||||
|
||||
win.Enabled = true;
|
||||
win.FocusFirst ();
|
||||
win.FocusFirst (null);
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
|
||||
@@ -1632,10 +1632,12 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
View otherView = new ()
|
||||
{
|
||||
Id = "otherView",
|
||||
X = 0, Y = 0,
|
||||
Height = 1,
|
||||
Width = 1,
|
||||
CanFocus = true,
|
||||
TabStop = view.TabStop
|
||||
};
|
||||
|
||||
view.X = Pos.Right (otherView);
|
||||
@@ -1658,27 +1660,42 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.Equal (1, nEnter);
|
||||
Assert.Equal (0, nLeave);
|
||||
|
||||
// Use keyboard to navigate to next view (otherView).
|
||||
// Use keyboard to navigate to next view (otherView).
|
||||
if (view is TextView)
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
}
|
||||
else if (view is DatePicker)
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
}
|
||||
}
|
||||
//else if (view is DatePicker)
|
||||
//{
|
||||
// for (var i = 0; i < 4; i++)
|
||||
// {
|
||||
// Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
// }
|
||||
//}
|
||||
else
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
int tries = 0;
|
||||
while (view.HasFocus)
|
||||
{
|
||||
if (++tries > 10)
|
||||
{
|
||||
Assert.Fail ($"{view} is not leaving.");
|
||||
}
|
||||
Application.OnKeyDown (view.TabStop == TabBehavior.TabStop ? Key.Tab : Key.Tab.WithCtrl);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Equal (1, nEnter);
|
||||
Assert.Equal (1, nLeave);
|
||||
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Assert.False (view.HasFocus);
|
||||
Assert.True (otherView.HasFocus);
|
||||
|
||||
// Now navigate back to our test view
|
||||
Application.OnKeyDown (view.TabStop == TabBehavior.TabStop ? Key.Tab : Key.Tab.WithCtrl);
|
||||
|
||||
Assert.False (otherView.HasFocus);
|
||||
Assert.True (view.HasFocus);
|
||||
|
||||
Assert.Equal (2, nEnter);
|
||||
Assert.Equal (1, nLeave);
|
||||
|
||||
@@ -1091,7 +1091,7 @@ At 0,0
|
||||
Assert.True (RunesCount () == 0);
|
||||
|
||||
win.Visible = true;
|
||||
win.FocusFirst ();
|
||||
win.FocusFirst (null);
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
top.Draw ();
|
||||
|
||||
@@ -815,7 +815,7 @@ Three ",
|
||||
cb.SetSource (source);
|
||||
var top = new Toplevel ();
|
||||
top.Add (cb);
|
||||
top.FocusFirst ();
|
||||
top.FocusFirst (null);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal (string.Empty, cb.Text);
|
||||
var opened = false;
|
||||
@@ -845,7 +845,7 @@ Three ",
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); // losing focus
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.False (cb.HasFocus);
|
||||
top.FocusFirst (); // Gets focus again
|
||||
top.FocusFirst (null); // Gets focus again
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.True (cb.HasFocus);
|
||||
cb.Expand ();
|
||||
@@ -954,7 +954,7 @@ Three
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
top.FocusFirst (); // Gets focus again
|
||||
top.FocusFirst (null); // Gets focus again
|
||||
Assert.True (cb.HasFocus);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
@@ -974,7 +974,7 @@ Three
|
||||
var cb = new ComboBox ();
|
||||
var top = new Toplevel ();
|
||||
top.Add (cb);
|
||||
top.FocusFirst ();
|
||||
top.FocusFirst (null);
|
||||
Assert.Null (cb.Source);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
ObservableCollection<string> source = [];
|
||||
|
||||
@@ -616,7 +616,7 @@ public class TableViewTests (ITestOutputHelper output)
|
||||
top.Add (tableView);
|
||||
Application.Begin (top);
|
||||
|
||||
top.FocusFirst ();
|
||||
top.FocusFirst (null);
|
||||
Assert.True (tableView.HasFocus);
|
||||
|
||||
Assert.Equal (0, tableView.RowOffset);
|
||||
@@ -1606,7 +1606,7 @@ public class TableViewTests (ITestOutputHelper output)
|
||||
top.Add (tv);
|
||||
Application.Begin (top);
|
||||
|
||||
top.FocusFirst ();
|
||||
top.FocusFirst (null);
|
||||
Assert.True (tv.HasFocus);
|
||||
|
||||
// already on fish
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TextFieldTests (ITestOutputHelper output)
|
||||
public void Cancel_TextChanging_ThenBackspace ()
|
||||
{
|
||||
var tf = new TextField ();
|
||||
tf.FocusFirstOrLast ();
|
||||
tf.RestoreFocus ();
|
||||
tf.NewKeyDownEvent (Key.A.WithShift);
|
||||
Assert.Equal ("A", tf.Text);
|
||||
|
||||
@@ -929,7 +929,7 @@ public class TextFieldTests (ITestOutputHelper output)
|
||||
public void Backspace_From_End ()
|
||||
{
|
||||
var tf = new TextField { Text = "ABC" };
|
||||
tf.FocusFirstOrLast ();
|
||||
tf.RestoreFocus ();
|
||||
Assert.Equal ("ABC", tf.Text);
|
||||
tf.BeginInit ();
|
||||
tf.EndInit ();
|
||||
@@ -956,7 +956,7 @@ public class TextFieldTests (ITestOutputHelper output)
|
||||
public void Backspace_From_Middle ()
|
||||
{
|
||||
var tf = new TextField { Text = "ABC" };
|
||||
tf.FocusFirstOrLast ();
|
||||
tf.RestoreFocus ();
|
||||
tf.CursorPosition = 2;
|
||||
Assert.Equal ("ABC", tf.Text);
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ public class TreeTableSourceTests : IDisposable
|
||||
|
||||
var top = new Toplevel ();
|
||||
top.Add (tableView);
|
||||
top.FocusFirstOrLast ();
|
||||
top.RestoreFocus ();
|
||||
Assert.Equal (tableView, top.MostFocused);
|
||||
|
||||
return tableView;
|
||||
|
||||
Reference in New Issue
Block a user