|
@@ -1,18 +1,200 @@
|
|
|
-
|
|
|
-#nullable enable
|
|
|
-using Microsoft.VisualStudio.TestPlatform.Utilities;
|
|
|
-using Xunit.Abstractions;
|
|
|
+#nullable enable
|
|
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
|
|
-/// <summary>
|
|
|
-/// Tests View.FindDeepestView
|
|
|
-/// </summary>
|
|
|
-/// <param name="output"></param>
|
|
|
-public class FindDeepestViewTests ()
|
|
|
+public class GetViewsUnderMouseTests
|
|
|
{
|
|
|
[Theory]
|
|
|
[InlineData (0, 0, 0, 0, 0, -1, -1, null)]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, 0, 0, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, 1, 1, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, 9, 9, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, 10, 10, null)]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, -1, -1, null)]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, 0, 0, null)]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, 1, 1, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, 9, 9, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 0, 0, 0, 10, 10, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, -1, -1, null)]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, 0, 0, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, 1, 1, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, 9, 9, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 0, 0, 10, 10, null)]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, -1, -1, null)]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, 0, 0, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, 1, 1, typeof (Border))]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, 9, 9, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 1, 0, 10, 10, null)]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, -1, -1, null)]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 0, 0, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 1, 1, typeof (Border))]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 2, 2, typeof (Padding))]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 9, 9, typeof (Margin))]
|
|
|
+ [InlineData (0, 0, 1, 1, 1, 10, 10, null)]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, -1, -1, null)]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, 0, 0, null)]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, 1, 1, typeof (Margin))]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, 9, 9, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 1, 0, 0, 10, 10, typeof (Margin))]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, -1, -1, null)]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, 0, 0, null)]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, 1, 1, typeof (Margin))]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, 9, 9, typeof (Border))]
|
|
|
+ [InlineData (1, 1, 1, 1, 0, 10, 10, typeof (Margin))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, -1, -1, null)]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 0, 0, null)]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 1, 1, typeof (Margin))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 2, 2, typeof (Border))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 3, 3, typeof (Padding))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 4, 4, typeof (Toplevel))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 8, 8, typeof (Padding))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 9, 9, typeof (Border))]
|
|
|
+ [InlineData (1, 1, 1, 1, 1, 10, 10, typeof (Margin))]
|
|
|
+ public void GetViewsUnderMouse_Top_Adornments_Returns_Correct_View (int frameX, int frameY, int marginThickness, int borderThickness, int paddingThickness, int testX, int testY, Type? expectedViewType)
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ Application.Top = new ()
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (frameX, frameY, 10, 10),
|
|
|
+ };
|
|
|
+ Application.Top.Margin.Thickness = new Thickness (marginThickness);
|
|
|
+ Application.Top.Border.Thickness = new Thickness (borderThickness);
|
|
|
+ Application.Top.Padding.Thickness = new Thickness (paddingThickness);
|
|
|
+
|
|
|
+ var location = new Point (testX, testY);
|
|
|
+
|
|
|
+ // Act
|
|
|
+ var viewsUnderMouse = View.GetViewsUnderMouse (location);
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ if (expectedViewType == null)
|
|
|
+ {
|
|
|
+ Assert.Empty (viewsUnderMouse);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Assert.Contains (viewsUnderMouse, v => v?.GetType () == expectedViewType);
|
|
|
+ }
|
|
|
+ Application.Top.Dispose ();
|
|
|
+ Application.ResetState (ignoreDisposed: true);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData (0, 0)]
|
|
|
+ [InlineData (1, 1)]
|
|
|
+ [InlineData (2, 2)]
|
|
|
+ public void GetViewsUnderMouse_Returns_Top_If_No_SubViews (int testX, int testY)
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ Application.Top = new ()
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (0, 0, 10, 10)
|
|
|
+ };
|
|
|
+
|
|
|
+ var location = new Point (testX, testY);
|
|
|
+
|
|
|
+ // Act
|
|
|
+ var viewsUnderMouse = View.GetViewsUnderMouse (location);
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ Assert.Contains (viewsUnderMouse, v => v == Application.Top);
|
|
|
+ Application.Top.Dispose ();
|
|
|
+ Application.ResetState (ignoreDisposed: true);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData (0, 0)]
|
|
|
+ [InlineData (2, 1)]
|
|
|
+ [InlineData (20, 20)]
|
|
|
+ public void GetViewsUnderMouse_Returns_Null_If_No_SubViews_Coords_Outside (int testX, int testY)
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ var view = new View
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (0, 0, 10, 10)
|
|
|
+ };
|
|
|
+
|
|
|
+ var location = new Point (testX, testY);
|
|
|
+
|
|
|
+ // Act
|
|
|
+ var viewsUnderMouse = View.GetViewsUnderMouse (location);
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ Assert.Empty (viewsUnderMouse);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData (0, 0)]
|
|
|
+ [InlineData (2, 1)]
|
|
|
+ [InlineData (20, 20)]
|
|
|
+ public void GetViewsUnderMouse_Returns_Null_If_Start_Not_Visible (int testX, int testY)
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ var view = new View
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (0, 0, 10, 10),
|
|
|
+ Visible = false
|
|
|
+ };
|
|
|
+
|
|
|
+ var location = new Point (testX, testY);
|
|
|
+
|
|
|
+ // Act
|
|
|
+ var viewsUnderMouse = View.GetViewsUnderMouse (location);
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ Assert.Empty (viewsUnderMouse);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData (0, 0, false)]
|
|
|
+ [InlineData (1, 1, true)]
|
|
|
+ [InlineData (9, 9, false)]
|
|
|
+ [InlineData (10, 10, false)]
|
|
|
+ [InlineData (6, 7, true)]
|
|
|
+ [InlineData (1, 2, true)]
|
|
|
+ [InlineData (5, 6, true)]
|
|
|
+ public void GetViewsUnderMouse_Returns_Correct_If_SubViews (int testX, int testY, bool expected)
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ Application.Top = new ()
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (0, 0, 10, 10)
|
|
|
+ };
|
|
|
+
|
|
|
+ var subView = new View
|
|
|
+ {
|
|
|
+ Frame = new Rectangle (1, 1, 8, 8)
|
|
|
+ };
|
|
|
+
|
|
|
+ Application.Top.Add (subView);
|
|
|
+
|
|
|
+ var location = new Point (testX, testY);
|
|
|
+
|
|
|
+ // Act
|
|
|
+ var viewsUnderMouse = View.GetViewsUnderMouse (location);
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ if (expected)
|
|
|
+ {
|
|
|
+ Assert.Contains (viewsUnderMouse, v => v == subView);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Assert.DoesNotContain (viewsUnderMouse, v => v == subView);
|
|
|
+ }
|
|
|
+ Application.Top.Dispose ();
|
|
|
+ Application.ResetState (ignoreDisposed: true);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData (0, 0, 0, 0, 0, -1, -1, null)]
|
|
|
[InlineData (0, 0, 0, 0, 0, 0, 0, typeof (View))]
|
|
|
[InlineData (0, 0, 0, 0, 0, 1, 1, typeof (View))]
|
|
|
[InlineData (0, 0, 0, 0, 0, 4, 4, typeof (View))]
|
|
@@ -104,7 +286,7 @@ public class FindDeepestViewTests ()
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView returns the correct view if the start view has no subviews
|
|
|
+ // Test that GetViewsUnderMouse returns the correct view if the start view has no subviews
|
|
|
[Theory]
|
|
|
[InlineData (0, 0)]
|
|
|
[InlineData (1, 1)]
|
|
@@ -116,12 +298,12 @@ public class FindDeepestViewTests ()
|
|
|
Width = 10, Height = 10,
|
|
|
};
|
|
|
|
|
|
- Assert.Same (Application.Top, View.FindDeepestView (new (testX, testY)));
|
|
|
+ Assert.Same (Application.Top, View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault());
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView returns null if the start view has no subviews and coords are outside the view
|
|
|
+ // Test that GetViewsUnderMouse returns null if the start view has no subviews and coords are outside the view
|
|
|
[Theory]
|
|
|
[InlineData (0, 0)]
|
|
|
[InlineData (2, 1)]
|
|
@@ -134,7 +316,7 @@ public class FindDeepestViewTests ()
|
|
|
Width = 10, Height = 10,
|
|
|
};
|
|
|
|
|
|
- Assert.Null (View.FindDeepestView (new (testX, testY)));
|
|
|
+ Assert.Null (View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault());
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
@@ -152,12 +334,12 @@ public class FindDeepestViewTests ()
|
|
|
Visible = false,
|
|
|
};
|
|
|
|
|
|
- Assert.Null (View.FindDeepestView (new (testX, testY)));
|
|
|
+ Assert.Null (View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault());
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView returns the correct view if the start view has subviews
|
|
|
+ // Test that GetViewsUnderMouse returns the correct view if the start view has subviews
|
|
|
[Theory]
|
|
|
[InlineData (0, 0, false)]
|
|
|
[InlineData (1, 1, false)]
|
|
@@ -181,7 +363,7 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -211,7 +393,7 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -244,14 +426,14 @@ public class FindDeepestViewTests ()
|
|
|
subview.Visible = true;
|
|
|
Assert.True (subview.Visible);
|
|
|
Assert.False (Application.Top.Visible);
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView works if the start view has positive Adornments
|
|
|
+ // Test that GetViewsUnderMouse works if the start view has positive Adornments
|
|
|
[Theory]
|
|
|
[InlineData (0, 0, false)]
|
|
|
[InlineData (1, 1, false)]
|
|
@@ -278,14 +460,14 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView works if the start view has offset Viewport location
|
|
|
+ // Test that GetViewsUnderMouse works if the start view has offset Viewport location
|
|
|
[Theory]
|
|
|
[InlineData (1, 0, 0, true)]
|
|
|
[InlineData (1, 1, 1, true)]
|
|
@@ -311,7 +493,7 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -338,14 +520,14 @@ public class FindDeepestViewTests ()
|
|
|
|
|
|
var subview = new View ()
|
|
|
{
|
|
|
- X = Pos.AnchorEnd(1), Y = Pos.AnchorEnd(1),
|
|
|
+ X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1),
|
|
|
Width = 1, Height = 1,
|
|
|
};
|
|
|
Application.Top.Padding.Add (subview);
|
|
|
- Application.Top.BeginInit();
|
|
|
- Application.Top.EndInit();
|
|
|
+ Application.Top.BeginInit ();
|
|
|
+ Application.Top.EndInit ();
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -381,13 +563,13 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
Assert.Equal (expectedAdornmentType, found!.GetType ());
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView works if the subview has positive Adornments
|
|
|
+ // Test that GetViewsUnderMouse works if the subview has positive Adornments
|
|
|
[Theory]
|
|
|
[InlineData (0, 0, false)]
|
|
|
[InlineData (1, 1, false)]
|
|
@@ -414,7 +596,7 @@ public class FindDeepestViewTests ()
|
|
|
subview.Margin.Thickness = new Thickness (1);
|
|
|
Application.Top.Add (subview);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == subview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -458,10 +640,10 @@ public class FindDeepestViewTests ()
|
|
|
};
|
|
|
subview.Padding.Add (paddingSubview);
|
|
|
Application.Top.Add (subview);
|
|
|
- Application.Top.BeginInit();
|
|
|
- Application.Top.EndInit();
|
|
|
+ Application.Top.BeginInit ();
|
|
|
+ Application.Top.EndInit ();
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new Point(testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == paddingSubview);
|
|
|
Application.Top.Dispose ();
|
|
@@ -512,14 +694,14 @@ public class FindDeepestViewTests ()
|
|
|
Application.Top.BeginInit ();
|
|
|
Application.Top.EndInit ();
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new (testX, testY)).LastOrDefault();
|
|
|
|
|
|
Assert.Equal (expectedSubViewFound, found == paddingSubview);
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|
|
|
}
|
|
|
|
|
|
- // Test that FindDeepestView works with nested subviews
|
|
|
+ // Test that GetViewsUnderMouse works with nested subviews
|
|
|
[Theory]
|
|
|
[InlineData (0, 0, -1)]
|
|
|
[InlineData (9, 9, -1)]
|
|
@@ -556,7 +738,7 @@ public class FindDeepestViewTests ()
|
|
|
|
|
|
Application.Top.Add (subviews [0]);
|
|
|
|
|
|
- var found = View.FindDeepestView (new (testX, testY));
|
|
|
+ var found = View.GetViewsUnderMouse(new (testX, testY)).LastOrDefault();
|
|
|
Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!));
|
|
|
Application.Top.Dispose ();
|
|
|
Application.ResetState (ignoreDisposed: true);
|