using System.Globalization;
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;
namespace IntegrationTests.FluentTests;
///
/// Tests for the PopoverMenu class
///
public class PopoverMenuTests
{
private readonly TextWriter _out;
public PopoverMenuTests (ITestOutputHelper outputHelper)
{
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
_out = new TestOutputWriter (outputHelper);
}
[Theory]
[ClassData (typeof (TestDrivers))]
public void EnableForDesign_CreatesMenuItems (TestDriver d)
{
using GuiTestContext c = With.A (80, 25, d)
.Then ((app) =>
{
PopoverMenu popoverMenu = new ();
app.TopRunnable!.Add (popoverMenu);
// Call EnableForDesign
Toplevel top = app.TopRunnable;
bool result = popoverMenu.EnableForDesign (ref top);
// Should return true
Assert.True (result);
// Should have created menu items
Assert.NotNull (popoverMenu.Root);
Assert.Equal (7, popoverMenu.Root.SubViews.Count);
// Should have Cut menu item
View? cutMenuItem = popoverMenu.GetMenuItemsOfAllSubMenus ().FirstOrDefault (v => v?.Title == "Cu_t");
Assert.NotNull (cutMenuItem);
});
}
private static readonly object o = new ();
[Theory]
[ClassData (typeof (TestDrivers))]
public void Activate_Sets_Application_Navigation_Correctly (TestDriver d)
{
lock (o)
{
IApplication? app = null;
using GuiTestContext c = With.A (50, 20, d)
.Then ((a) =>
{
app = a;
PopoverMenu popoverMenu = new ()
{
App = app
};
// Call EnableForDesign
Toplevel top = app.TopRunnable!;
popoverMenu.EnableForDesign (ref top);
var view = new View
{
CanFocus = true,
Height = Dim.Auto (),
Width = Dim.Auto (),
Id = "focusableView",
Text = "View"
};
app.TopRunnable!.Add (view);
// EnableForDesign sets to true; undo that
popoverMenu.Visible = false;
app?.Popover!.Register (popoverMenu);
view.SetFocus ();
})
.AssertFalse (app?.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType