Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Terminal.Gui/FileServices/FileDialogStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Terminal.Gui;
public class FileDialogStyle
{
private readonly IFileSystem _fileSystem;
private bool _preserveFilenameOnDirectoryChanges;

/// <summary>Creates a new instance of the <see cref="FileDialogStyle"/> class.</summary>
public FileDialogStyle (IFileSystem fileSystem)
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public virtual void Paste ()
TextModel.SetCol (ref col, Viewport.Width - 1, cols);
}

int pos = col - ScrollOffset + Math.Min (Viewport.X, 0);
int pos = col + Math.Min (Viewport.X, 0);
Move (pos, 0);

return new Point (pos, 0);
Expand Down
51 changes: 51 additions & 0 deletions Tests/IntegrationTests/FluentTests/TextFieldFluentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terminal.Gui;
using TerminalGuiFluentTesting;
using TerminalGuiFluentTestingXunit;
using Xunit.Abstractions;

namespace IntegrationTests.FluentTests;
public class TextFieldFluentTests
{
private readonly TextWriter _out;

public TextFieldFluentTests (ITestOutputHelper outputHelper)
{
_out = new TestOutputWriter (outputHelper);
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void TextField_Cursor_AtEnd_WhenTyping (V2TestDriver d)
{
// Simulates typing abcd into a TextField with width 3 (wide enough to render 2 characters only)
using var c = With.A<Window> (100, 20, d)
.Add (new TextField () { Width = 3 })
.Focus<TextField> ()
.WaitIteration ()
.AssertCursorPosition (new Point (1, 1)) // Initial cursor position (because Window has border)
.RaiseKeyDownEvent (Key.A)
.WaitIteration ()
.ScreenShot ("After typing first letter", _out)
.AssertCursorPosition (new Point (2, 1)) // Cursor moves along as letter is pressed
.RaiseKeyDownEvent (Key.B)
.WaitIteration ()
.AssertCursorPosition (new Point (3, 1)) // Cursor moves along as letter is pressed
.RaiseKeyDownEvent (Key.C)
.WaitIteration ()
.ScreenShot ("After typing all letters",_out)
.AssertCursorPosition (new Point (3, 1)) // Cursor stays where it is because we are at end of TextField
.RaiseKeyDownEvent (Key.D)
.WaitIteration ()
.ScreenShot ("Typing one more letter", _out)
.AssertCursorPosition (new Point (3, 1)) // Cursor still stays at end of TextField
.WriteOutLogs (_out)
.Stop ();
}
}
7 changes: 6 additions & 1 deletion Tests/TerminalGuiFluentTesting/FakeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public void Write (ReadOnlySpan<char> text) { }
public void SetCursorVisibility (CursorVisibility visibility) { }

/// <inheritdoc/>
public void SetCursorPosition (int col, int row) { }
public void SetCursorPosition (int col, int row) { CursorPosition = new Point (col, row); }

/// <summary>
/// The last value set by calling <see cref="SetCursorPosition"/>
/// </summary>
public Point CursorPosition { get; private set; }
}
15 changes: 14 additions & 1 deletion Tests/TerminalGuiFluentTesting/GuiTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,14 @@ public GuiTestContext Focus (View toFocus)
/// is found (of Type T) or all views are looped through (back to the beginning)
/// in which case triggers hard stop and Exception
/// </summary>
/// <param name="evaluator">Delegate that returns true if the passed View is the one
/// you are trying to focus. Leave <see langword="null"/> to focus the first view of type
/// <typeparamref name="T"/></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public GuiTestContext Focus<T> (Func<T, bool> evaluator) where T : View
public GuiTestContext Focus<T> (Func<T, bool>? evaluator = null) where T : View
{
evaluator ??= _ => true;
Toplevel? t = Application.Top;

HashSet<View> seen = new ();
Expand Down Expand Up @@ -816,4 +820,13 @@ public GuiTestContext Send (Key key)

return this;
}

/// <summary>
/// Returns the last set position of the cursor.
/// </summary>
/// <returns></returns>
public Point GetCursorPosition ()
{
return _output.CursorPosition;
}
}
26 changes: 25 additions & 1 deletion Tests/TerminalGuiFluentTestingXunit/XunitContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
using TerminalGuiFluentTesting;
using System.Drawing;
using TerminalGuiFluentTesting;
using Xunit;

namespace TerminalGuiFluentTestingXunit;

public static partial class XunitContextExtensions
{
// Placeholder


/// <summary>
/// Asserts that the last set cursor position matches <paramref name="expected"/>
/// </summary>
/// <param name="context"></param>
/// <param name="expected"></param>
/// <returns></returns>
public static GuiTestContext AssertCursorPosition (this GuiTestContext context, Point expected)
{
try
{
Assert.Equal (expected, context.GetCursorPosition ());
}
catch (Exception)
{
context.HardStop ();

throw;
}

return context;
}
}
Loading