diff --git a/TerminalGuiFluentTesting/GuiTestContext.cs b/TerminalGuiFluentTesting/GuiTestContext.cs index bd3f8d974..f7d713034 100644 --- a/TerminalGuiFluentTesting/GuiTestContext.cs +++ b/TerminalGuiFluentTesting/GuiTestContext.cs @@ -315,9 +315,7 @@ public class GuiTestContext : IDisposable throw new ArgumentOutOfRangeException (); } - WaitIteration (); - - return this; + return WaitIteration (); ; } public GuiTestContext Down () @@ -326,7 +324,6 @@ public class GuiTestContext : IDisposable { case V2TestDriver.V2Win: SendWindowsKey (ConsoleKeyMapping.VK.DOWN); - WaitIteration (); break; case V2TestDriver.V2Net: foreach (var k in NetSequences.Down) @@ -339,7 +336,7 @@ public class GuiTestContext : IDisposable } - return this; + return WaitIteration (); ; } /// @@ -353,7 +350,6 @@ public class GuiTestContext : IDisposable { case V2TestDriver.V2Win: SendWindowsKey (ConsoleKeyMapping.VK.RIGHT); - WaitIteration (); break; case V2TestDriver.V2Net: foreach (var k in NetSequences.Right) @@ -365,7 +361,7 @@ public class GuiTestContext : IDisposable throw new ArgumentOutOfRangeException (); } - return this; + return WaitIteration (); } /// @@ -379,7 +375,6 @@ public class GuiTestContext : IDisposable { case V2TestDriver.V2Win: SendWindowsKey (ConsoleKeyMapping.VK.LEFT); - WaitIteration (); break; case V2TestDriver.V2Net: foreach (var k in NetSequences.Left) @@ -391,7 +386,7 @@ public class GuiTestContext : IDisposable throw new ArgumentOutOfRangeException (); } - return this; + return WaitIteration (); } /// @@ -405,7 +400,6 @@ public class GuiTestContext : IDisposable { case V2TestDriver.V2Win: SendWindowsKey (ConsoleKeyMapping.VK.UP); - WaitIteration (); break; case V2TestDriver.V2Net: foreach (var k in NetSequences.Up) @@ -417,7 +411,7 @@ public class GuiTestContext : IDisposable throw new ArgumentOutOfRangeException (); } - return this; + return WaitIteration (); } /// @@ -447,7 +441,7 @@ public class GuiTestContext : IDisposable throw new ArgumentOutOfRangeException (); } - return this; + return WaitIteration (); } /// @@ -550,4 +544,11 @@ public class GuiTestContext : IDisposable WaitIteration (); } + + public GuiTestContext SendKey (Key key) + { + Application.RaiseKeyDownEvent (key); + + return WaitIteration(); + } } diff --git a/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs b/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs index 81247bb94..9eda387c0 100644 --- a/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs +++ b/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs @@ -232,65 +232,39 @@ public class MenuBarv2Tests [Theory] [ClassData (typeof (V2TestDrivers))] - public void Navigation_BetweenItems (V2TestDriver d) + public void Navigation_Left_Right_Wraps (V2TestDriver d) { - var menuBarActivated = false; + MenuBarv2? menuBar = null; - using GuiTestContext c = With.A (80, 25, d) + using GuiTestContext c = With.A (50, 20, d) .Then ( () => { - // Create menu items - var fileMenu = new MenuBarItemv2 ( - "_File", - [ - new MenuItemv2 ("_Open", string.Empty, null), - new MenuItemv2 ("_Save", string.Empty, null) - ]); - - var editMenu = new MenuBarItemv2 ( - "_Edit", - [ - new MenuItemv2 ("_Cut", string.Empty, null), - new MenuItemv2 ("_Copy", string.Empty, null) - ]); - - // Create menu bar and add to window - var menuBar = new MenuBarv2 ([fileMenu, editMenu]); - Application.Top.Add (menuBar); - - // Set menu bar to active state using reflection - FieldInfo? activeField = typeof (MenuBarv2).GetField ( - "_active", - BindingFlags.NonPublic | BindingFlags.Instance); - activeField?.SetValue (menuBar, true); - menuBar.CanFocus = true; - menuBarActivated = true; - - // Give focus to the first menu item - fileMenu.SetFocus (); - Assert.True (fileMenu.HasFocus); - - Application.LayoutAndDraw (); + menuBar = new MenuBarv2 (); + menuBar.EnableForDesign (); + Application.Top!.Add (menuBar); }) + .WaitIteration () .ScreenShot ("MenuBar initial state", _out) - .Then ( - () => - { - if (!menuBarActivated) - { - // Skip further tests if activation failed - } - - // Move right to select the edit menu - // This simulates navigation between menu items - }) + .SendKey (MenuBarv2.DefaultKey) + .Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu)) + .Then (() => Assert.True (menuBar?.IsOpen())) + .Then (() => Assert.Equal ("_New file", Application.Navigation?.GetFocused ()!.Title)) + .ScreenShot ($"After {MenuBarv2.DefaultKey}", _out) .Right () + .Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu)) .ScreenShot ("After right arrow", _out) + .Then (() => Assert.Equal ("Cu_t", Application.Navigation?.GetFocused ()!.Title)) .Right () - .ScreenShot ("After second right arrow (should wrap)", _out) + .ScreenShot ("After second right arrow", _out) + .Then (() => Assert.Equal ("_Online Help...", Application.Navigation?.GetFocused ()!.Title)) + .ScreenShot ("After third right arrow", _out) + .Right () + .ScreenShot ("After fourth right arrow", _out) + .Then (() => Assert.Equal ("_New file", Application.Navigation?.GetFocused ()!.Title)) .Left () .ScreenShot ("After left arrow", _out) + .Then (() => Assert.Equal ("_Online Help...", Application.Navigation?.GetFocused ()!.Title)) .WriteOutLogs (_out) .Stop (); } diff --git a/Tests/UnitTestsParallelizable/Views/FlagSelectorTests.cs b/Tests/UnitTestsParallelizable/Views/FlagSelectorTests.cs index 8b99b8488..08fcc8ea7 100644 --- a/Tests/UnitTestsParallelizable/Views/FlagSelectorTests.cs +++ b/Tests/UnitTestsParallelizable/Views/FlagSelectorTests.cs @@ -28,6 +28,21 @@ public class FlagSelectorTests Assert.Equal (flags, flagSelector.Flags); } + [Fact] + public void SetFlags_WithDictionary_ShouldSetValue () + { + var flagSelector = new FlagSelector (); + var flags = new Dictionary + { + { 1, "Flag1" }, + { 2, "Flag2" } + }; + + flagSelector.SetFlags (flags); + + Assert.Equal ((uint)1, flagSelector.Value); + } + [Fact] public void SetFlags_WithEnum_ShouldSetFlags () { @@ -116,7 +131,7 @@ public class FlagSelectorTests bool eventRaised = false; flagSelector.ValueChanged += (sender, args) => eventRaised = true; - flagSelector.Value = 1; + flagSelector.Value = 2; Assert.True (eventRaised); } @@ -143,15 +158,6 @@ public class FlagSelectorTests Assert.Throws (() => flagSelector.SetFlags (styles => null)); } - [Fact] - public void Generic_ () - { - var flagSelector = new FlagSelector (); - - var flags = flagSelector.Flags; - - } - [Fact] public void GenericSetFlagNames_ShouldSetFlagNames () {