2
0

BasicFluentAssertionTests.cs 5.3 KB

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