MouseTests.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ViewTests;
  3. public class MouseTests (ITestOutputHelper output)
  4. {
  5. [Theory]
  6. [InlineData (false, false, false)]
  7. [InlineData (true, false, true)]
  8. [InlineData (true, true, true)]
  9. public void MouseClick_SetsFocus_If_CanFocus (bool canFocus, bool setFocus, bool expectedHasFocus)
  10. {
  11. var superView = new View { CanFocus = true, Height = 1, Width = 15 };
  12. var focusedView = new View { CanFocus = true, Width = 1, Height = 1 };
  13. var testView = new View { CanFocus = canFocus, X = 4, Width = 4, Height = 1 };
  14. superView.Add (focusedView, testView);
  15. superView.BeginInit ();
  16. superView.EndInit ();
  17. focusedView.SetFocus ();
  18. Assert.True (superView.HasFocus);
  19. Assert.True (focusedView.HasFocus);
  20. Assert.False (testView.HasFocus);
  21. if (setFocus)
  22. {
  23. testView.SetFocus ();
  24. }
  25. testView.OnMouseEvent (new() { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked });
  26. Assert.True (superView.HasFocus);
  27. Assert.Equal (expectedHasFocus, testView.HasFocus);
  28. }
  29. // TODO: Add more tests that ensure the above test works with positive adornments
  30. }