Files
Terminal.Gui/Tests/UnitTestsParallelizable/Application/ApplicationPopoverTests.cs
Tig cabe4115d1 Fixes #3691 - Adds ViewArrangement.Popover (#3852)
* Added Applicaton.Popover.
Refactored FindDeepestView

* Popover prototype

* Testing highlight

* Fixed click outside issue

* Fixed DialogTests

* Fixed click outside issue (agbain)

* Enabled mouse wheel in Bar

* Enabled mouse wheel in Bar

* Progress. Broke arrangement

* Added popover tests.
Fixed a bunch more CM issues related ot unreliable unit tests.
Updated config.json to include Glyphs.

* Can't set ForceDriver to empty in Resources/config.json.

* added BUGBUG

* Made Position/ScreenPosition clear

* Added View.IsInHierarchy tests

* Added Contextmenuv2 scenario.

* Implemented CM2 in TextView

* Removed unneeded CM stuff from testhelpers

* Shortcut API docs

* Fixed keybinding unit tests

* Fixed mouse handling

* Fighting with CM related unit test failures

* Unit tests pass. I think.

* Shortcut code cleanup

* TextView uses new CM2

* Starting on OnSelect etc...

* Starting on OnSelect etc...

* Fixed ContextMenuv2

* ContextMenu is working again.

* Ugh. ANd fixed button api docs

* Fixed DrawHorizontalShadowTransparent (vertical was already fixed).

* Made Scenarios compatible with #nullable enable

* Undid some keybinding stuff

* Fixed stuff

* Sped up unit tests

* Sped up unit tests 2

* Sped up unit tests 3

* Messing with menus

* merged latest v2_develop

* Added more Popover unit tests

* Added more Popover unit tests2

* Fixed positioning bug

* Fixed mouse bug

* Fixed Bar draw issue

* WIP

* merge v2_develop

* CM2 sorta works

* Enabled Bar subclasses to have IDesignable

* Added ViewportSettings.Transparent

* Region -> nullable enable

* Added ViewportSettigs Editor

* merged v2_develop part 2

* merged v2_develop part 3

* WIP: GetViewsUnderMouse

* WIP: More GetViewsUnderMouse work

* Bars works again

* Added unit tests

* CM now works

* MenuItemv2 POC

* SubMenu POC

* CommandNotBound

* More POC

* Optimize Margin to not defer draw if there's no shadow

* Logger cleanup

* Reverted Generic

* Cascading mostly working

* fixed layout bug

* API docs

* API docs

* Fixed cascade

* Events basically work

* code cleanup

* Fixed IsDefault bug;

* Enabled hotkey support

* Made context-menu-like

* Improved usability

* Refactored ApplicationPopover again

* Cleanup

* Menuv2 POC basically complete

* Code Cleanup

* Made menu API simpler

* Fixed Strings bugs

* Got old ContextMenu scenario mostly working

* ContextMenu scenario now works

* ContextMenu fixes

* ContextMenu fixes

* Tons of menu cleanup

* ContextMenu works in TextView

* Fixed unit tes

* Added unit tests

* Fixed tests

* code cleanup

* More code cleanup

* Deep dive

* scenario

* typos

* Demo colorpicker in a Menu

* Added Region tests proving Region is broken in some Union cases

* fixed v2win/net
2025-05-29 14:08:47 -06:00

164 lines
4.4 KiB
C#

using Moq;
namespace Terminal.Gui.ApplicationTests;
public class ApplicationPopoverTests
{
[Fact]
public void Register_AddsPopover ()
{
// Arrange
var popover = new Mock<IPopover> ().Object;
var popoverManager = new ApplicationPopover ();
// Act
popoverManager.Register (popover);
// Assert
Assert.Contains (popover, popoverManager.Popovers);
}
[Fact]
public void DeRegister_RemovesPopover ()
{
// Arrange
var popover = new Mock<IPopover> ().Object;
var popoverManager = new ApplicationPopover ();
popoverManager.Register (popover);
// Act
var result = popoverManager.DeRegister (popover);
// Assert
Assert.True (result);
Assert.DoesNotContain (popover, popoverManager.Popovers);
}
[Fact]
public void ShowPopover_SetsActivePopover ()
{
// Arrange
var popover = new Mock<IPopoverTestClass> ().Object;
var popoverManager = new ApplicationPopover ();
// Act
popoverManager.ShowPopover (popover);
// Assert
Assert.Equal (popover, popoverManager.GetActivePopover ());
}
[Fact]
public void HidePopover_ClearsActivePopover ()
{
// Arrange
var popover = new Mock<IPopover> ().Object;
var popoverManager = new ApplicationPopover ();
popoverManager.ShowPopover (popover);
// Act
popoverManager.HidePopover (popover);
// Assert
Assert.Null (popoverManager.GetActivePopover ());
}
[Fact]
public void DispatchKeyDown_ActivePopoverGetsKey ()
{
// Arrange
var popover = new IPopoverTestClass ();
var popoverManager = new ApplicationPopover ();
popoverManager.ShowPopover (popover);
// Act
popoverManager.DispatchKeyDown (Key.A);
// Assert
Assert.Contains (KeyCode.A, popover.HandledKeys);
}
[Fact]
public void DispatchKeyDown_ActivePopoverGetsHotKey ()
{
// Arrange
var popover = new IPopoverTestClass ();
var popoverManager = new ApplicationPopover ();
popoverManager.ShowPopover (popover);
// Act
popoverManager.DispatchKeyDown (Key.N.WithCtrl);
// Assert
Assert.Equal(1, popover.NewCommandInvokeCount);
Assert.Contains (Key.N.WithCtrl, popover.HandledKeys);
}
[Fact]
public void DispatchKeyDown_InactivePopoverGetsHotKey ()
{
// Arrange
var activePopover = new IPopoverTestClass () { Id = "activePopover" };
var inactivePopover = new IPopoverTestClass () { Id = "inactivePopover" }; ;
var popoverManager = new ApplicationPopover ();
popoverManager.ShowPopover (activePopover);
popoverManager.Register (inactivePopover);
// Act
popoverManager.DispatchKeyDown (Key.N.WithCtrl);
// Assert
Assert.Equal (1, activePopover.NewCommandInvokeCount);
Assert.Equal (1, inactivePopover.NewCommandInvokeCount);
Assert.Contains (Key.N.WithCtrl, activePopover.HandledKeys);
Assert.NotEmpty (inactivePopover.HandledKeys);
}
[Fact]
public void DispatchKeyDown_InactivePopoverDoesGetKey ()
{
// Arrange
var activePopover = new IPopoverTestClass ();
var inactivePopover = new IPopoverTestClass ();
var popoverManager = new ApplicationPopover ();
popoverManager.ShowPopover (activePopover);
popoverManager.Register (inactivePopover);
// Act
popoverManager.DispatchKeyDown (Key.A);
// Assert
Assert.Contains (Key.A, activePopover.HandledKeys);
Assert.NotEmpty (inactivePopover.HandledKeys);
}
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;
}
}
}