| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- using static System.Net.Mime.MediaTypeNames;
- namespace Terminal.Gui.ApplicationTests;
- public class ApplicationPopoverTests
- {
- [Fact]
- public void Popover_ApplicationInit_Inits ()
- {
- // Arrange
- Assert.Null (Application.Popover);
- Application.Init (new FakeDriver ());
- // Act
- Assert.NotNull (Application.Popover);
- Application.ResetState (true);
- }
- [Fact]
- public void Popover_ApplicationShutdown_CleansUp ()
- {
- // Arrange
- Assert.Null (Application.Popover);
- Application.Init (new FakeDriver ());
- // Act
- Assert.NotNull (Application.Popover);
- Application.Shutdown ();
- // Test
- Assert.Null (Application.Popover);
- }
- [Fact]
- public void Popover_NotCleanedUp_On_End ()
- {
- // Arrange
- Assert.Null (Application.Popover);
- Application.Init (new FakeDriver ());
- Assert.NotNull (Application.Popover);
- Application.Iteration += (s, a) => Application.RequestStop ();
- var top = new Toplevel ();
- RunState rs = Application.Begin (top);
- // Act
- Application.End (rs);
- // Test
- Assert.NotNull (Application.Popover);
- top.Dispose ();
- Application.Shutdown ();
- }
- [Fact]
- public void Popover_Active_Hidden_On_End ()
- {
- // Arrange
- Assert.Null (Application.Popover);
- Application.Init (new FakeDriver ());
- Application.Iteration += (s, a) => Application.RequestStop ();
- var top = new Toplevel ();
- RunState rs = Application.Begin (top);
- IPopoverTestClass popover = new ();
- Application.Popover?.ShowPopover (popover);
- Assert.True (popover.Visible);
- // Act
- Application.End (rs);
- top.Dispose ();
- // Test
- Assert.False (popover.Visible);
- Assert.NotNull (Application.Popover);
- popover.Dispose ();
- Application.Shutdown ();
- }
- public class IPopoverTestClass : View, IPopover
- {
- public List<Key> HandledKeys { get; } = new List<Key> ();
- public int NewCommandInvokeCount { get; private set; }
- public IPopoverTestClass ()
- {
- CanFocus = true;
- AddCommand (Command.New, NewCommandHandler);
- HotKeyBindings.Add (Key.N.WithCtrl, Command.New);
- bool? NewCommandHandler (ICommandContext ctx)
- {
- NewCommandInvokeCount++;
- return false;
- }
- }
- protected override bool OnKeyDown (Key key)
- {
- HandledKeys.Add (key);
- return false;
- }
- }
- //[Fact]
- //public void Popover_SetToNull ()
- //{
- // // Arrange
- // var popover = new View ();
- // Application.Popover = popover;
- // // Act
- // Application.Popover = null;
- // // Assert
- // Assert.Null (Application.Popover);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_VisibleChangedEvent ()
- //{
- // // Arrange
- // var popover = new View ()
- // {
- // Visible = false
- // };
- // Application.Popover = popover;
- // bool eventTriggered = false;
- // popover.VisibleChanged += (sender, e) => eventTriggered = true;
- // // Act
- // popover.Visible = true;
- // // Assert
- // Assert.True (eventTriggered);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_InitializesCorrectly ()
- //{
- // // Arrange
- // var popover = new View ();
- // // Act
- // Application.Popover = popover;
- // // Assert
- // Assert.True (popover.IsInitialized);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_SetsColorScheme ()
- //{
- // // Arrange
- // var popover = new View ();
- // var topColorScheme = new ColorScheme ();
- // Application.Top = new Toplevel { ColorScheme = topColorScheme };
- // // Act
- // Application.Popover = popover;
- // // Assert
- // Assert.Equal (topColorScheme, popover.ColorScheme);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_VisibleChangedToTrue_SetsFocus ()
- //{
- // // Arrange
- // var popover = new View ()
- // {
- // Visible = false,
- // CanFocus = true
- // };
- // Application.Popover = popover;
- // // Act
- // popover.Visible = true;
- // // Assert
- // Assert.True (popover.Visible);
- // Assert.True (popover.HasFocus);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Theory]
- //[InlineData(-1, -1)]
- //[InlineData (0, 0)]
- //[InlineData (2048, 2048)]
- //[InlineData (2049, 2049)]
- //public void Popover_VisibleChangedToTrue_Locates_In_Visible_Position (int x, int y)
- //{
- // // Arrange
- // var popover = new View ()
- // {
- // X = x,
- // Y = y,
- // Visible = false,
- // CanFocus = true,
- // Width = 1,
- // Height = 1
- // };
- // Application.Popover = popover;
- // // Act
- // popover.Visible = true;
- // Application.LayoutAndDraw();
- // // Assert
- // Assert.True (Application.Screen.Contains (popover.Frame));
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_VisibleChangedToFalse_Hides_And_Removes_Focus ()
- //{
- // // Arrange
- // var popover = new View ()
- // {
- // Visible = false,
- // CanFocus = true
- // };
- // Application.Popover = popover;
- // popover.Visible = true;
- // // Act
- // popover.Visible = false;
- // // Assert
- // Assert.False (popover.Visible);
- // Assert.False (popover.HasFocus);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_Quit_Command_Hides ()
- //{
- // // Arrange
- // var popover = new View ()
- // {
- // Visible = false,
- // CanFocus = true
- // };
- // Application.Popover = popover;
- // popover.Visible = true;
- // Assert.True (popover.Visible);
- // Assert.True (popover.HasFocus);
- // // Act
- // Application.RaiseKeyDownEvent (Application.QuitKey);
- // // Assert
- // Assert.False (popover.Visible);
- // Assert.False (popover.HasFocus);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_MouseClick_Outside_Hides_Passes_Event_On ()
- //{
- // // Arrange
- // Application.Top = new Toplevel ()
- // {
- // Id = "top",
- // Height = 10,
- // Width = 10,
- // };
- // View otherView = new ()
- // {
- // X = 1,
- // Y = 1,
- // Height = 1,
- // Width = 1,
- // Id = "otherView",
- // };
- // bool otherViewPressed = false;
- // otherView.MouseEvent += (sender, e) =>
- // {
- // otherViewPressed = e.Flags.HasFlag(MouseFlags.Button1Pressed);
- // };
- // Application.Top.Add (otherView);
- // var popover = new View ()
- // {
- // Id = "popover",
- // X = 5,
- // Y = 5,
- // Width = 1,
- // Height = 1,
- // Visible = false,
- // CanFocus = true
- // };
- // Application.Popover = popover;
- // popover.Visible = true;
- // Assert.True (popover.Visible);
- // Assert.True (popover.HasFocus);
- // // Act
- // // Click on popover
- // Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed, ScreenPosition = new (5, 5) });
- // Assert.True (popover.Visible);
- // // Click outside popover (on button)
- // Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed, ScreenPosition = new (1, 1) });
- // // Assert
- // Assert.True (otherViewPressed);
- // Assert.False (popover.Visible);
- // Application.Top.Dispose ();
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Theory]
- //[InlineData (0, 0, false)]
- //[InlineData (5, 5, true)]
- //[InlineData (10, 10, false)]
- //[InlineData (5, 10, false)]
- //[InlineData (9, 9, false)]
- //public void Popover_MouseClick_Outside_Hides (int mouseX, int mouseY, bool expectedVisible)
- //{
- // // Arrange
- // Application.Top = new Toplevel ()
- // {
- // Id = "top",
- // Height = 10,
- // Width = 10,
- // };
- // var popover = new View ()
- // {
- // Id = "popover",
- // X = 5,
- // Y = 5,
- // Width = 1,
- // Height = 1,
- // Visible = false,
- // CanFocus = true
- // };
- // Application.Popover = popover;
- // popover.Visible = true;
- // Assert.True (popover.Visible);
- // Assert.True (popover.HasFocus);
- // // Act
- // Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed, ScreenPosition = new (mouseX, mouseY) });
- // // Assert
- // Assert.Equal (expectedVisible, popover.Visible);
- // Application.Top.Dispose ();
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_SetAndGet_ReturnsCorrectValue ()
- //{
- // // Arrange
- // var view = new View ();
- // // Act
- // Application.Popover = view;
- // // Assert
- // Assert.Equal (view, Application.Popover);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_SetToNull_HidesPreviousPopover ()
- //{
- // // Arrange
- // var view = new View { Visible = true };
- // Application.Popover = view;
- // // Act
- // Application.Popover = null;
- // // Assert
- // Assert.False (view.Visible);
- // Assert.Null (Application.Popover);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_SetNewPopover_HidesPreviousPopover ()
- //{
- // // Arrange
- // var oldView = new View { Visible = true };
- // var newView = new View ();
- // Application.Popover = oldView;
- // // Act
- // Application.Popover = newView;
- // // Assert
- // Assert.False (oldView.Visible);
- // Assert.Equal (newView, Application.Popover);
- // Application.ResetState (ignoreDisposed: true);
- //}
- //[Fact]
- //public void Popover_SetNewPopover_InitializesAndSetsProperties ()
- //{
- // // Arrange
- // var view = new View ();
- // // Act
- // Application.Popover = view;
- // // Assert
- // Assert.True (view.IsInitialized);
- // Assert.True (view.Arrangement.HasFlag (ViewArrangement.Overlapped));
- // Assert.Equal (Application.Top?.ColorScheme, view.ColorScheme);
- // Application.ResetState (ignoreDisposed: true);
- //}
- }
|