Fixes #3947 Adds Fake driver and fixes fluent tests (iteration-zero) (#4225)

* Consider width2 chars that are not IsBmp

* Apply same fix in WindowsDriver

* Explicitly use type of local variable

* Revert changes to WindowsDriver

* Assume we are running in a terminal that supports true color by default unless user explicitly forces 16

* Switch to SetAttribute and WriteConsole instead of WriteConsoleOutput for 16 color mode

* Fix some cursor issues (WIP)

* Remove concept of 'dirty rows' from v2 as its never actually used

* Remove damageRegion as it does nothing

* Make string builder to console writing simpler

* Radically simplify Write method

* Simplify conditional logic

* Simplify restoring cursor position

* Reference local variable for console buffer

* Reduce calls to ConsoleWrite by accumulating till attribute changes

* When resizing v2 16 color mode on windows, recreate the back buffer to match its size

* Fixes for VTS enabled

* Fix _lastSize never being assigned

* Fixes VTS for Force16Colors

* Fixes force16Colors in VTS

* Fixes escape sequences always echoing in non-VTS

* Force Force16Colors in non-VTS. It have a bug in adding a newline in the last line

* WIP Add base class for NetOutput

* Abstract away how we change attribute

* WIP - Make WindowsOutput use base class

* WIP working to fix set cursor position

* Remove commented out code

* Fixes legacy output mode

* Fixes size with no alt buffer supported on VTS and size restore after maximized.

* Fix set cursor which also fixes the broken surrogate pairs

* Add force parameter

* Fixes an issue that only happens with Windows Terminal when paste surrogate pairs by press Ctrl+V

* In Windows escape sequences must be sent during the lifetime of the console which is created in input handle

* Ensure flush the input buffer before reset the console

* Flush input buffer before reset console in v2win

* Fixes issue in v2net not being refreshing the menu bar at start

* Only force layout and draw on size changed.

* Fix v2net issue not draw first line by forcing set cursor position

* Set _lastCursorPosition nullable and remove bool force from set cursor position

* Remove force parameter

* Add v2 version of fake driver attribute

* Make direct replacement and wire up window resizing events

* Update casts to use V2 fake driver instead

* Adjust interfaces to expose less internals

* Fix not raising iteration event in v2

* WIP investigate what it takes to do resize and redraw using TextAlignment_Centered as example

* Sketch adding component factory

* Create relevant fake component factories

* Add window size monitor into factory

* Fake size monitor injecting

* Add helper for faking console resize in AutoInitShutdown tests

* Fix size setting in FakeDriverV2

* Switch to new method

* Fix IsLegacy becoming false when using blank constructor

* Fix for Ready not being raised when showing same top twice also fixes garbage collection issue if running millions of top levels

* Fix tests

* Remove auto init

* Restore conditional compilation stuff

* Restore 'if running unit tests' logic

* Check only for the output being specific classes for the suppression

* Fix ShadowView blowing up with index out of bounds error

* Fix resize in fluent tests

* Fix for people using Iteration call directly

* Fix more calls to iteration to use
        AutoInitShutdownAttribute.RunIteration ();

* Add comment

* Remove assumption that Run with prior view not disposed should throw

* Fix timings in Dialog_Opened_From_Another_Dialog

* Fix Zero_Buttons_Works

* Standardize and fix Button_IsDefault_True_Return_His_Index_On_Accepting

* Fix iteration counts on MessageBoxTests

* Fix WizartTests and DrawTests_Ruler

* Implement SendKeys into ConsoleDriverFacade

* Fix SendKeys in console driver facade such that FileDialogTests works
Fix when Clip is null in popover

* Add missing dispose call to test

* Fix support for Esc in facade SendKeys

* Fix AutocompleteTests

* Fix various tests

* Replace LayoutAndDraw with run iteration

* Fix draw issues

* fix draw order

* Fix run iteration calls

* Fix unit tests

* Fix SendKeys in facade.

* Manipulate upper and lower cases.

