Fixed fragile toplevel drag unit tests

This commit is contained in:
Tig
2024-04-04 19:34:39 -04:00
parent c5b7b084a9
commit e1a2793c5c
3 changed files with 11 additions and 336 deletions

View File

@@ -812,77 +812,16 @@ public class ApplicationTests
((FakeDriver)Application.Driver).SetBufferSize (10, 10);
RunState rs = Application.Begin (w);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
_output
);
// Don't use visuals to test as style of border can change over time.
Assert.Equal (new Point (0, 0), w.Frame.Location);
Attribute [] attributes =
{
// 0
new (ColorName.White, ColorName.Black),
// 1
Colors.ColorSchemes ["Base"].Normal
};
TestHelpers.AssertDriverAttributesAre (
@"
1111100000
1111100000
1111100000
1111100000
1111100000
",
null,
attributes
);
// TODO: In PR #2920 this breaks because the mouse is not grabbed anymore.
// TODO: Move the mouse grap/drag mode from Toplevel to Border.
Application.OnMouseEvent (new () { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed });
Assert.Equal (w.Border, Application.MouseGrabView);
Assert.Equal (new Point (0,0), w.Frame.Location);
// Move down and to the right.
Application.OnMouseEvent (new () { X = 1, Y = 1, Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition });
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
_output
);
attributes = new []
{
// 0
new (ColorName.White, ColorName.Black),
// 1
Colors.ColorSchemes ["Base"].Normal
};
TestHelpers.AssertDriverAttributesAre (
@"
0000000000
0111110000
0111110000
0111110000
0111110000
0111110000
",
null,
attributes
);
Assert.Equal (new Point (1, 1), w.Frame.Location);
Application.End (rs);
w.Dispose ();

View File

@@ -909,40 +909,8 @@ public class OverlappedTests
Assert.Equal (win2, Application.Current);
Assert.Equal (win1, rsWin1.Toplevel);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
_output
);
Attribute [] attributes =
{
// 0
Colors.ColorSchemes ["TopLevel"].Normal,
// 1
Colors.ColorSchemes ["Base"].Normal
};
TestHelpers.AssertDriverAttributesAre (
@"
0000000000
0111110000
0111110000
0111110000
0111110000
0111110000
0000000000
0000000000
0000000000
0000000000",
null,
attributes
);
// Tests that rely on visuals are too fragile. If border style changes they break.
// Instead we should just rely on the test above.
Application.OnMouseEvent (new MouseEvent { X = 1, Y = 1, Flags = MouseFlags.Button1Pressed });
Assert.Equal (win2.Border, Application.MouseGrabView);
@@ -973,31 +941,8 @@ public class OverlappedTests
Assert.Equal (win2, Application.Current);
Assert.Equal (win1, rsWin1.Toplevel);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
_output
);
TestHelpers.AssertDriverAttributesAre (
@"
0000000000
0000000000
0011111000
0011111000
0011111000
0011111000
0011111000
0000000000
0000000000
0000000000",
null,
attributes
);
// Tests that rely on visuals are too fragile. If border style changes they break.
// Instead we should just rely on the test above.
// This will end the win2 and not the overlapped
Application.End (rsOverlapped);

View File

