Browse Source

Fixing unit tests. TableView. WIP

Tig 9 months ago
parent
commit
0e6a2bcc7d

+ 0 - 1
UnitTests/TestHelpers.cs

@@ -210,7 +210,6 @@ public class SetupFakeDriverAttribute : BeforeAfterTestAttribute
         Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
 
         base.Before (methodUnderTest);
-
     }
 }
 

+ 3 - 0
UnitTests/Views/GraphViewTests.cs

@@ -1,4 +1,5 @@
 using System.Text;
+using Terminal.Gui.ViewMouseTests;
 using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
@@ -684,6 +685,7 @@ public class MultiBarSeriesTests
         fakeXAxis.LabelPoints.Clear ();
         gv.LayoutSubviews ();
         gv.SetNeedsDraw ();
+        Application.ClipToScreen ();
         gv.Draw ();
 
         Assert.Equal (3, fakeXAxis.LabelPoints.Count);
@@ -1546,6 +1548,7 @@ public class PathAnnotationTests
             // change the text and redraw
             view.Text = "ff1234";
             mount.SetNeedsDraw ();
+            Application.ClipToScreen ();
             mount.Draw ();
 
             // should have the new text rendered

+ 3 - 0
UnitTests/Views/ProgressBarTests.cs

@@ -36,6 +36,7 @@ public class ProgressBarTests
         for (var i = 0; i <= pb.Frame.Width; i++)
         {
             pb.Fraction += 0.2F;
+            Application.ClipToScreen ();
             pb.Draw ();
 
             if (i == 0)
@@ -177,6 +178,7 @@ public class ProgressBarTests
         for (var i = 0; i < 38; i++)
         {
             pb.Pulse ();
+            Application.ClipToScreen ();
             pb.Draw ();
 
             if (i == 0)
@@ -881,6 +883,7 @@ public class ProgressBarTests
         for (var i = 0; i < 38; i++)
         {
             pb.Pulse ();
+            Application.ClipToScreen ();
             pb.Draw ();
 
             if (i == 0)

+ 8 - 8
UnitTests/Views/ScrollBarViewTests.cs

@@ -311,8 +311,8 @@ public class ScrollBarViewTests
         top.Add (label);
 
         var sbv = new ScrollBarView (label, true, false) { Size = 100 };
-        Application.Begin (top);
-        Application.LayoutAndDrawToplevels ();
+        RunState rs = Application.Begin (top);
+        Application.RunIteration (ref rs);
 
         Assert.True (sbv.Visible);
 
@@ -330,7 +330,7 @@ This is a tes▼
 
         sbv.Visible = false;
         Assert.False (sbv.Visible);
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -346,7 +346,7 @@ This is a test
 
         sbv.Visible = true;
         Assert.True (sbv.Visible);
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -362,7 +362,7 @@ This is a tes▼
 
         sbv.Visible = false;
         Assert.False (sbv.Visible);
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -561,9 +561,9 @@ This is a test
 
         var sbv = new ScrollBarView (label, true) { Size = 100 };
         sbv.OtherScrollBarView.Size = 100;
-        Application.Begin (top);
-        Application.LayoutAndDrawToplevels ();
+        RunState rs = Application.Begin (top);
 
+        Application.RunIteration (ref rs);
         Assert.Equal (100, sbv.Size);
         Assert.Equal (100, sbv.OtherScrollBarView.Size);
         Assert.True (sbv.ShowScrollIndicator);
@@ -618,7 +618,7 @@ This is a test
         Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator);
         Assert.True (sbv.Visible);
         Assert.True (sbv.OtherScrollBarView.Visible);
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

+ 21 - 21
UnitTests/Views/ScrollViewTests.cs

@@ -194,7 +194,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var bottomLabel = new Label { X = 15, Y = 15, Text = "At 15,15" };
         var top = new Toplevel ();
         top.Add (topLabel, sv, bottomLabel);
-        Application.Begin (top);
+        RunState rs = Application.Begin (top);
         Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -250,7 +250,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         sv.Add (new Window { X = 3, Y = 3, Width = 20, Height = 20 });
 
-        Application.LayoutAndDrawToplevels ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -297,7 +297,7 @@ public class ScrollViewTests (ITestOutputHelper output)
                                               );
 
         sv.ContentOffset = new (20, 20);
-        Application.LayoutAndDrawToplevels ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -412,6 +412,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         top.LayoutSubviews ();
 
+        Application.ClipToScreen ();
         top.Draw ();
 
         View contentBottomRightCorner = sv.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner);
@@ -566,8 +567,8 @@ public class ScrollViewTests (ITestOutputHelper output)
         win.Add (scrollView);
         var top = new Toplevel ();
         top.Add (win);
-        Application.Begin (top);
-        Application.LayoutAndDrawToplevels ();
+        RunState rs = Application.Begin (top);
+        Application.RunIteration(ref rs);
 
         var expected = @"
  ┌──────────────────┐