* Add IsValidInput method to the interface.

* Fix SendKeys scenario

* Fixes surrogate pairs in the label

* Make tests more sensible - they are testing draw functionality.  Callbacks do not need to happen in Iteration method

* Fix tests and harden cleanup in AutoInitShutdownAttribute v2 lifecycle dispose

* Delete extra create input call

* Fix mocks and order of exceptions thrown in Run when things are not initialized

* Revert use of `MapConsoleKeyInfoToKeyCode`

* Ignore casing as it is not what test is really about

* Clear application top and top levels before each auto init shutdown test

* Fix for unstable tests

* Restore actually working SendKeys code

* option to pass logger in fluent ctor

* restore ToArray

* Fix SendKeys method and add extension to unit test

* Leverage the EscSeqUtils.MapConsoleKeyInfo method to avoid duplicate code

* Remove unnecessary hack

* Using only KeyCode for rKeys

* Recover modifier keys in surrogate pairs

* Reformat

* Remove iteration limit for benchmarking in v2

* remove iteration delay to identify bugs

* Remove nudge to unique key and make Then run on UI thread

* fix fluid assertions

* Ensure UI operations all happen on UI thread

* Add explicit error for WaitIteration during an invoke

* Remove timeout added for debug

* Catch failing asserts better

* Fix screenshot

* Fix null ref

* Fix race condition in processing input

* Test fixing

* Standardize asserts

* Remove calls to layout and draw, remove pointless lock and enable reading Cancelled from Dialog even if it is disposed

* fix bad merge

* Make logs access threadsafe

* add extra wait to remove race between iteration end and assert

* Code cleanup

* Remove test for crash on access Cancelled after dispose as this is no longer a restriction

* Change resize console to run on UI thread - fixing race condition with redrawing

* Restore original frame rate after test

* Restore nudge to unique key

* Code Cleanup

* Fix for cascading failures when an assert fails in a specific test

* fix for bad merge

* Address PR feedback

* Move classes to seperate files and add xmldoc

* xml doc warnings

* More xml comments docs

* Fix spelling

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
This commit is contained in:
Thomas Nind
2025-09-10 17:01:57 +01:00
committed by GitHub
parent 00aaefb962
commit 51dda7e69f
85 changed files with 1783 additions and 1130 deletions

View File

