Fixes #4035 - FileDialog keeps path when selecting folder (optionally) (#4065)

* WIP keep path

* Make new 'sticky filename' behaviour optional

* Tests for new behaviour when selecting in TreeView

* Add more tests, this time for table view navigation

* Add the new style option into UICatalog scenario
This commit is contained in:
Thomas Nind
2025-05-09 15:47:04 +01:00
committed by GitHub
parent b46b7781f1
commit d0bfa5ef13
5 changed files with 236 additions and 4 deletions

View File

@@ -189,4 +189,174 @@ public class FileDialogFluentTests
.WriteOutLogs (_out)
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.Focus<TextField> (_=>true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
.AssertIsType <TextField>(sd.Focused)
// Type a filename into the dialog
.RaiseKeyDownEvent (Key.H)
.RaiseKeyDownEvent (Key.E)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.O)
.WaitIteration ()
.ScreenShot ("After typing filename 'hello'", _out)
.AssertEndsWith ("hello", sd.Path)
.LeftClick<Button> (b => b.Text == "►►")
.ScreenShot ("After pop tree", _out)
.Focus<TreeView<IFileSystemInfo>> (_ => true)
.Right ()
.ScreenShot ("After expand tree", _out)
// Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
.AssertEndsWith ("hello", sd.Path)
.Down ()
.ScreenShot ("After navigate down in tree", _out)
// Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
.AssertContains ("empty-dir",sd.Path)
.AssertEndsWith ("hello", sd.Path)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.Focus<TextField> (_ => true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
.AssertIsType<TextField> (sd.Focused)
// Type a filename into the dialog
.RaiseKeyDownEvent (Key.H)
.RaiseKeyDownEvent (Key.E)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.O)
.WaitIteration ()
.ScreenShot ("After typing filename 'hello'", _out)
.AssertEndsWith ("hello", sd.Path)
.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)
// PreserveFilenameOnDirectoryChanges is false so just select new path
.AssertEndsWith ("empty-dir", sd.Path)
.AssertDoesNotContain ("hello", sd.Path)
.Enter ()
.WaitIteration ()
.Then (() => Assert.False (sd.Canceled))
.AssertContains ("empty-dir", sd.FileName)
.WriteOutLogs (_out)
.Stop ();
}
[Theory]
[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)
.ScreenShot ("Save dialog", _out)
.Then (() => Assert.True (sd.Canceled))
.Focus<TextField> (_ => true)
// Clear selection by pressing right in 'file path' text box
.RaiseKeyDownEvent (Key.CursorRight)
.AssertIsType<TextField> (sd.Focused)
// Type a filename into the dialog
.RaiseKeyDownEvent (Key.H)
.RaiseKeyDownEvent (Key.E)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.L)
.RaiseKeyDownEvent (Key.O)
.WaitIteration ()
.ScreenShot ("After typing filename 'hello'", _out)
.AssertEndsWith ("hello", sd.Path)
.Focus<TableView> (_ => true)
.ScreenShot ("After focus table", _out)
.Down ()
.ScreenShot ("After down in table", _out);
if (preserve)
{
c.AssertContains ("logs", sd.Path)
.AssertEndsWith ("hello", sd.Path);
}
else
{
c.AssertContains ("logs", sd.Path)
.AssertDoesNotContain ("hello", sd.Path);
}
c.Up ()
.ScreenShot ("After up in table", _out);
if (preserve)
{
c.AssertContains ("empty-dir", sd.Path)
.AssertEndsWith ("hello", sd.Path);
}
else
{
c.AssertContains ("empty-dir", sd.Path)
.AssertDoesNotContain ("hello", sd.Path);
}
c.Enter ()
.ScreenShot ("After enter in table", _out); ;
if (preserve)
{
c.AssertContains ("empty-dir", sd.Path)
.AssertEndsWith ("hello", sd.Path);
}
else
{
c.AssertContains ("empty-dir", sd.Path)
.AssertDoesNotContain ("hello", sd.Path);
}
c.LeftClick<Button> (b => b.Text == "_Save");
c.AssertFalse (sd.Canceled);
if (preserve)
{
c.AssertContains ("empty-dir", sd.Path)
.AssertEndsWith ("hello", sd.Path);
}
else
{
c.AssertContains ("empty-dir", sd.Path)
.AssertDoesNotContain ("hello", sd.Path);
}
c.WriteOutLogs (_out)
.Stop ();
}
}

View File

@@ -13,3 +13,20 @@ public class V2TestDrivers : IEnumerable<object []>
IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
}
/// <summary>
/// Test cases for functions with signature <code>V2TestDriver d, bool someFlag</code>
/// that enumerates all variations
/// </summary>
public class V2TestDrivers_WithTrueFalseParameter : IEnumerable<object []>
{
public IEnumerator<object []> GetEnumerator ()
{
yield return new object [] { V2TestDriver.V2Win,false };
yield return new object [] { V2TestDriver.V2Net,false };
yield return new object [] { V2TestDriver.V2Win,true };
yield return new object [] { V2TestDriver.V2Net,true };
}
IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
}