AdornmentSubViewTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ViewTests;
  3. public class AdornmentSubViewTests (ITestOutputHelper output)
  4. {
  5. private readonly ITestOutputHelper _output = output;
  6. [Theory]
  7. [InlineData (0, 0, false)] // Margin has no thickness, so false
  8. [InlineData (0, 1, false)] // Margin has no thickness, so false
  9. [InlineData (1, 0, true)]
  10. [InlineData (1, 1, true)]
  11. [InlineData (2, 1, true)]
  12. public void Adornment_WithSubView_GetViewsUnderMouse_Finds (int viewMargin, int subViewMargin, bool expectedFound)
  13. {
  14. Application.Top = new Toplevel()
  15. {
  16. Width = 10,
  17. Height = 10
  18. };
  19. Application.Top.Margin.Thickness = new Thickness (viewMargin);
  20. var subView = new View ()
  21. {
  22. X = 0,
  23. Y = 0,
  24. Width = 5,
  25. Height = 5
  26. };
  27. subView.Margin.Thickness = new Thickness (subViewMargin);
  28. Application.Top.Margin.Add (subView);
  29. Application.Top.Layout ();
  30. var foundView = View.GetViewsUnderMouse (new Point(0, 0)).LastOrDefault ();
  31. bool found = foundView == subView || foundView == subView.Margin;
  32. Assert.Equal (expectedFound, found);
  33. Application.Top.Dispose ();
  34. Application.ResetState (ignoreDisposed: true);
  35. }
  36. [Fact]
  37. public void Adornment_WithNonVisibleSubView_GetViewsUnderMouse_Finds_Adornment ()
  38. {
  39. Application.Top = new Toplevel ()
  40. {
  41. Width = 10,
  42. Height = 10
  43. };
  44. Application.Top.Padding.Thickness = new Thickness (1);
  45. var subView = new View ()
  46. {
  47. X = 0,
  48. Y = 0,
  49. Width = 1,
  50. Height = 1,
  51. Visible = false
  52. };
  53. Application.Top.Padding.Add (subView);
  54. Application.Top.Layout ();
  55. Assert.Equal (Application.Top.Padding, View.GetViewsUnderMouse (new Point(0, 0)).LastOrDefault ());
  56. Application.Top?.Dispose ();
  57. Application.ResetState (ignoreDisposed: true);
  58. }
  59. [Fact]
  60. public void Setting_Thickness_Causes_Adornment_SubView_Layout ()
  61. {
  62. var view = new View ();
  63. var subView = new View ();
  64. view.Margin.Add (subView);
  65. view.BeginInit ();
  66. view.EndInit ();
  67. var raised = false;
  68. subView.SubviewLayout += LayoutStarted;
  69. view.Margin.Thickness = new Thickness (1, 2, 3, 4);
  70. view.Layout ();
  71. Assert.True (raised);
  72. return;
  73. void LayoutStarted (object sender, LayoutEventArgs e)
  74. {
  75. raised = true;
  76. }
  77. }
  78. }