@@ -1,4 +1,5 @@
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;
namespace IntegrationTests.FluentTests;
@@ -7,16 +8,13 @@ public class BasicFluentAssertionTests
{
private readonly TextWriter _out;
public BasicFluentAssertionTests (ITestOutputHelper outputHelper)
{
_out = new TestOutputWriter (outputHelper);
}
public BasicFluentAssertionTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter (outputHelper); }
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void GuiTestContext_NewInstance_Runs (V2TestDriver d)
{
using GuiTestContext context = With.A<Window> (40, 10, d);
using GuiTestContext context = With.A<Window> (40, 10, d, _out);
Assert.True (Application.Top!.Running);
context.WriteOutLogs (_out);
@@ -34,9 +32,6 @@ public class BasicFluentAssertionTests
context.RaiseKeyDownEvent (Application.QuitKey);
Assert.False (top!.Running);
Application.Top?.Dispose ();
Application.Shutdown ();
context.WriteOutLogs (_out);
context.Stop ();
}
@@ -69,9 +64,10 @@ public class BasicFluentAssertionTests
using GuiTestContext c = With.A<Window> (40, 10, d)
.Add (lbl)
.Then (() => Assert.Equal (38, lbl.Frame.Width)) // Window has 2 border
.AssertEqual (38, lbl.Frame.Width) // Window has 2 border
.ResizeConsole (20, 20)
.Then (() => Assert.Equal (18, lbl.Frame.Width))
.WaitIteration ()
.AssertEqual (18, lbl.Frame.Width)
.WriteOutLogs (_out)
.Stop ();
}
@@ -85,7 +81,7 @@ public class BasicFluentAssertionTests
MenuItemv2 [] menuItems = [new ("_New File", string.Empty, () => { clicked = true; })];
using GuiTestContext c = With.A<Window> (40, 10, d)
.WithContextMenu (new PopoverMenu (menuItems))
.WithContextMenu (new (menuItems))
.ScreenShot ("Before open menu", _out)
// Click in main area inside border
@@ -98,7 +94,6 @@ public class BasicFluentAssertionTests
Assert.NotNull (popover);
var popoverMenu = popover as PopoverMenu;
popoverMenu!.Root!.BorderStyle = LineStyle.Single;
})
.WaitIteration ()
.ScreenShot ("After open menu", _out)
@@ -114,26 +109,30 @@ public class BasicFluentAssertionTests
{
var clicked = false;
MenuItemv2 [] menuItems = [
new ("One", "", null),
new ("Two", "", null),
new ("Three", "", null),
new ("Four", "", new (
[
new ("SubMenu1", "", null),
new ("SubMenu2", "", ()=>clicked=true),
new ("SubMenu3", "", null),
new ("SubMenu4", "", null),
new ("SubMenu5", "", null),
new ("SubMenu6", "", null),
new ("SubMenu7", "", null)
])),
new ("Five", "", null),
new ("Six", "", null)
];
MenuItemv2 [] menuItems =
[
new ("One", "", null),
new ("Two", "", null),
new ("Three", "", null),
new (
"Four",
"",
new (
[
new ("SubMenu1", "", null),
new ("SubMenu2", "", () => clicked = true),
new ("SubMenu3", "", null),
new ("SubMenu4", "", null),
new ("SubMenu5", "", null),
new ("SubMenu6", "", null),
new ("SubMenu7", "", null)
])),
new ("Five", "", null),
new ("Six", "", null)
];
using GuiTestContext c = With.A<Window> (40, 10, d)
.WithContextMenu (new PopoverMenu (menuItems))
.WithContextMenu (new (menuItems))
.ScreenShot ("Before open menu", _out)
// Click in main area inside border
@@ -177,43 +176,43 @@ public class BasicFluentAssertionTests
Application.Top!.Add (w1, w2, w3);
})
.WaitIteration ()
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v1.HasFocus))
.AssertTrue (v1.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v3.HasFocus))
.AssertTrue (v3.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v1.HasFocus))
.AssertTrue (v1.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v3.HasFocus))
.AssertTrue (v3.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v1.HasFocus))
.AssertTrue (v1.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v3.HasFocus))
.AssertTrue (v3.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v1.HasFocus))
.AssertTrue (v1.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v3.HasFocus))
.AssertTrue (v3.HasFocus)
.RaiseKeyDownEvent (Key.Tab)
.Then (() => Assert.True (v4.HasFocus))
.AssertTrue (v4.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v1.HasFocus))
.AssertTrue (v1.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v5.HasFocus))
.AssertTrue (v5.HasFocus)
.RaiseKeyDownEvent (Key.Tab)
.Then (() => Assert.True (v6.HasFocus))
.AssertTrue (v6.HasFocus)
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v4.HasFocus))
.AssertTrue (v4.HasFocus)
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v6.HasFocus))
.AssertTrue (v6.HasFocus)
.WriteOutLogs (_out)
.Stop ();
Assert.False (v1.HasFocus);
@@ -221,6 +220,5 @@ public class BasicFluentAssertionTests
Assert.False (v3.HasFocus);
Assert.False (v4.HasFocus);
Assert.False (v5.HasFocus);
Assert.False (v6.HasFocus);
}
}

View File

