AdornmentSubViewTests.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }