BasicFluentAssertionTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System.Text;
  2. using Terminal.Gui;
  3. using TerminalGuiFluentTesting;
  4. using Xunit.Abstractions;
  5. namespace IntegrationTests.FluentTests;
  6. public class BasicFluentAssertionTests
  7. {
  8. private readonly TextWriter _out;
  9. public class TestOutputWriter : TextWriter
  10. {
  11. private readonly ITestOutputHelper _output;
  12. public TestOutputWriter (ITestOutputHelper output) { _output = output; }
  13. public override void WriteLine (string? value) { _output.WriteLine (value ?? string.Empty); }
  14. public override Encoding Encoding => Encoding.UTF8;
  15. }
  16. public BasicFluentAssertionTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter (outputHelper); }
  17. [Fact]
  18. public void GuiTestContext_StartsAndStopsWithoutError ()
  19. {
  20. using GuiTestContext context = With.A<Window> (40, 10);
  21. // No actual assertions are needed — if no exceptions are thrown, it's working
  22. context.Stop ();
  23. }
  24. [Fact]
  25. public void GuiTestContext_ForgotToStop ()
  26. {
  27. using GuiTestContext context = With.A<Window> (40, 10);
  28. }
  29. [Fact]
  30. public void TestWindowsResize ()
  31. {
  32. var lbl = new Label
  33. {
  34. Width = Dim.Fill ()
  35. };
  36. using GuiTestContext c = With.A<Window> (40, 10)
  37. .Add (lbl)
  38. .Then (() => Assert.Equal (lbl.Frame.Width, 38)) // Window has 2 border
  39. .ResizeConsole (20, 20)
  40. .Then (() => Assert.Equal (lbl.Frame.Width, 18))
  41. .Stop ();
  42. }
  43. [Fact]
  44. public void ContextMenu_CrashesOnRight ()
  45. {
  46. var clicked = false;
  47. var ctx = new ContextMenu ();
  48. var menuItems = new MenuBarItem (
  49. [
  50. new ("_New File", string.Empty, () => { clicked = true; })
  51. ]
  52. );
  53. using GuiTestContext c = With.A<Window> (40, 10)
  54. .WithContextMenu (ctx, menuItems)
  55. .ScreenShot ("Before open menu", _out)
  56. // Click in main area inside border
  57. .RightClick (1, 1)
  58. .ScreenShot ("After open menu", _out)
  59. .LeftClick (3, 3)
  60. .Stop ()
  61. .WriteOutLogs (_out);
  62. Assert.True (clicked);
  63. }
  64. [Fact]
  65. public void ContextMenu_OpenSubmenu ()
  66. {
  67. var clicked = false;
  68. var ctx = new ContextMenu ();
  69. var menuItems = new MenuBarItem (
  70. [
  71. new MenuItem ("One", "", null),
  72. new MenuItem ("Two", "", null),
  73. new MenuItem ("Three", "", null),
  74. new MenuBarItem (
  75. "Four",
  76. [
  77. new MenuItem ("SubMenu1", "", null),
  78. new MenuItem ("SubMenu2", "", ()=>clicked=true),
  79. new MenuItem ("SubMenu3", "", null),
  80. new MenuItem ("SubMenu4", "", null),
  81. new MenuItem ("SubMenu5", "", null),
  82. new MenuItem ("SubMenu6", "", null),
  83. new MenuItem ("SubMenu7", "", null)
  84. ]
  85. ),
  86. new MenuItem ("Five", "", null),
  87. new MenuItem ("Six", "", null)
  88. ]
  89. );
  90. using GuiTestContext c = With.A<Window> (40, 10)
  91. .WithContextMenu (ctx, menuItems)
  92. .ScreenShot ("Before open menu", _out)
  93. // Click in main area inside border
  94. .RightClick (1, 1)
  95. .ScreenShot ("After open menu", _out)
  96. .Down ()
  97. .Down ()
  98. .Down ()
  99. .Right()
  100. .ScreenShot ("After open submenu", _out)
  101. .Down ()
  102. .Enter ()
  103. .ScreenShot ("Menu should be closed after selecting", _out)
  104. .Stop ()
  105. .WriteOutLogs (_out);
  106. Assert.True (clicked);
  107. }
  108. }