Files
Terminal.Gui/Tests/IntegrationTests/FluentTests/FileDialogFluentTests.cs
Tig 47bcf1bf57 Partial on #2975 - Replaces Menu v1 in many places with v2 (#4040)
* touching publish.yml

* Fixed UICatalog bugs. Added fluent tests.

* marked v1 menu stuff as obsolte

* Tweaks.
Added View.GetSubMenus<type>().

* fixed unit tests

* general messing around

* general messing around

* Playing with Fluent

* ColorScheme tweaks

* WIP: ColorScheme tweaks

* Playing with Fluent

* Merged from laptop2

* Hacky-ish fixes to:
- #4016
- #4014

* Fixed Region bug preventing menus without borders from working

* Tweaks

* Fixed a bunch of CM issues

* Fixed OoptionSelector

* ip

* FixedCM issues

* Fixed CM issues2

* Revert "FixedCM issues"

This reverts commit dd6c6a70a3.

* Reverted stuff

* Found and fixed bug in AllViews_Center_Properly

* Fixed CM issues2

* removed menuv2 onapplied.
Changed how UICatalog Applys CM

* changed test time out to see if it helkps with ubuntu fails

* reset app on fail?

* back to 1500ms

* Made StatusBar nullable.

* Code Cleanup.

* HexEditor Code Cleanup.

* HexEditor Code Cleanup.

* Back to 3000ms. Sigh.

* Trying different logic

* Trying different logic2

* Fixed potential crash in runlop

* Fixed potential crash in runlop2

* Tweaked Spinner stuff

* Removed TabView from TextEffects scenario. Not needed and possible culprit.

* back to 2000ms

* WIP: Revamping menu scenarios

* Menu Scenario refinements.
Fixed a few bugs.
Code cleanup.

* fixed unit test

* Fixed warnings

* Fixed warnings2

* Fixed File.Exit

* WIP: Dealing with QuitKey struggles

* WIP: Dealing with QuitKey struggles 2

* WIP: Dealing with QuitKey struggles 3

* Fixed ListView collection nav bug

* Fixed a bunch of menu stuff.
Fixed Appv2 stuff.

* Lots of refactoring and fixing

* Lots of unit test issues

* Fixed DebugIDisposable issues

* Fixed release build issue

* Fixed release build issue 2

* DebugIDisposable -> EnableDebugIDisposableAsserts and more

* DebugIDisposable -> EnableDebugIDisposableAsserts and more 2

* Fixed Menus scenario - context menu

* Added @bdisp suggested assert. Commented it out as it breaks tests.

* Code cleanup

* Fixed disposed but

* Fixed UICatalog exit

* Fixed Unit test I broke.
Added 'Minimal' Theme that turns off all borders etc...
2025-04-24 05:17:58 -06:00

193 lines
7.5 KiB
C#

using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Runtime.InteropServices;
using Terminal.Gui;
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;
namespace IntegrationTests.FluentTests;
public class FileDialogFluentTests
{
private readonly TextWriter _out;
public FileDialogFluentTests (ITestOutputHelper outputHelper)
{
_out = new TestOutputWriter (outputHelper);
}
private MockFileSystem CreateExampleFileSystem ()
{
// Optional: use Ordinal to simulate Linux-style case sensitivity
var mockFileSystem = new MockFileSystem (new Dictionary<string, MockFileData> ());
string testDir = mockFileSystem.Path.Combine ("test-dir");
string subDir = mockFileSystem.Path.Combine (testDir, "sub-dir");
string logsDir = "logs";
string emptyDir = "empty-dir";
// Add files
mockFileSystem.AddFile (mockFileSystem.Path.Combine (testDir, "file1.txt"), new MockFileData ("Hello, this is file 1."));
mockFileSystem.AddFile (mockFileSystem.Path.Combine (testDir, "file2.txt"), new MockFileData ("Hello, this is file 2."));
mockFileSystem.AddFile (mockFileSystem.Path.Combine (subDir, "nested-file.txt"), new MockFileData ("This is a nested file."));
mockFileSystem.AddFile (mockFileSystem.Path.Combine (logsDir, "log1.log"), new MockFileData ("Log entry 1"));
mockFileSystem.AddFile (mockFileSystem.Path.Combine (logsDir, "log2.log"), new MockFileData ("Log entry 2"));
// Create an empty directory
mockFileSystem.AddDirectory (emptyDir);
return mockFileSystem;
}
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingEscape (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ());
using var c = With.A (sd, 100, 20, d)
.ScreenShot ("Save dialog", _out)
.Escape ()
.Then (() => Assert.True (sd.Canceled))
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Focus<Button> (b => b.Text == "_Cancel")
.Then (() => Assert.True (sd.Canceled))
.Enter ()
.Stop ();
}
[Theory]
[ClassData (typeof (V2TestDrivers))]
public void CancelFileDialog_UsingCancelButton_LeftClickButton (V2TestDriver d)
{
var sd = new SaveDialog (CreateExampleFileSystem ());
using var c = With.A (sd, 100, 20, d)
.ScreenShot ("Save dialog", _out)
.LeftClick<Button> (b => b.Text == "_Cancel")
.WriteOutLogs (_out)
.Then (() => Assert.True (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)
.ScreenShot ("Save dialog", _out)
.Send (Key.C.WithAlt)
.WriteOutLogs (_out)
.Then (() => Assert.True (sd.Canceled))
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.LeftClick<Button> (b => b.Text == "_Save")
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Send (Key.S.WithAlt)
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Focus<Button> (b => b.Text == "_Save")
.Enter ()
.WriteOutLogs (_out)
.Then (() => Assert.False (sd.Canceled))
.Then (() => AssertIsFileSystemRoot (fs, sd))
.Stop ();
}
private void AssertIsFileSystemRoot (IFileSystem fs, SaveDialog sd)
{
var expectedPath =
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)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.Focus<Button> (b => b.Text == "►►")
.Enter ()
.ScreenShot ("After pop tree", _out)
.WriteOutLogs (_out)
.Then (() => Assert.True (sd.Canceled))
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.LeftClick<Button> (b => b.Text == "►►")
.ScreenShot ("After pop tree", _out)
.Focus<TreeView<IFileSystemInfo>> (_ => true)
.Right ()
.ScreenShot ("After expand tree", _out)
.Down ()
.ScreenShot ("After navigate down in tree", _out)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
}
}