mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Playing with Fluent
This commit is contained in:
@@ -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 (); ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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 ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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 ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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 ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -447,7 +441,7 @@ public class GuiTestContext : IDisposable
|
||||
throw new ArgumentOutOfRangeException ();
|
||||
}
|
||||
|
||||
return this;
|
||||
return WaitIteration ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -550,4 +544,11 @@ public class GuiTestContext : IDisposable
|
||||
|
||||
WaitIteration ();
|
||||
}
|
||||
|
||||
public GuiTestContext SendKey (Key key)
|
||||
{
|
||||
Application.RaiseKeyDownEvent (key);
|
||||
|
||||
return WaitIteration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Window> (80, 25, d)
|
||||
using GuiTestContext c = With.A<Window> (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 ();
|
||||
}
|
||||
|
||||
@@ -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<uint, string>
|
||||
{
|
||||
{ 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<InvalidOperationException> (() => flagSelector.SetFlags<FlagSelectorStyles> (styles => null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generic_ ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
var flags = flagSelector.Flags;
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericSetFlagNames_ShouldSetFlagNames ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user