GetViewsUnderMouseTests.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #nullable enable
  2. namespace Terminal.Gui.ViewMouseTests;
  3. [Trait ("Category", "Input")]
  4. public class GetViewsUnderMouseTests
  5. {
  6. [Theory]
  7. [InlineData (0, 0)]
  8. [InlineData (2, 1)]
  9. [InlineData (20, 20)]
  10. public void GetViewsUnderMouse_Returns_Null_If_No_SubViews_Coords_Outside (int testX, int testY)
  11. {
  12. // Arrange
  13. var view = new View
  14. {
  15. Frame = new (0, 0, 10, 10)
  16. };
  17. var location = new Point (testX, testY);
  18. // Act
  19. List<View?> viewsUnderMouse = View.GetViewsUnderMouse (location);
  20. // Assert
  21. Assert.Empty (viewsUnderMouse);
  22. }
  23. [Theory]
  24. [InlineData (0, 0)]
  25. [InlineData (2, 1)]
  26. [InlineData (20, 20)]
  27. public void GetViewsUnderMouse_Returns_Null_If_Start_Not_Visible (int testX, int testY)
  28. {
  29. // Arrange
  30. var view = new View
  31. {
  32. Frame = new (0, 0, 10, 10),
  33. Visible = false
  34. };
  35. var location = new Point (testX, testY);
  36. // Act
  37. List<View?> viewsUnderMouse = View.GetViewsUnderMouse (location);
  38. // Assert
  39. Assert.Empty (viewsUnderMouse);
  40. }
  41. [Theory]
  42. [InlineData (0, 0, 0, 0, 0, -1, -1, null)]
  43. [InlineData (0, 0, 0, 0, 0, 0, 0, typeof (View))]
  44. [InlineData (0, 0, 0, 0, 0, 1, 1, typeof (View))]
  45. [InlineData (0, 0, 0, 0, 0, 4, 4, typeof (View))]
  46. [InlineData (0, 0, 0, 0, 0, 9, 9, typeof (View))]
  47. [InlineData (0, 0, 0, 0, 0, 10, 10, null)]
  48. [InlineData (1, 1, 0, 0, 0, -1, -1, null)]
  49. [InlineData (1, 1, 0, 0, 0, 0, 0, null)]
  50. [InlineData (1, 1, 0, 0, 0, 1, 1, typeof (View))]
  51. [InlineData (1, 1, 0, 0, 0, 4, 4, typeof (View))]
  52. [InlineData (1, 1, 0, 0, 0, 9, 9, typeof (View))]
  53. [InlineData (1, 1, 0, 0, 0, 10, 10, typeof (View))]
  54. [InlineData (0, 0, 1, 0, 0, -1, -1, null)]
  55. [InlineData (0, 0, 1, 0, 0, 0, 0, typeof (Margin))]
  56. [InlineData (0, 0, 1, 0, 0, 1, 1, typeof (View))]
  57. [InlineData (0, 0, 1, 0, 0, 4, 4, typeof (View))]
  58. [InlineData (0, 0, 1, 0, 0, 9, 9, typeof (Margin))]
  59. [InlineData (0, 0, 1, 0, 0, 10, 10, null)]
  60. [InlineData (0, 0, 1, 1, 0, -1, -1, null)]
  61. [InlineData (0, 0, 1, 1, 0, 0, 0, typeof (Margin))]
  62. [InlineData (0, 0, 1, 1, 0, 1, 1, typeof (Border))]
  63. [InlineData (0, 0, 1, 1, 0, 4, 4, typeof (View))]
  64. [InlineData (0, 0, 1, 1, 0, 9, 9, typeof (Margin))]
  65. [InlineData (0, 0, 1, 1, 0, 10, 10, null)]
  66. [InlineData (0, 0, 1, 1, 1, -1, -1, null)]
  67. [InlineData (0, 0, 1, 1, 1, 0, 0, typeof (Margin))]
  68. [InlineData (0, 0, 1, 1, 1, 1, 1, typeof (Border))]
  69. [InlineData (0, 0, 1, 1, 1, 2, 2, typeof (Padding))]
  70. [InlineData (0, 0, 1, 1, 1, 4, 4, typeof (View))]
  71. [InlineData (0, 0, 1, 1, 1, 9, 9, typeof (Margin))]
  72. [InlineData (0, 0, 1, 1, 1, 10, 10, null)]
  73. [InlineData (1, 1, 1, 0, 0, -1, -1, null)]
  74. [InlineData (1, 1, 1, 0, 0, 0, 0, null)]
  75. [InlineData (1, 1, 1, 0, 0, 1, 1, typeof (Margin))]
  76. [InlineData (1, 1, 1, 0, 0, 4, 4, typeof (View))]
  77. [InlineData (1, 1, 1, 0, 0, 9, 9, typeof (View))]
  78. [InlineData (1, 1, 1, 0, 0, 10, 10, typeof (Margin))]
  79. [InlineData (1, 1, 1, 1, 0, -1, -1, null)]
  80. [InlineData (1, 1, 1, 1, 0, 0, 0, null)]
  81. [InlineData (1, 1, 1, 1, 0, 1, 1, typeof (Margin))]
  82. [InlineData (1, 1, 1, 1, 0, 4, 4, typeof (View))]
  83. [InlineData (1, 1, 1, 1, 0, 9, 9, typeof (Border))]
  84. [InlineData (1, 1, 1, 1, 0, 10, 10, typeof (Margin))]
  85. [InlineData (1, 1, 1, 1, 1, -1, -1, null)]
  86. [InlineData (1, 1, 1, 1, 1, 0, 0, null)]
  87. [InlineData (1, 1, 1, 1, 1, 1, 1, typeof (Margin))]
  88. [InlineData (1, 1, 1, 1, 1, 2, 2, typeof (Border))]
  89. [InlineData (1, 1, 1, 1, 1, 3, 3, typeof (Padding))]
  90. [InlineData (1, 1, 1, 1, 1, 4, 4, typeof (View))]
  91. [InlineData (1, 1, 1, 1, 1, 8, 8, typeof (Padding))]
  92. [InlineData (1, 1, 1, 1, 1, 9, 9, typeof (Border))]
  93. [InlineData (1, 1, 1, 1, 1, 10, 10, typeof (Margin))]
  94. public void Contains (
  95. int frameX,
  96. int frameY,
  97. int marginThickness,
  98. int borderThickness,
  99. int paddingThickness,
  100. int testX,
  101. int testY,
  102. Type? expectedAdornmentType
  103. )
  104. {
  105. var view = new View
  106. {
  107. X = frameX, Y = frameY,
  108. Width = 10, Height = 10
  109. };
  110. view.Margin!.Thickness = new (marginThickness);
  111. view.Border!.Thickness = new (borderThickness);
  112. view.Padding!.Thickness = new (paddingThickness);
  113. Type? containedType = null;
  114. if (view.Contains (new (testX, testY)))
  115. {
  116. containedType = view.GetType ();
  117. }
  118. if (view.Margin.Contains (new (testX, testY)))
  119. {
  120. containedType = view.Margin.GetType ();
  121. }
  122. if (view.Border.Contains (new (testX, testY)))
  123. {
  124. containedType = view.Border.GetType ();
  125. }
  126. if (view.Padding.Contains (new (testX, testY)))
  127. {
  128. containedType = view.Padding.GetType ();
  129. }
  130. Assert.Equal (expectedAdornmentType, containedType);
  131. }
  132. }