Browse Source

Fixing SplitContainer unit tests

tznind 2 years ago
parent
commit
634d5877cf
2 changed files with 46 additions and 31 deletions
  1. 3 1
      Terminal.Gui/Views/SplitContainer.cs
  2. 43 30
      UnitTests/SplitContainerTests.cs

+ 3 - 1
Terminal.Gui/Views/SplitContainer.cs

@@ -70,6 +70,7 @@ namespace Terminal.Gui {
 			set {
 			set {
 				orientation = value;
 				orientation = value;
 				Setup ();
 				Setup ();
+				LayoutSubviews ();
 			}
 			}
 		}
 		}
 
 
@@ -90,6 +91,7 @@ namespace Terminal.Gui {
 				splitterDistance = value;
 				splitterDistance = value;
 				Setup ();
 				Setup ();
 				OnSplitterMoved ();
 				OnSplitterMoved ();
+				LayoutSubviews ();
 			}
 			}
 		}
 		}
 
 
@@ -243,7 +245,7 @@ namespace Terminal.Gui {
 		/// A panel within a <see cref="SplitterPanel"/>. 
 		/// A panel within a <see cref="SplitterPanel"/>. 
 		/// </summary>
 		/// </summary>
 		public class SplitterPanel : View {
 		public class SplitterPanel : View {
-			Pos minSize = 2;
+			Pos minSize = 1;
 
 
 			/// <summary>
 			/// <summary>
 			/// Gets or sets the minimum size for the panel.
 			/// Gets or sets the minimum size for the panel.

+ 43 - 30
UnitTests/SplitContainerTests.cs

@@ -18,7 +18,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical ()
 		public void TestSplitContainer_Vertical ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			string looksLike =
 			string looksLike =
@@ -29,7 +29,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Keyboard movement on splitter should have no effect if it is not focused
 			// Keyboard movement on splitter should have no effect if it is not focused
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
@@ -38,7 +38,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical_WithBorder ()
 		public void TestSplitContainer_Vertical_WithBorder ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer (true);
+			var splitContainer = Get11By3SplitContainer (out var line, true);
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			string looksLike =
 			string looksLike =
@@ -49,7 +49,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Keyboard movement on splitter should have no effect if it is not focused
 			// Keyboard movement on splitter should have no effect if it is not focused
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
@@ -58,7 +58,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical_Focused ()
 		public void TestSplitContainer_Vertical_Focused ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
 
 
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
@@ -71,7 +71,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Now while focused move the splitter 1 unit right
 			// Now while focused move the splitter 1 unit right
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -83,8 +83,8 @@ namespace UnitTests {
 
 
 
 
 			// and 2 to the left
 			// and 2 to the left
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -98,7 +98,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical_Focused_WithBorder ()
 		public void TestSplitContainer_Vertical_Focused_WithBorder ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer (true);
+			var splitContainer = Get11By3SplitContainer (out var line, true);
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
 
 
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
@@ -111,7 +111,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Now while focused move the splitter 1 unit right
 			// Now while focused move the splitter 1 unit right
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -123,8 +123,8 @@ namespace UnitTests {
 
 
 
 
 			// and 2 to the left
 			// and 2 to the left
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -139,7 +139,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical_Focused_50PercentSplit ()
 		public void TestSplitContainer_Vertical_Focused_50PercentSplit ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
 			splitContainer.SplitterDistance = Pos.Percent (50);
 			splitContainer.SplitterDistance = Pos.Percent (50);
 			Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
 			Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
@@ -153,7 +153,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Now while focused move the splitter 1 unit right
 			// Now while focused move the splitter 1 unit right
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -168,8 +168,8 @@ namespace UnitTests {
 
 
 
 
 			// and 2 to the left
 			// and 2 to the left
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
 			looksLike =
 			looksLike =
@@ -185,7 +185,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Horizontal ()
 		public void TestSplitContainer_Horizontal ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
@@ -197,7 +197,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Keyboard movement on splitter should have no effect if it is not focused
 			// Keyboard movement on splitter should have no effect if it is not focused
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
@@ -207,7 +207,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Vertical_Panel1MinSize_Absolute ()
 		public void TestSplitContainer_Vertical_Panel1MinSize_Absolute ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
 			splitContainer.Panels [0].MinSize = 6;
 			splitContainer.Panels [0].MinSize = 6;
 
 
@@ -229,13 +229,13 @@ namespace UnitTests {
 
 
 			// Keyboard movement on splitter should have no effect because it
 			// Keyboard movement on splitter should have no effect because it
 			// would take us below the minimum splitter size
 			// would take us below the minimum splitter size
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// but we can continue to move the splitter right if we want
 			// but we can continue to move the splitter right if we want
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.SetNeedsDisplay ();
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 
 
@@ -251,7 +251,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Horizontal_Focused ()
 		public void TestSplitContainer_Horizontal_Focused ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 
 
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
@@ -266,7 +266,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Now move splitter line down
 			// Now move splitter line down
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			looksLike =
 			looksLike =
 @"    
 @"    
@@ -276,8 +276,8 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// And 2 up
 			// And 2 up
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			looksLike =
 			looksLike =
 @"    
 @"    
@@ -290,7 +290,7 @@ namespace UnitTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestSplitContainer_Horizontal_Panel1MinSize_Absolute ()
 		public void TestSplitContainer_Horizontal_Panel1MinSize_Absolute ()
 		{
 		{
-			var splitContainer = Get11By3SplitContainer ();
+			var splitContainer = Get11By3SplitContainer (out var line);
 
 
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
 			SetInputFocusLine (splitContainer);
 			SetInputFocusLine (splitContainer);
@@ -310,7 +310,7 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// Now move splitter line down (allowed
 			// Now move splitter line down (allowed
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			looksLike =
 			looksLike =
 @"    
 @"    
@@ -320,8 +320,8 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
 			// And up 2 (only 1 is allowed because of minimum size of 1 on panel1)
 			// And up 2 (only 1 is allowed because of minimum size of 1 on panel1)
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
-			splitContainer.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
+			line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
 			splitContainer.Redraw (splitContainer.Bounds);
 			splitContainer.Redraw (splitContainer.Bounds);
 			looksLike =
 			looksLike =
 @"    
 @"    
@@ -348,13 +348,26 @@ namespace UnitTests {
 			Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property.  Passed value was PosCombine", ex.Message);
 			Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property.  Passed value was PosCombine", ex.Message);
 		}
 		}
 
 
+		private LineView GetSplitContainerLineView (SplitContainer splitContainer)
+		{
+			return splitContainer.Subviews [0].Subviews.OfType<LineView> ().Single ();
+		}
+
 		private void SetInputFocusLine (SplitContainer splitContainer)
 		private void SetInputFocusLine (SplitContainer splitContainer)
 		{
 		{
-			var line = splitContainer.Subviews [0].Subviews.OfType<LineView> ().Single ();
+			var line = GetSplitContainerLineView (splitContainer);
 			line.SetFocus ();
 			line.SetFocus ();
 			Assert.True (line.HasFocus);
 			Assert.True (line.HasFocus);
 		}
 		}
 
 
+		private SplitContainer Get11By3SplitContainer(out LineView line, bool withBorder = false)
+		{
+			var split = Get11By3SplitContainer (withBorder);
+			line = GetSplitContainerLineView (split);
+			
+			return split;
+		}
+
 		private SplitContainer Get11By3SplitContainer (bool withBorder = false)
 		private SplitContainer Get11By3SplitContainer (bool withBorder = false)
 		{
 		{
 			var container = new SplitContainer () {
 			var container = new SplitContainer () {