Browse Source

Fixed Create and related unit tests

Tig Kindel 1 year ago
parent
commit
5ab8d4d545
2 changed files with 21 additions and 4 deletions
  1. 1 1
      Terminal.Gui/Views/Toplevel.cs
  2. 20 3
      UnitTests/Views/Toplevel/ToplevelTests.cs

+ 1 - 1
Terminal.Gui/Views/Toplevel.cs

@@ -60,7 +60,7 @@ public partial class Toplevel : View {
 	/// will be set to the dimensions of the terminal using <see cref="Dim.Fill"/>.
 	/// </remarks>
 	/// <returns>The created Toplevel.</returns>
-	public static Toplevel Create () => new (new Rect (0, 0, Driver.Cols, Driver.Rows)); // BUGBUG: Should be ComputedLayout
+	public static Toplevel Create () => new (); // BUGBUG: Should be ComputedLayout
 
 	/// <summary>
 	/// Gets or sets whether the main loop for this <see cref="Toplevel"/> is running or not.

+ 20 - 3
UnitTests/Views/Toplevel/ToplevelTests.cs

@@ -25,6 +25,11 @@ public class ToplevelTests {
 		Assert.Null (top.StatusBar);
 		Assert.False (top.IsOverlappedContainer);
 		Assert.False (top.IsOverlapped);
+
+		// Because Toplevel is LayoutStyle.Computed, SetRelativeLayout needs to be called
+		// to set the Frame.
+		top.SetRelativeLayout (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows));
+		Assert.Equal (new Rect (0,          0, Application.Driver.Cols, Application.Driver.Rows), top.Frame);
 	}
 
 	[Fact]
@@ -32,9 +37,21 @@ public class ToplevelTests {
 	public void Create_Toplevel ()
 	{
 		var top = Toplevel.Create ();
-		top.BeginInit ();
-		top.EndInit ();
-		Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
+
+		Assert.Equal (Colors.TopLevel, top.ColorScheme);
+		Assert.Equal ("Fill(0)",       top.Width.ToString ());
+		Assert.Equal ("Fill(0)",       top.Height.ToString ());
+		Assert.False (top.Running);
+		Assert.False (top.Modal);
+		Assert.Null (top.MenuBar);
+		Assert.Null (top.StatusBar);
+		Assert.False (top.IsOverlappedContainer);
+		Assert.False (top.IsOverlapped);
+
+		// Because Toplevel is LayoutStyle.Computed, SetRelativeLayout needs to be called
+		// to set the Frame.
+		top.SetRelativeLayout (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows));
+		Assert.Equal (new Rect (0,          0, Application.Driver.Cols, Application.Driver.Rows), top.Frame);
 	}
 
 #if BROKE_IN_2927