@@ -591,7 +592,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -615,7 +616,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -639,7 +640,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -663,7 +664,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -687,7 +688,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -711,7 +712,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -735,7 +736,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -758,7 +759,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.End.WithCtrl));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -782,7 +783,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         Assert.True (scrollView.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -805,7 +806,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -828,7 +829,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -851,7 +852,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.NewKeyDownEvent (Key.End));
-        top.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
  ┌──────────────────┐
@@ -897,8 +898,8 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         var top = new Toplevel ();
         top.Add (sv);
-        Application.Begin (top);
-        Application.LayoutAndDrawToplevels ();
+        RunState rs = Application.Begin (top);
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -916,8 +917,7 @@ public class ScrollViewTests (ITestOutputHelper output)
                                                      );
 
         sv.ContentOffset = new (5, 5);
-        sv.LayoutSubviews ();
-        Application.LayoutAndDrawToplevels ();
+        Application.RunIteration (ref rs);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

+ 1 - 0
UnitTests/Views/SpinnerViewTests.cs

@@ -59,6 +59,7 @@ public class SpinnerViewTests
         TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 
         view.AdvanceAnimation ();
+        Application.ClipToScreen ();
         view.Draw ();
 
         expected = "/";

+ 46 - 30
UnitTests/Views/TableViewTests.cs

@@ -419,7 +419,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         var top = new Toplevel ();
         top.Add (tableView);
-        Application.Begin (top);
+        RunState rs = Application.Begin (top);
 
         tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
 
@@ -461,9 +461,7 @@ public class TableViewTests (ITestOutputHelper output)
         // is to specify a MinAcceptableWidth for the column
         style.MaxWidth = 10;
 
-        tableView.LayoutSubviews ();
-        tableView.SetNeedsDraw ();
-        tableView.Draw ();
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -481,10 +479,8 @@ public class TableViewTests (ITestOutputHelper output)
         // RepresentationGetter and apply max length there
 
         style.RepresentationGetter = s => { return s.ToString ().Length < 15 ? s.ToString () : s.ToString ().Substring (0, 13) + "..."; };
-
-        tableView.LayoutSubviews ();
         tableView.SetNeedsDraw ();
-        tableView.Draw ();
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -509,10 +505,9 @@ public class TableViewTests (ITestOutputHelper output)
         // (Up to MaxWidth) but the renderer can accept using
         // less space down to this limit
         style.MinAcceptableWidth = 5;
-
-        tableView.LayoutSubviews ();
         tableView.SetNeedsDraw ();
-        tableView.Draw ();
+
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -529,8 +524,7 @@ public class TableViewTests (ITestOutputHelper output)
         driver.ClearContents ();
 
         tableView.Viewport = new (0, 0, 9, 5);
-        tableView.LayoutSubviews ();
-        tableView.Draw ();
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -546,8 +540,7 @@ public class TableViewTests (ITestOutputHelper output)
         // meet MinAcceptableWidth of 5.  Column width includes terminator line
         // symbol (e.g. ┤ or │)
         tableView.Viewport = new (0, 0, 10, 5);
-        tableView.LayoutSubviews ();
-        tableView.Draw ();
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -568,8 +561,7 @@ public class TableViewTests (ITestOutputHelper output)
         tableView.MaxCellWidth = 10;
         tableView.MinCellWidth = 3;
 
-        tableView.LayoutSubviews ();
-        tableView.Draw ();
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -583,10 +575,9 @@ public class TableViewTests (ITestOutputHelper output)
         // MaxCellWidth limits MinCellWidth
         tableView.MaxCellWidth = 5;
         tableView.MinCellWidth = 10;
-
-        tableView.LayoutSubviews ();
         tableView.SetNeedsDraw ();
-        tableView.Draw ();
+
+        Application.RunIteration (ref rs);
 
         expected =
             @"
@@ -732,6 +723,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // since A is now pushed off screen we get indicator showing
         // that user can scroll left to see first column
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         expected =
@@ -746,6 +738,7 @@ public class TableViewTests (ITestOutputHelper output)
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
 
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         expected =
@@ -804,7 +797,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // Scroll right
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
-
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         // Note that with SmoothHorizontalScrolling only a single new column
@@ -852,7 +845,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // select last visible column
         tableView.SelectedColumn = 2; // column C
-
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         var expected =
@@ -864,7 +857,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // Scroll right
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
-
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         // notice that without smooth scrolling we just update the first column
@@ -1070,12 +1063,12 @@ public class TableViewTests (ITestOutputHelper output)
 
         var top = new Toplevel ();
         top.Add (tv);
-        Application.Begin (top);
+        RunState rs = Application.Begin (top);
 
         tv.HasFocus = focused;
         Assert.Equal (focused, tv.HasFocus);
 
-        tv.Draw ();
+        Application.RunIteration (ref rs);
 
         var expected = @"
 ┌─┬─┐
@@ -1108,7 +1101,8 @@ public class TableViewTests (ITestOutputHelper output)
         dt.Rows [0] [1] = 5;
 
         tv.SetNeedsDraw ();
