TextFieldFluentTests.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO.Abstractions;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Terminal.Gui;
  9. using TerminalGuiFluentTesting;
  10. using TerminalGuiFluentTestingXunit;
  11. using Xunit.Abstractions;
  12. namespace IntegrationTests.FluentTests;
  13. public class TextFieldFluentTests
  14. {
  15. private readonly TextWriter _out;
  16. public TextFieldFluentTests (ITestOutputHelper outputHelper)
  17. {
  18. _out = new TestOutputWriter (outputHelper);
  19. }
  20. [Theory]
  21. [ClassData (typeof (V2TestDrivers))]
  22. public void TextField_Cursor_AtEnd_WhenTyping (V2TestDriver d)
  23. {
  24. // Simulates typing abcd into a TextField with width 3 (wide enough to render 2 characters only)
  25. using var c = With.A<Window> (100, 20, d)
  26. .Add (new TextField () { Width = 3 })
  27. .Focus<TextField> ()
  28. .WaitIteration ()
  29. .AssertCursorPosition (new Point (1, 1)) // Initial cursor position (because Window has border)
  30. .RaiseKeyDownEvent (Key.A)
  31. .WaitIteration ()
  32. .ScreenShot ("After typing first letter", _out)
  33. .AssertCursorPosition (new Point (2, 1)) // Cursor moves along as letter is pressed
  34. .RaiseKeyDownEvent (Key.B)
  35. .WaitIteration ()
  36. .AssertCursorPosition (new Point (3, 1)) // Cursor moves along as letter is pressed
  37. .RaiseKeyDownEvent (Key.C)
  38. .WaitIteration ()
  39. .ScreenShot ("After typing all letters",_out)
  40. .AssertCursorPosition (new Point (3, 1)) // Cursor stays where it is because we are at end of TextField
  41. .RaiseKeyDownEvent (Key.D)
  42. .WaitIteration ()
  43. .ScreenShot ("Typing one more letter", _out)
  44. .AssertCursorPosition (new Point (3, 1)) // Cursor still stays at end of TextField
  45. .WriteOutLogs (_out)
  46. .Stop ();
  47. }
  48. }