Skip to content

Commit

Permalink
Actually Fixes gui-cs#3022 & adds unit test to prove it
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Dec 1, 2023
1 parent a044013 commit c948d03
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
33 changes: 31 additions & 2 deletions UnitTests/Views/TextFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using Xunit;
using Xunit.Abstractions;
using static Terminal.Gui.ViewsTests.TextViewTests;

namespace Terminal.Gui.ViewsTests {
public class TextFieldTests {
Expand All @@ -29,7 +30,9 @@ public override void Before (MethodInfo methodUnderTest)

// 1 2 3
// 01234567890123456789012345678901=32 (Length)
TextFieldTests._textField = new TextField ("TAB to jump between text fields.");
TextFieldTests._textField = new TextField ("TAB to jump between text fields.") {
ColorScheme = Colors.Base
};
}

public override void After (MethodInfo methodUnderTest)
Expand All @@ -41,6 +44,32 @@ public override void After (MethodInfo methodUnderTest)

private static TextField _textField;

[Fact]
[TextFieldTestsAutoInitShutdown]
public void Selected_Text_Shows ()
{
// Proves #3022 is fixed (TextField selected text does not show in v2)

_textField.CursorPosition = 0;
Application.Top.Add (_textField);
var rs = Application.Begin (Application.Top);

var attributes = new Attribute [] {
_textField.ColorScheme.Focus,
new Attribute(_textField.ColorScheme.Focus.Background, _textField.ColorScheme.Focus.Foreground)
};

// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("0000000", driver: Application.Driver, attributes);
_textField.ProcessKeyPressed (new (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));

bool first = true;
Application.RunIteration (ref rs, ref first);
Assert.Equal (4, _textField.CursorPosition);
// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("1111000", driver: Application.Driver, attributes);
}

[Fact]
[TextFieldTestsAutoInitShutdown]
public void Changing_SelectedStart_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
Expand Down Expand Up @@ -1258,7 +1287,7 @@ public void Test_RootMouseKeyEvent_Cancel ()
View = tf
};

Application.OnMouseEvent(new MouseEventEventArgs(mouseEvent));
Application.OnMouseEvent (new MouseEventEventArgs (mouseEvent));
Assert.Equal (1, clickCounter);

// Get a fresh instance that represents a right click.
Expand Down
10 changes: 7 additions & 3 deletions UnitTests/Views/TextViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public void WordBackward_With_No_Selection ()
public void Selected_Text_Shows ()
{
// Proves #3022 is fixed (TextField selected text does not show in v2)
Application.Top.Add (_textView);
var rs = Application.Begin (Application.Top);

_textView.CursorPosition = new Point (0, 0);
_textView.SelectionStartColumn = 0;
_textView.SelectionStartRow = 0;
Expand All @@ -287,14 +290,15 @@ public void Selected_Text_Shows ()
_textView.ColorScheme.Focus,
new Attribute(_textView.ColorScheme.Focus.Background, _textView.ColorScheme.Focus.Foreground)
};

_textView.OnDrawContent(_textView.Bounds);

// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("0000000", driver: Application.Driver, attributes);

_textView.ProcessKeyPressed (new (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));

_textView.OnDrawContent (_textView.Bounds);
bool first = true;
Application.RunIteration (ref rs, ref first);
Assert.Equal (new Point(4, 0), _textView.CursorPosition);
// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("1111000", driver: Application.Driver, attributes);
}
Expand Down

0 comments on commit c948d03

Please sign in to comment.