Add test for ensuring PosFactor preserves its type during keyboard splitter movement

This commit is contained in:
tznind
2022-12-24 20:23:44 +00:00
parent 5d39ae7ac6
commit a4d49d00eb
2 changed files with 73 additions and 24 deletions

View File

@@ -14,8 +14,8 @@ namespace UnitTests {
}
[Fact,AutoInitShutdown]
public void TestSplitContainer_Vertical()
[Fact, AutoInitShutdown]
public void TestSplitContainer_Vertical ()
{
var splitContainer = Get11By3SplitContainer ();
splitContainer.Redraw (splitContainer.Bounds);
@@ -74,6 +74,53 @@ namespace UnitTests {
TestHelpers.AssertDriverContentsAre (looksLike, output);
}
[Fact, AutoInitShutdown]
public void TestSplitContainer_Vertical_Focused_50PercentSplit ()
{
var splitContainer = Get11By3SplitContainer ();
splitContainer.EnsureFocus ();
splitContainer.FocusFirst ();
splitContainer.SplitterDistance = Pos.Percent (50);
Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
splitContainer.Redraw (splitContainer.Bounds);
string looksLike =
@"
11111│22222
│ ";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// Now while focused move the splitter 1 unit right
splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
111111│2222
│ ";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// Even when moving the splitter location it should stay a Percentage based one
Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
// and 2 to the left
splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
splitContainer.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
1111│222222
│ ";
TestHelpers.AssertDriverContentsAre (looksLike, output);
// Even when moving the splitter location it should stay a Percentage based one
Assert.IsType<Pos.PosFactor> (splitContainer.SplitterDistance);
}
[Fact, AutoInitShutdown]
public void TestSplitContainer_Horizontal ()
{
@@ -100,7 +147,7 @@ namespace UnitTests {
public void TestSplitContainer_Vertical_Panel1MinSize_Absolute ()
{
var splitContainer = Get11By3SplitContainer ();
splitContainer.EnsureFocus ();
splitContainer.FocusFirst ();
splitContainer.Panel1MinSize = 6;
@@ -109,7 +156,7 @@ namespace UnitTests {
splitContainer.SplitterDistance = 2;
// Should bound the value to the minimum distance
Assert.Equal(6,splitContainer.SplitterDistance);
Assert.Equal (6, splitContainer.SplitterDistance);
splitContainer.Redraw (splitContainer.Bounds);
@@ -132,7 +179,7 @@ namespace UnitTests {
splitContainer.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
splitContainer.SetNeedsDisplay ();
splitContainer.Redraw (splitContainer.Bounds);
looksLike =
@"
1111111│222
@@ -148,8 +195,8 @@ namespace UnitTests {
var splitContainer = Get11By3SplitContainer ();
splitContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
splitContainer.EnsureFocus();
splitContainer.FocusFirst();
splitContainer.EnsureFocus ();
splitContainer.FocusFirst ();
splitContainer.Redraw (splitContainer.Bounds);
@@ -194,7 +241,7 @@ namespace UnitTests {
// 0 should not be allowed because it brings us below minimum size of Panel1
splitContainer.SplitterDistance = 0;
Assert.Equal((Pos)1,splitContainer.SplitterDistance);
Assert.Equal ((Pos)1, splitContainer.SplitterDistance);
splitContainer.Redraw (splitContainer.Bounds);
@@ -232,16 +279,16 @@ namespace UnitTests {
{
var splitContainer = Get11By3SplitContainer ();
var ex = Assert.Throws<ArgumentException>(()=>splitContainer.SplitterDistance = Pos.Right(splitContainer));
Assert.Equal("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosCombine",ex.Message);
var ex = Assert.Throws<ArgumentException> (() => splitContainer.SplitterDistance = Pos.Right (splitContainer));
Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosCombine", ex.Message);
ex = Assert.Throws<ArgumentException>(()=>splitContainer.SplitterDistance = Pos.Function(()=>1));
Assert.Equal("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosFunc",ex.Message);
ex = Assert.Throws<ArgumentException> (() => splitContainer.SplitterDistance = Pos.Function (() => 1));
Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosFunc", ex.Message);
// Also not allowed because this results in a PosCombine
ex = Assert.Throws<ArgumentException>(()=>splitContainer.SplitterDistance = Pos.Percent(50) - 1);
Assert.Equal("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosCombine",ex.Message);
ex = Assert.Throws<ArgumentException> (() => splitContainer.SplitterDistance = Pos.Percent (50) - 1);
Assert.Equal ("Only Percent and Absolute values are supported for SplitterDistance property. Passed value was PosCombine", ex.Message);
}
private SplitContainer Get11By3SplitContainer ()
@@ -250,7 +297,7 @@ namespace UnitTests {
Width = 11,
Height = 3,
};
container.Panel1.Add (new Label (new string ('1', 100)));
container.Panel2.Add (new Label (new string ('2', 100)));