|
1 | 1 | using System;
|
| 2 | +using System.Linq; |
2 | 3 | using Terminal.Gui;
|
3 | 4 | using Xunit;
|
4 | 5 | using Xunit.Abstractions;
|
@@ -33,13 +34,33 @@ public void TestSplitContainer_Vertical ()
|
33 | 34 | splitContainer.Redraw (splitContainer.Bounds);
|
34 | 35 | TestHelpers.AssertDriverContentsAre (looksLike, output);
|
35 | 36 |
|
| 37 | + } |
| 38 | + [Fact, AutoInitShutdown] |
| 39 | + public void TestSplitContainer_Vertical_WithBorder () |
| 40 | + { |
| 41 | + var splitContainer = Get11By3SplitContainer (true); |
| 42 | + splitContainer.Redraw (splitContainer.Bounds); |
| 43 | + |
| 44 | + string looksLike = |
| 45 | +@" |
| 46 | +┌────┬────┐ |
| 47 | +│1111│2222│ |
| 48 | +└────┴────┘"; |
| 49 | + TestHelpers.AssertDriverContentsAre (looksLike, output); |
| 50 | + |
| 51 | + // Keyboard movement on splitter should have no effect if it is not focused |
| 52 | + splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())); |
| 53 | + splitContainer.SetNeedsDisplay (); |
| 54 | + splitContainer.Redraw (splitContainer.Bounds); |
| 55 | + TestHelpers.AssertDriverContentsAre (looksLike, output); |
| 56 | + |
36 | 57 | }
|
37 | 58 | [Fact, AutoInitShutdown]
|
38 | 59 | public void TestSplitContainer_Vertical_Focused ()
|
39 | 60 | {
|
40 | 61 | var splitContainer = Get11By3SplitContainer ();
|
41 |
| - splitContainer.EnsureFocus (); |
42 |
| - splitContainer.FocusFirst (); |
| 62 | + SetInputFocusLine (splitContainer); |
| 63 | + |
43 | 64 | splitContainer.Redraw (splitContainer.Bounds);
|
44 | 65 |
|
45 | 66 | string looksLike =
|
@@ -74,12 +95,52 @@ public void TestSplitContainer_Vertical_Focused ()
|
74 | 95 | TestHelpers.AssertDriverContentsAre (looksLike, output);
|
75 | 96 | }
|
76 | 97 |
|
| 98 | + [Fact, AutoInitShutdown] |
| 99 | + public void TestSplitContainer_Vertical_Focused_WithBorder () |
| 100 | + { |
| 101 | + var splitContainer = Get11By3SplitContainer (true); |
| 102 | + SetInputFocusLine (splitContainer); |
| 103 | + |
| 104 | + splitContainer.Redraw (splitContainer.Bounds); |
| 105 | + |
| 106 | + string looksLike = |
| 107 | +@" |
| 108 | +┌────┬────┐ |
| 109 | +│1111◊2222│ |
| 110 | +└────┴────┘"; |
| 111 | + TestHelpers.AssertDriverContentsAre (looksLike, output); |
| 112 | + |
| 113 | + // Now while focused move the splitter 1 unit right |
| 114 | + splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())); |
| 115 | + splitContainer.Redraw (splitContainer.Bounds); |
| 116 | + |
| 117 | + looksLike = |
| 118 | +@" |
| 119 | +┌─────┬───┐ |
| 120 | +│11111◊222│ |
| 121 | +└─────┴───┘"; |
| 122 | + TestHelpers.AssertDriverContentsAre (looksLike, output); |
| 123 | + |
| 124 | + |
| 125 | + // and 2 to the left |
| 126 | + splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())); |
| 127 | + splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())); |
| 128 | + splitContainer.Redraw (splitContainer.Bounds); |
| 129 | + |
| 130 | + looksLike = |
| 131 | +@" |
| 132 | +┌───┬─────┐ |
| 133 | +│111◊22222│ |
| 134 | +└───┴─────┘"; |
| 135 | + TestHelpers.AssertDriverContentsAre (looksLike, output); |
| 136 | + } |
| 137 | + |
| 138 | + |
77 | 139 | [Fact, AutoInitShutdown]
|
78 | 140 | public void TestSplitContainer_Vertical_Focused_50PercentSplit ()
|
79 | 141 | {
|
80 | 142 | var splitContainer = Get11By3SplitContainer ();
|
81 |
| - splitContainer.EnsureFocus (); |
82 |
| - splitContainer.FocusFirst (); |
| 143 | + SetInputFocusLine (splitContainer); |
83 | 144 | splitContainer.SplitterDistance = Pos.Percent (50);
|
84 | 145 | Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
|
85 | 146 | splitContainer.Redraw (splitContainer.Bounds);
|
@@ -147,9 +208,7 @@ public void TestSplitContainer_Horizontal ()
|
147 | 208 | public void TestSplitContainer_Vertical_Panel1MinSize_Absolute ()
|
148 | 209 | {
|
149 | 210 | var splitContainer = Get11By3SplitContainer ();
|
150 |
| - |
151 |
| - splitContainer.EnsureFocus (); |
152 |
| - splitContainer.FocusFirst (); |
| 211 | + SetInputFocusLine (splitContainer); |
153 | 212 | splitContainer.Panels [0].MinSize = 6;
|
154 | 213 |
|
155 | 214 | // distance is too small (below 6)
|
@@ -195,8 +254,7 @@ public void TestSplitContainer_Horizontal_Focused ()
|
195 | 254 | var splitContainer = Get11By3SplitContainer ();
|
196 | 255 |
|
197 | 256 | splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
|
198 |
| - splitContainer.EnsureFocus (); |
199 |
| - splitContainer.FocusFirst (); |
| 257 | + SetInputFocusLine (splitContainer); |
200 | 258 |
|
201 | 259 | splitContainer.Redraw (splitContainer.Bounds);
|
202 | 260 |
|
@@ -235,8 +293,7 @@ public void TestSplitContainer_Horizontal_Panel1MinSize_Absolute ()
|
235 | 293 | var splitContainer = Get11By3SplitContainer ();
|
236 | 294 |
|
237 | 295 | splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
|
238 |
| - splitContainer.EnsureFocus (); |
239 |
| - splitContainer.FocusFirst (); |
| 296 | + SetInputFocusLine (splitContainer); |
240 | 297 | splitContainer.Panels [0].MinSize = 1;
|
241 | 298 |
|
242 | 299 | // 0 should not be allowed because it brings us below minimum size of Panel1
|
@@ -291,15 +348,24 @@ public void TestSplitContainer_CannotSetSplitterPosToFuncEtc ()
|
291 | 348 | Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosCombine", ex.Message);
|
292 | 349 | }
|
293 | 350 |
|
294 |
| - private SplitContainer Get11By3SplitContainer () |
| 351 | + private void SetInputFocusLine (SplitContainer splitContainer) |
| 352 | + { |
| 353 | + var line = splitContainer.Subviews [0].Subviews.OfType<LineView> ().Single (); |
| 354 | + line.SetFocus (); |
| 355 | + Assert.True (line.HasFocus); |
| 356 | + } |
| 357 | + |
| 358 | + private SplitContainer Get11By3SplitContainer (bool withBorder = false) |
295 | 359 | {
|
296 | 360 | var container = new SplitContainer () {
|
297 | 361 | Width = 11,
|
298 | 362 | Height = 3,
|
299 | 363 | };
|
300 | 364 |
|
301 |
| - container.Border.DrawMarginFrame = false; |
302 |
| - container.Border.BorderStyle = BorderStyle.None; |
| 365 | + if (!withBorder) { |
| 366 | + container.Border.BorderStyle = BorderStyle.None; |
| 367 | + container.Border.DrawMarginFrame = false; |
| 368 | + } |
303 | 369 |
|
304 | 370 | container.Panels [0].Add (new Label (new string ('1', 100)));
|
305 | 371 | container.Panels [1].Add (new Label (new string ('2', 100)));
|
|
0 commit comments