-        tv.Draw ();
+        Application.RunIteration (ref rs);
+
 
         expected = @"
 ┌─┬─┐
@@ -1166,7 +1160,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         var top = new Toplevel ();
         top.Add (tv);
-        Application.Begin (top);
+        RunState rs = Application.Begin (top);
 
         tv.HasFocus = focused;
         Assert.Equal (focused, tv.HasFocus);
@@ -1203,7 +1197,7 @@ public class TableViewTests (ITestOutputHelper output)
         dt.Rows [0] [1] = 5;
 
         tv.SetNeedsDraw ();
-        tv.Draw ();
+        Application.RunIteration (ref rs);
 
         expected = @"
 ┌─┬─┐
@@ -1986,6 +1980,7 @@ public class TableViewTests (ITestOutputHelper output)
 ◄─┼─┼─┤
 │2│3│4│";
         tableView.SetNeedsDraw ();
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         TestHelpers.AssertDriverContentsAre (expected, output);
@@ -1999,6 +1994,7 @@ public class TableViewTests (ITestOutputHelper output)
 ├─┼─┼─┤
 │2│3│4│";
         tableView.SetNeedsDraw ();
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         TestHelpers.AssertDriverContentsAre (expected, output);
@@ -2014,6 +2010,7 @@ public class TableViewTests (ITestOutputHelper output)
         tableView.Style.ShowHorizontalHeaderUnderline = true;
         tableView.LayoutSubviews ();
         tableView.SetNeedsDraw ();
+        Application.ClipToScreen ();
         tableView.Draw ();
 
         // normally we should have scroll indicators because DEF are of screen
@@ -2036,6 +2033,7 @@ public class TableViewTests (ITestOutputHelper output)
 ├─┼─┼─┤
 │1│2│3│";
         tableView.SetNeedsDraw ();
+        Application.ClipToScreen ();
         tableView.Draw ();
         TestHelpers.AssertDriverContentsAre (expected, output);
     }
@@ -2574,7 +2572,9 @@ A B C
     [SetupFakeDriver]
     public void TestTableViewCheckboxes_ByObject ()
     {
-        Assert.Equal (ConfigurationManager.ConfigLocations.DefaultOnly, ConfigurationManager.Locations);
+        ConfigurationManager.Locations = ConfigurationManager.ConfigLocations.DefaultOnly;
+        ConfigurationManager.Reset();
+
         TableView tv = GetPetTable (out EnumerableTableSource<PickablePet> source);
         tv.LayoutSubviews ();
         IReadOnlyCollection<PickablePet> pets = source.Data;
@@ -2609,6 +2609,7 @@ A B C
 
         Assert.True (pets.First ().IsPicked);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2628,7 +2629,7 @@ A B C
         Assert.True (pets.ElementAt (0).IsPicked);
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
-
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2648,7 +2649,7 @@ A B C
         Assert.False (pets.ElementAt (0).IsPicked);
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
-
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2676,6 +2677,7 @@ A B C
         wrapper.CheckedRows.Add (0);
         wrapper.CheckedRows.Add (2);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2699,6 +2701,7 @@ A B C
         Assert.Contains (2, wrapper.CheckedRows);
         Assert.Equal (3, wrapper.CheckedRows.Count);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2714,6 +2717,7 @@ A B C
         // Untoggle the top 2
         tv.NewKeyDownEvent (Key.Space);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2742,6 +2746,7 @@ A B C
         tv.NewKeyDownEvent (Key.A.WithCtrl);
         tv.NewKeyDownEvent (Key.Space);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2761,6 +2766,7 @@ A B C
         // Untoggle all again
         tv.NewKeyDownEvent (Key.Space);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2801,6 +2807,7 @@ A B C
 
         Assert.True (pets.All (p => p.IsPicked));
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2820,6 +2827,7 @@ A B C
         Assert.Empty (pets.Where (p => p.IsPicked));
 #pragma warning restore xUnit2029
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2846,6 +2854,7 @@ A B C
         var wrapper = new CheckBoxTableSourceWrapperByIndex (tv, tv.Table);
         tv.Table = wrapper;
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2865,6 +2874,7 @@ A B C
 
         Assert.Single (wrapper.CheckedRows, 0);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2884,6 +2894,7 @@ A B C
         Assert.Contains (1, wrapper.CheckedRows);
         Assert.Equal (2, wrapper.CheckedRows.Count);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2902,6 +2913,7 @@ A B C
 
         Assert.Single (wrapper.CheckedRows, 1);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2933,6 +2945,7 @@ A B C
         wrapper.UseRadioButtons = true;
 
         tv.Table = wrapper;
+        Application.ClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2955,6 +2968,7 @@ A B C
 
         Assert.True (pets.First ().IsPicked);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2975,6 +2989,7 @@ A B C
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2995,6 +3010,7 @@ A B C
         Assert.False (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
 
+        Application.ClipToScreen ();
         tv.Draw ();
 
         expected =