@@ -41,15 +41,28 @@ public class FileDialogFluentTests
return mockFileSystem;
}
private Toplevel NewSaveDialog (out SaveDialog sd, bool modal = true)
{
return NewSaveDialog (out sd, out _, modal);
}
private Toplevel NewSaveDialog (out SaveDialog sd, out MockFileSystem fs,bool modal = true)
{
fs = CreateExampleFileSystem ();
sd = new SaveDialog (fs) { Modal = modal };
return sd;
}
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingEscape (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ());
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
using var c = With.A (()=>NewSaveDialog(out sd), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Escape ()
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd!.Canceled)
.Stop ();
}
@@ -57,11 +70,11 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingCancelButton_TabThenEnter (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
using var c = With.A (() => NewSaveDialog (out sd,modal:false), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Focus<Button> (b => b.Text == "_Cancel")
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Enter ()
.Stop ();
}
@@ -70,25 +83,24 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingCancelButton_LeftClickButton (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ());
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
using var c = With.A (() => NewSaveDialog (out sd), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.LeftClick<Button> (b => b.Text == "_Cancel")
.WriteOutLogs (_out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Stop ();
}
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingCancelButton_AltC (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ());
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
using var c = With.A (() => NewSaveDialog (out sd), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Send (Key.C.WithAlt)
.WriteOutLogs (_out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Stop ();
}
@@ -96,14 +108,15 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_UsingOkButton_Enter (V2TestDriver d)
{
var fs = CreateExampleFileSystem ();
var sd = new SaveDialog (fs);
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd,out fs), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.LeftClick<Button> (b => b.Text == "_Save")
.WaitIteration ()
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.AssertFalse(sd.Canceled)
.AssertEqual (GetFileSystemRoot (fs), sd.FileName)
.Stop ();
}
@@ -111,14 +124,14 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_UsingOkButton_AltS (V2TestDriver d)
{
var fs = CreateExampleFileSystem ();
var sd = new SaveDialog (fs);
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Send (Key.S.WithAlt)
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.AssertFalse (sd.Canceled)
.AssertEqual (GetFileSystemRoot (fs), sd.FileName)
.Stop ();
}
@@ -127,42 +140,39 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_UsingOkButton_TabEnter (V2TestDriver d)
{
var fs = CreateExampleFileSystem ();
var sd = new SaveDialog (fs) { Modal = false };
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs,modal:false), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Focus<Button> (b => b.Text == "_Save")
.Enter ()
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.AssertFalse(sd.Canceled)
.AssertEqual (GetFileSystemRoot(fs), sd.FileName)
.Stop ();
}
private void AssertIsFileSystemRoot (IFileSystem fs, SaveDialog sd)
private string GetFileSystemRoot (IFileSystem fs)
{
var expectedPath =
RuntimeInformation.IsOSPlatform (OSPlatform.Windows) ?
return RuntimeInformation.IsOSPlatform (OSPlatform.Windows) ?
$@"C:{fs.Path.DirectorySeparatorChar}" :
"/";
Assert.Equal (expectedPath, sd.FileName);
}
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_PressingPopTree_ShouldNotChangeCancel (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs,modal:false), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Focus<Button> (b => b.Text == "►►")
.Enter ()
.ScreenShot ("After pop tree", _out)
.WriteOutLogs (_out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Stop ();
}
@@ -171,11 +181,11 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_PopTree_AndNavigate (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.LeftClick<Button> (b => b.Text == "►►")
.ScreenShot ("After pop tree", _out)
.Focus<TreeView<IFileSystemInfo>> (_ => true)
@@ -185,7 +195,7 @@ public class FileDialogFluentTests
.ScreenShot ("After navigate down in tree", _out)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertFalse (sd.Canceled)
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
@@ -195,12 +205,12 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_PopTree_AndNavigate_PreserveFilenameOnDirectoryChanges_True (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
sd.Style.PreserveFilenameOnDirectoryChanges = true;
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
.Then (()=>sd.Style.PreserveFilenameOnDirectoryChanges=true)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Focus<TextField> (_=>true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
@@ -228,7 +238,7 @@ public class FileDialogFluentTests
.AssertEndsWith ("hello", sd.Path)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertFalse (sd.Canceled)
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
@@ -238,12 +248,12 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers))]
public void SaveFileDialog_PopTree_AndNavigate_PreserveFilenameOnDirectoryChanges_False (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
sd.Style.PreserveFilenameOnDirectoryChanges = false;
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
.Then (()=> sd.Style.PreserveFilenameOnDirectoryChanges = false)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Focus<TextField> (_ => true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
@@ -269,7 +279,7 @@ public class FileDialogFluentTests
.AssertDoesNotContain ("hello", sd.Path)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertFalse (sd.Canceled)
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
@@ -279,12 +289,12 @@ public class FileDialogFluentTests
[ClassData (typeof (V2TestDrivers_WithTrueFalseParameter))]
public void SaveFileDialog_TableView_UpDown_PreserveFilenameOnDirectoryChanges_True (V2TestDriver d, bool preserve)
{
var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false };
sd.Style.PreserveFilenameOnDirectoryChanges = preserve;
using var c = With.A (sd, 100, 20, d)
SaveDialog? sd = null;
MockFileSystem? fs = null;
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
.Then (() => sd.Style.PreserveFilenameOnDirectoryChanges = preserve)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.AssertTrue (sd.Canceled)
.Focus<TextField> (_ => true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
@@ -344,6 +354,7 @@ public class FileDialogFluentTests
}
c.LeftClick<Button> (b => b.Text == "_Save");
c.WaitIteration ();
c.AssertFalse (sd.Canceled);
if (preserve)
@@ -357,7 +368,8 @@ public class FileDialogFluentTests
.AssertDoesNotContain ("hello", sd.Path);
}
c.WriteOutLogs (_out)
.Stop ();
c.WriteOutLogs (_out);
c.WaitIteration ();
c.Stop ();
}
}

