Fixing tests...

This commit is contained in:
Tig
2024-04-18 13:14:22 -06:00
parent a48146af82
commit f3b5ed7afc
7 changed files with 454 additions and 417 deletions

View File

@@ -1,6 +1,8 @@
using System.Globalization;
using System.Text;
using Xunit.Abstractions;
using static Terminal.Gui.Dim;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
@@ -587,7 +589,7 @@ public class DimAutoTests
[InlineData (1, 10, 10)]
[InlineData (9, 10, 10)]
[InlineData (10, 10, 10)]
public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
{
var superView = new View
{
@@ -600,7 +602,6 @@ public class DimAutoTests
var subView = new View
{
Text = new string ('*', textLen),
X = subX,
Y = 0,
Width = Dim.Auto (Dim.DimAutoStyle.Subviews),
@@ -608,6 +609,16 @@ public class DimAutoTests
ValidatePosDim = true
};
var subSubView = new View
{
X = 0,
Y = 0,
Width = subSubViewWidth,
Height = 1,
ValidatePosDim = true
};
subView.Add (subSubView);
superView.Add (subView);
superView.BeginInit ();
@@ -618,5 +629,32 @@ public class DimAutoTests
Assert.Equal (expectedSubWidth, subView.Frame.Width);
}
[Fact]
public void DimAuto_Text_Viewport_Stays_Set ()
{
var super = new View ()
{
Width = Dim.Fill (),
Height = Dim.Fill ()
};
var view = new View ()
{
Width = Auto (DimAutoStyle.Text),
Height = Auto (DimAutoStyle.Text),
Text = "New text"
};
Rectangle expectedViewport = new (0, 0, 8, 1);
Assert.Equal (expectedViewport, view.Viewport);
super.Add (view);
Assert.Equal (expectedViewport, view.Viewport);
super.LayoutSubviews ();
Assert.Equal (expectedViewport, view.Viewport);
super.Dispose ();
}
// Test variations of Frame
}

View File

@@ -75,6 +75,7 @@ public class DimTests
Assert.Equal (10, result);
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// A new test that does not depend on Application is needed.
[Fact]
@@ -897,8 +898,8 @@ public class DimTests
Assert.Equal (50, v4.Frame.Width);
Assert.Equal (50, v4.Frame.Height);
v4.AutoSize = true;
Assert.Equal ("Absolute(11)", v4.Width.ToString ());
Assert.Equal ("Absolute(1)", v4.Height.ToString ());
Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Width);
Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Height);
Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is Dim.DimAbsolute
Assert.Equal (1, v4.Frame.Height); // 1 because is Dim.DimAbsolute