TextFieldFluentTests.cs 2.2 KB

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