View File

@@ -1,6 +1,7 @@
using System.Globalization;
using System.Reflection;
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;
namespace IntegrationTests.FluentTests;
@@ -167,15 +168,15 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.WaitIteration ()
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.WriteOutLogs (_out)
.Then (() => Assert.Equal ("_New file", Application.Navigation!.GetFocused ()!.Title))
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (menuBar?.IsOpen ()))
.AssertEqual ("_New file", Application.Navigation!.GetFocused ()!.Title)
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (menuBar?.IsOpen ())
.WriteOutLogs (_out)
.Stop ();
}
@@ -205,14 +206,14 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.Then (() => Assert.Equal ("_New file", Application.Navigation!.GetFocused ()!.Title))
.AssertEqual ("_New file", Application.Navigation!.GetFocused ()!.Title)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.WriteOutLogs (_out)
.Stop ();
}
@@ -328,24 +329,24 @@ public class MenuBarv2Tests
.WaitIteration ()
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (menuBar?.IsOpen ()))
.Then (() => Assert.Equal ("_New file", Application.Navigation?.GetFocused ()!.Title))
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (menuBar?.IsOpen ())
.AssertEqual ("_New file", Application.Navigation?.GetFocused ()!.Title)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.Right ()
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.ScreenShot ("After right arrow", _out)
.Then (() => Assert.Equal ("Cu_t", Application.Navigation?.GetFocused ()!.Title))
.AssertEqual ("Cu_t", Application.Navigation?.GetFocused ()!.Title)
.Right ()
.ScreenShot ("After second right arrow", _out)
.Then (() => Assert.Equal ("_Online Help...", Application.Navigation?.GetFocused ()!.Title))
.AssertEqual ("_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))
.AssertEqual ("_New file", Application.Navigation?.GetFocused ()!.Title)
.Left ()
.ScreenShot ("After left arrow", _out)
.Then (() => Assert.Equal ("_Online Help...", Application.Navigation?.GetFocused ()!.Title))
.AssertEqual ("_Online Help...", Application.Navigation?.GetFocused ()!.Title)
.WriteOutLogs (_out)
.Stop ();
}
@@ -375,17 +376,17 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.Then (() => Assert.Equal ("_New file", Application.Navigation!.GetFocused ()!.Title))
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (menuBar?.IsOpen ()))
.Then (() => Assert.Equal ("_New file", Application.Navigation?.GetFocused ()!.Title))
.AssertEqual ("_New file", Application.Navigation!.GetFocused ()!.Title)
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (menuBar?.IsOpen ())
.AssertEqual ("_New file", Application.Navigation?.GetFocused ()!.Title)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.WriteOutLogs (_out)
.Stop ();
}
@@ -414,19 +415,19 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.RaiseKeyDownEvent (Key.CursorRight)
.Then (() => Assert.Equal ("Cu_t", Application.Navigation!.GetFocused ()!.Title))
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (menuBar?.IsOpen ()))
.Then (() => Assert.Equal ("Cu_t", Application.Navigation?.GetFocused ()!.Title))
.AssertEqual ("Cu_t", Application.Navigation!.GetFocused ()!.Title)
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (menuBar?.IsOpen ())
.AssertEqual ("Cu_t", Application.Navigation?.GetFocused ()!.Title)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.RaiseKeyDownEvent (Application.QuitKey)
.WriteOutLogs (_out)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.Stop ();
}
@@ -454,15 +455,15 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.Then (() => Assert.Equal ("_New file", Application.Navigation!.GetFocused ()!.Title))
.Then (() => Assert.True (Application.Top!.Running))
.AssertEqual ("_New file", Application.Navigation!.GetFocused ()!.Title)
.AssertTrue (Application.Top!.Running)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (Application.Top!.Running))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (Application.Top!.Running)
.WriteOutLogs (_out)
.Stop ();
}
@@ -496,14 +497,14 @@ public class MenuBarv2Tests
Application.Top!.Add (menuBar);
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.ScreenShot ("MenuBar initial state", _out)
.RaiseKeyDownEvent (MenuBarv2.DefaultKey)
.Then (() => Assert.Equal ("_New file", Application.Navigation!.GetFocused ()!.Title))
.AssertEqual ("_New file", Application.Navigation!.GetFocused ()!.Title)
.ScreenShot ($"After {MenuBarv2.DefaultKey}", _out)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (Application.Top!.Running))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (Application.Top!.Running)
.WriteOutLogs (_out)
.Stop ();
}
@@ -540,7 +541,7 @@ public class MenuBarv2Tests
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Space)
.Then (() => Assert.Equal (1, spaceKeyDownCount))
.AssertEqual (1, spaceKeyDownCount)
.WriteOutLogs (_out)
.Stop ();
}
@@ -577,7 +578,7 @@ public class MenuBarv2Tests
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Enter)
.Then (() => Assert.Equal (1, enterKeyDownCount))
.AssertEqual (1, enterKeyDownCount)
.WriteOutLogs (_out)
.Stop ();
}

