SplitContainerTests.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using Terminal.Gui;
  3. using Xunit;
  4. using Xunit.Abstractions;
  5. namespace UnitTests {
  6. public class SplitContainerTests {
  7. readonly ITestOutputHelper output;
  8. public SplitContainerTests (ITestOutputHelper output)
  9. {
  10. this.output = output;
  11. }
  12. [Fact,AutoInitShutdown]
  13. public void TestSplitContainer_Vertical()
  14. {
  15. var splitContainer = Get11By3SplitContainer ();
  16. splitContainer.Redraw (splitContainer.Bounds);
  17. string looksLike =
  18. @"
  19. 11111│22222
  20. │ ";
  21. TestHelpers.AssertDriverContentsAre (looksLike, output);
  22. // Keyboard movement on splitter should have no effect if it is not focused
  23. splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  24. splitContainer.SetNeedsDisplay ();
  25. splitContainer.Redraw (splitContainer.Bounds);
  26. TestHelpers.AssertDriverContentsAre (looksLike, output);
  27. }
  28. [Fact, AutoInitShutdown]
  29. public void TestSplitContainer_Vertical_Focused ()
  30. {
  31. var splitContainer = Get11By3SplitContainer ();
  32. splitContainer.EnsureFocus ();
  33. splitContainer.FocusFirst ();
  34. splitContainer.Redraw (splitContainer.Bounds);
  35. string looksLike =
  36. @"
  37. 11111│22222
  38. │ ";
  39. TestHelpers.AssertDriverContentsAre (looksLike, output);
  40. // Now while focused move the splitter 1 unit right
  41. splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  42. splitContainer.Redraw (splitContainer.Bounds);
  43. looksLike =
  44. @"
  45. 111111│2222
  46. │ ";
  47. TestHelpers.AssertDriverContentsAre (looksLike, output);
  48. // and 2 to the left
  49. splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  50. splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  51. splitContainer.Redraw (splitContainer.Bounds);
  52. looksLike =
  53. @"
  54. 1111│222222
  55. │ ";
  56. TestHelpers.AssertDriverContentsAre (looksLike, output);
  57. }
  58. [Fact, AutoInitShutdown]
  59. public void TestSplitContainer_Horizontal ()
  60. {
  61. var splitContainer = Get11By3SplitContainer ();
  62. splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  63. splitContainer.Redraw (splitContainer.Bounds);
  64. string looksLike =
  65. @"
  66. 11111111111
  67. ───────────
  68. 22222222222";
  69. TestHelpers.AssertDriverContentsAre (looksLike, output);
  70. // Keyboard movement on splitter should have no effect if it is not focused
  71. splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
  72. splitContainer.SetNeedsDisplay ();
  73. splitContainer.Redraw (splitContainer.Bounds);
  74. TestHelpers.AssertDriverContentsAre (looksLike, output);
  75. }
  76. [Fact, AutoInitShutdown]
  77. public void TestSplitContainer_Horizontal_Focused ()
  78. {
  79. var splitContainer = Get11By3SplitContainer ();
  80. splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  81. splitContainer.EnsureFocus();
  82. splitContainer.FocusFirst();
  83. splitContainer.Redraw (splitContainer.Bounds);
  84. string looksLike =
  85. @"
  86. 11111111111
  87. ─────◊─────
  88. 22222222222";
  89. TestHelpers.AssertDriverContentsAre (looksLike, output);
  90. // Now move splitter line down
  91. splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
  92. splitContainer.Redraw (splitContainer.Bounds);
  93. looksLike =
  94. @"
  95. 11111111111
  96. ─────◊─────";
  97. TestHelpers.AssertDriverContentsAre (looksLike, output);
  98. // And 2 up
  99. splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
  100. splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
  101. splitContainer.Redraw (splitContainer.Bounds);
  102. looksLike =
  103. @"
  104. ─────◊─────
  105. 22222222222";
  106. TestHelpers.AssertDriverContentsAre (looksLike, output);
  107. }
  108. private SplitContainer Get11By3SplitContainer ()
  109. {
  110. var container = new SplitContainer () {
  111. Width = 11,
  112. Height = 3,
  113. };
  114. container.Panel1.Add (new Label (new string ('1', 100)));
  115. container.Panel2.Add (new Label (new string ('2', 100)));
  116. Application.Top.Add (container);
  117. container.ColorScheme = new ColorScheme ();
  118. container.LayoutSubviews ();
  119. return container;
  120. }
  121. }
  122. }