@@ -875,18 +875,7 @@ public class ToplevelTests
}
else if (iterations == 1)
{
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌─────────────┐
│ │
│ ┌────────┐ │
│ │Hello │ │
│ └────────┘ │
│ │
└─────────────┘
",
_output
);
Assert.Equal(new Point(2,2), Application.Current.Frame.Location);
}
else if (iterations == 2)
{
@@ -918,18 +907,7 @@ public class ToplevelTests
else if (iterations == 4)
{
Assert.Equal (Application.Current.Border, Application.MouseGrabView);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌─────────────┐
│ │
│┌────────┐ │
││Hello │ │
│└────────┘ │
│ │
└─────────────┘",
_output
);
Assert.Equal (new Point (1, 2), Application.Current.Frame.Location);
Assert.Equal (Application.Current.Border, Application.MouseGrabView);
}
@@ -953,18 +931,8 @@ public class ToplevelTests
else if (iterations == 6)
{
Assert.Equal (Application.Current.Border, Application.MouseGrabView);
Assert.Equal (new Point (1, 1), Application.Current.Frame.Location);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌─────────────┐
│┌────────┐ │
││Hello │ │
│└────────┘ │
│ │
│ │
└─────────────┘",
_output
);
Assert.Equal (Application.Current.Border, Application.MouseGrabView);
Assert.Equal (new Rectangle (1, 1, 10, 3), Application.Current.Frame);
@@ -1374,26 +1342,6 @@ public class ToplevelTests
Assert.Equal (new (0, 0, 200, 100), scrollView.Subviews [0].Frame);
Assert.Equal (new (3, 3, 194, 94), win.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌───────────────────────────────────┴
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ▼
◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ",
_output
);
Application.OnMouseEvent (new MouseEvent { X = 6, Y = 6, Flags = MouseFlags.Button1Pressed });
Assert.Equal (win.Border, Application.MouseGrabView);
@@ -1406,27 +1354,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (6, 6, 191, 91), win.Frame);
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌────────────────────────────────░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ▼
◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ",
_output
);
Application.OnMouseEvent (new MouseEvent
{
X = 5,
@@ -1440,27 +1367,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (2, 2, 195, 95), win.Frame);
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌────────────────────────────────────│
│ ┴
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ░
│ ▼
◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ",
_output
);
Application.OnMouseEvent (new MouseEvent { X = 5, Y = 5, Flags = MouseFlags.Button1Released });
// ScrollView always grab the mouse when the container's subview OnMouseEnter don't want grab the mouse
Assert.Equal (scrollView, Application.MouseGrabView);
@@ -1482,15 +1388,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌──────────────────┐
│ │
└──────────────────┘
",
_output
);
Assert.Null (Application.MouseGrabView);
Application.OnMouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed });
@@ -1509,15 +1406,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌──────────────────┐
│ │
└──────────────────┘
",
_output
);
// Changes Top size to same size as Dialog more menu and scroll bar
((FakeDriver)Application.Driver).SetBufferSize (20, 3);
@@ -1533,15 +1421,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 20, 3), top.Frame);
Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌──────────────────┐
│ │
└──────────────────┘
",
_output
);
// Changes Top size smaller than Dialog size
((FakeDriver)Application.Driver).SetBufferSize (19, 2);
@@ -1557,14 +1436,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 19, 2), top.Frame);
Assert.Equal (new Rectangle (-1, 0, 20, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
──────────────────┐
",
_output
);
Application.OnMouseEvent (new MouseEvent
{
X = 18,
@@ -1577,12 +1448,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 19, 2), top.Frame);
Assert.Equal (new Rectangle (18, 1, 20, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌",
_output
);
// On a real app we can't go beyond the SuperView bounds
Application.OnMouseEvent (new MouseEvent
{
@@ -1627,14 +1492,6 @@ public class ToplevelTests
Assert.Null (Application.MouseGrabView);
Assert.Equal (new Rectangle (0, 0, 10, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌────────┐
│ Test │
└────────┘",
_output
);
Application.OnMouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed });
var firstIteration = false;
@@ -1643,14 +1500,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 10, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌────────┐
│ Test │
└────────┘",
_output
);
Application.OnMouseEvent (new MouseEvent
{
X = 1,
@@ -1664,14 +1513,6 @@ public class ToplevelTests
Assert.Equal (window.Border, Application.MouseGrabView);
Assert.Equal (new Rectangle (1, 1, 10, 3), window.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌────────┐
│ Test │
└────────┘",
_output
);
Application.End (rs);
}
@@ -1706,31 +1547,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (0, 0, 20, 20), win.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@"
┌──────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────┘",
_output
);
var btnPopup = new Button { Text = "Popup" };
var testWindow = new Window { X = 2, Y = 1, Width = 15, Height = 10 };
testWindow.Add (btnPopup);
@@ -1774,31 +1590,6 @@ public class ToplevelTests
Assert.Equal (new Rectangle (2, 1, 15, 10), testWindow.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (
@$"
┌──────────────────┐
│ ┌─────────────┐ │
│ │{CM.Glyphs.LeftBracket} Popup {CM.Glyphs.RightBracket} │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ └─────────────┘ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────┘",
_output
);
Application.OnMouseEvent (new () { X = 5, Y = 2, Flags = MouseFlags.Button1Clicked });
Application.Top.Draw ();