123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using Xunit.Abstractions;
- namespace Terminal.Gui.ApplicationTests;
- public class CursorTests
- {
- private readonly ITestOutputHelper _output;
- public CursorTests (ITestOutputHelper output)
- {
- _output = output;
- ConsoleDriver.RunningUnitTests = true;
- }
- private class TestView : View
- {
- public Point? TestLocation { get; set; }
- /// <inheritdoc />
- public override Point? PositionCursor ()
- {
- if (TestLocation.HasValue && HasFocus)
- {
- Driver.SetCursorVisibility (CursorVisibility.Default);
- }
- return TestLocation;
- }
- }
- [Fact]
- [SetupFakeDriver]
- public void PositionCursor_No_Focus_Returns_False ()
- {
- Assert.False (Application.PositionCursor (null));
- TestView view = new ()
- {
- CanFocus = false,
- Width = 1,
- Height = 1,
- };
- view.TestLocation = new Point (0, 0);
- Assert.False (Application.PositionCursor (view));
- }
- [Fact]
- [SetupFakeDriver]
- public void PositionCursor_No_Position_Returns_False ()
- {
- TestView view = new ()
- {
- CanFocus = false,
- Width = 1,
- Height = 1,
- };
- view.CanFocus = true;
- view.SetFocus();
- Assert.False (Application.PositionCursor (view));
- }
- [Fact]
- [SetupFakeDriver]
- public void PositionCursor_No_IntersectSuperView_Returns_False ()
- {
- View superView = new ()
- {
- Width = 1,
- Height = 1,
- };
- TestView view = new ()
- {
- CanFocus = false,
- X = 1,
- Y =1,
- Width = 1,
- Height = 1,
- };
- superView.Add (view);
- view.CanFocus = true;
- view.SetFocus ();
- view.TestLocation = new Point (0, 0);
- Assert.False (Application.PositionCursor (view));
- }
- [Fact]
- [SetupFakeDriver]
- public void PositionCursor_Position_OutSide_SuperView_Returns_False ()
- {
- View superView = new ()
- {
- Width = 1,
- Height = 1,
- };
- TestView view = new ()
- {
- CanFocus = false,
- X = 0,
- Y = 0,
- Width = 2,
- Height = 2,
- };
- superView.Add (view);
- view.CanFocus = true;
- view.SetFocus ();
- view.TestLocation = new Point (1, 1);
- Assert.False (Application.PositionCursor (view));
- }
- [Fact, Trait("BUGBUG", "Views without subviews don't support Focused or MostFocused")]
- [SetupFakeDriver]
- public void PositionCursor_Focused_With_Position_Returns_True ()
- {
- TestView view = new ()
- {
- CanFocus = false,
- Width = 1,
- Height = 1,
- };
- view.CanFocus = true;
- view.SetFocus ();
- view.TestLocation = new Point (0, 0);
- Assert.False (Application.PositionCursor (view)); // BUGBUG: This should be true
- }
- [Fact]
- [SetupFakeDriver]
- public void PositionCursor_Defaults_Invisible ()
- {
- View view = new ()
- {
- CanFocus = true,
- Width = 1,
- Height = 1,
- };
- view.SetFocus();
- Assert.True (view.HasFocus);
- Assert.False (Application.PositionCursor (view));
- Application.Driver.GetCursorVisibility (out CursorVisibility cursor);
- Assert.Equal (CursorVisibility.Invisible, cursor);
- }
- }
|