View File

@@ -1,5 +1,6 @@
using System.Globalization;
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;
namespace IntegrationTests.FluentTests;
@@ -47,12 +48,15 @@ public class PopoverMenuTests
.Stop ();
}
private static object o = new ();
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void Activate_Sets_Application_Navigation_Correctly (V2TestDriver d)
{
using GuiTestContext c = With.A<Window> (50, 20, d)
lock (o)
{
using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
@@ -80,16 +84,18 @@ public class PopoverMenuTests
view.SetFocus ();
})
.WaitIteration ()
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsNotType<MenuItemv2> (Application.Navigation!.GetFocused ()))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType<MenuItemv2> (Application.Navigation!.GetFocused ())
.ScreenShot ("PopoverMenu initial state", _out)
.Then (() => Application.Popover!.Show (Application.Popover.Popovers.First ()))
.WaitIteration ()
.ScreenShot ($"After Show", _out)
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.Equal ("Cu_t", Application.Navigation!.GetFocused ()!.Title))
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertEqual ("Cu_t", Application.Navigation!.GetFocused ()!.Title)
.WriteOutLogs (_out)
.Stop ();
}
}
[Theory]
@@ -125,19 +131,18 @@ public class PopoverMenuTests
})
.WaitIteration ()
.ScreenShot ("PopoverMenu initial state", _out)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.Then (() => Application.Popover!.Show (Application.Popover.Popovers.First ()))
.WaitIteration ()
.ScreenShot ($"After Show", _out)
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Application.LayoutAndDraw (true))
.WaitIteration ()
.WriteOutLogs (_out)
.ScreenShot ($"After {Application.QuitKey}", _out)
.Then (() => Assert.False (Application.Popover!.Popovers.Cast<PopoverMenu> ().FirstOrDefault()!.Visible))
.Then (() => Assert.Null (Application.Popover!.GetActivePopover()))
.Then (() => Assert.True (Application.Top!.Running))
.AssertFalse (Application.Popover!.Popovers.Cast<PopoverMenu> ().FirstOrDefault()!.Visible)
.AssertNull (Application.Popover!.GetActivePopover())
.AssertTrue (Application.Top!.Running)
.WriteOutLogs (_out)
.Stop ();
}
@@ -175,17 +180,17 @@ public class PopoverMenuTests
})
.WaitIteration ()
.ScreenShot ("PopoverMenu initial state", _out)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.Then (() => Application.Popover!.Show (Application.Popover.Popovers.First ()))
.WaitIteration ()
.ScreenShot ($"After Show", _out)
.Then (() => Assert.True (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertTrue (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsType<MenuItemv2>(Application.Navigation!.GetFocused())
.RaiseKeyDownEvent (Application.QuitKey)
.ScreenShot ($"After {Application.QuitKey}", _out)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.WriteOutLogs (_out)
.Stop ();
}
@@ -222,18 +227,18 @@ public class PopoverMenuTests
view.SetFocus ();
})
.WaitIteration ()
.Then (() => Assert.IsNotType<MenuItemv2>(Application.Navigation!.GetFocused()))
.AssertIsNotType<MenuItemv2>(Application.Navigation!.GetFocused())
.ScreenShot ("PopoverMenu initial state", _out)
.Then (() => Application.Popover!.Show (Application.Popover.Popovers.First ()))
.WaitIteration ()
.ScreenShot ("PopoverMenu after Show", _out)
.Then (() => Assert.Equal ("Cu_t", Application.Navigation!.GetFocused ()!.Title))
.Then (() => Assert.True (Application.Top!.Running))
.AssertEqual ("Cu_t", Application.Navigation!.GetFocused ()!.Title)
.AssertTrue (Application.Top!.Running)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Application.LayoutAndDraw ())
.WaitIteration ()
.ScreenShot ($"After {Application.QuitKey}", _out)
.Then (() => Assert.False (Application.Popover?.GetActivePopover () is PopoverMenu))
.Then (() => Assert.True (Application.Top!.Running))
.AssertFalse (Application.Popover?.GetActivePopover () is PopoverMenu)
.AssertTrue (Application.Top!.Running)
.WriteOutLogs (_out)
.Stop ();
}
@@ -271,7 +276,7 @@ public class PopoverMenuTests
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Space)
.Then (() => Assert.Equal (1, spaceKeyDownCount))
.AssertEqual (1, spaceKeyDownCount)
.WriteOutLogs (_out)
.Stop ();
}
@@ -308,7 +313,7 @@ public class PopoverMenuTests
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Enter)
.Then (() => Assert.Equal (1, enterKeyDownCount))
.AssertEqual (1, enterKeyDownCount)
.WriteOutLogs (_out)
.Stop ();
}
@@ -345,7 +350,7 @@ public class PopoverMenuTests
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Assert.Equal (1, quitKeyDownCount))
.AssertEqual (1, quitKeyDownCount)
.WriteOutLogs (_out)
.Stop ();
}

View File

@@ -42,7 +42,7 @@ public class TreeViewFluentTests
.WaitIteration ()
.ScreenShot ("Before expanding", _out)
.AssertEqual (root, tv.GetObjectOnRow (0))
.Then (() => Assert.Null (tv.GetObjectOnRow (1)))
.AssertNull (tv.GetObjectOnRow (1))
.Right ()
.ScreenShot ("After expanding", _out)
.AssertMultiple (