Explorar o código

Simplified test

Tig Kindel hai 1 ano
pai
achega
1eaf8a713d

+ 19 - 40
Terminal.Gui/View/Adornment/Adornment.cs

@@ -33,7 +33,8 @@ public class Adornment : View
     /// <summary>Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0).</summary>
     public override Rectangle Bounds
     {
-        get => new Rectangle (Point.Empty, Thickness?.GetInside (new (Point.Empty, Frame.Size)).Size ?? Frame.Size);
+        get => new (Point.Empty, Thickness?.GetInside (new (Point.Empty, Frame.Size)).Size ?? Frame.Size);
+
         // QUESTION: So why even have a setter then?
         set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness.");
     }
@@ -158,35 +159,27 @@ public class Adornment : View
     {
         ThicknessChanged?.Invoke (
                                   this,
-                                  new ThicknessEventArgs { Thickness = Thickness, PreviousThickness = previousThickness }
+                                  new() { Thickness = Thickness, PreviousThickness = previousThickness }
                                  );
     }
 
     /// <summary>Fired whenever the <see cref="Thickness"/> property changes.</summary>
     public event EventHandler<ThicknessEventArgs> ThicknessChanged;
 
-    internal override Adornment CreateAdornment (Type adornmentType)
+    /// <inheritdoc/>
+    protected internal override bool OnMouseEnter (MouseEvent mouseEvent)
     {
-        /* Do nothing - Adornments do not have Adornments */
-        return null;
-    }
+        var args = new MouseEventEventArgs (mouseEvent);
 
-    internal override void LayoutAdornments ()
-    {
-        /* Do nothing - Adornments do not have Adornments */
+        return args.Handled || base.OnMouseEnter (mouseEvent);
     }
 
     /// <inheritdoc/>
-    public override bool OnMouseEvent (MouseEvent mouseEvent)
+    protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
     {
         var args = new MouseEventEventArgs (mouseEvent);
 
-        if (MouseEvent (mouseEvent))
-        {
-            return true;
-        }
-
-        if (mouseEvent.Flags == MouseFlags.Button1Clicked)
+        if (mouseEvent.Flags.HasFlag(MouseFlags.Button1Clicked))
         {
             if (Parent.CanFocus && !Parent.HasFocus)
             {
@@ -197,39 +190,25 @@ public class Adornment : View
             return OnMouseClick (args);
         }
 
-        if (mouseEvent.Flags == MouseFlags.Button2Clicked)
-        {
-            return OnMouseClick (args);
-        }
-
-        if (mouseEvent.Flags == MouseFlags.Button3Clicked)
-        {
-            return OnMouseClick (args);
-        }
-
-        if (mouseEvent.Flags == MouseFlags.Button4Clicked)
-        {
-            return OnMouseClick (args);
-        }
-
         return false;
     }
-    
+
     /// <inheritdoc/>
-    public override bool OnMouseEnter (MouseEvent mouseEvent)
+    protected internal override bool OnMouseLeave (MouseEvent mouseEvent)
     {
         var args = new MouseEventEventArgs (mouseEvent);
 
-        
-        return args.Handled || base.OnMouseEnter (mouseEvent);
+        return args.Handled || base.OnMouseLeave (mouseEvent);
     }
 
-
-    /// <inheritdoc/>
-    public override bool OnMouseLeave (MouseEvent mouseEvent)
+    internal override Adornment CreateAdornment (Type adornmentType)
     {
-        var args = new MouseEventEventArgs (mouseEvent);
+        /* Do nothing - Adornments do not have Adornments */
+        return null;
+    }
 
-        return args.Handled || base.OnMouseLeave (mouseEvent);
+    internal override void LayoutAdornments ()
+    {
+        /* Do nothing - Adornments do not have Adornments */
     }
 }

+ 4 - 27
UnitTests/View/Layout/LayoutTests.cs

@@ -511,11 +511,11 @@ public class LayoutTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void PosCombine_DimCombine_View_With_SubViews ()
     {
         var clicked = false;
-        Toplevel top = Application.Top;
+        Toplevel top = new Toplevel() { Width = 80, Height = 25 };
         var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
         var view1 = new View { Text = "view1", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
         var win2 = new Window { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
@@ -527,23 +527,9 @@ public class LayoutTests
         win2.Add (view2);
         win1.Add (view1, win2);
         top.Add (win1);
+        top.BeginInit();
+        top.EndInit();
 
-        RunState rs = Application.Begin (top);
-
-        TestHelpers.AssertDriverContentsWithFrameAre (
-                                                      @"
-┌──────────────────┐
-│view1             │
-│                  │
-│┌────────┐        │
-││        │        │
-│└────────┘        │
-│                  │
-│                  │
-│                  │
-└──────────────────┘",
-                                                      _output
-                                                     );
         Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
         Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame);
         Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame);
@@ -552,15 +538,6 @@ public class LayoutTests
         Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame);
         var foundView = View.FindDeepestView (top, 9, 4);
         Assert.Equal (foundView, view2);
-
-        Application.OnMouseEvent (
-                                  new MouseEventEventArgs (
-                                                           new MouseEvent { X = 9, Y = 4, Flags = MouseFlags.Button1Clicked }
-                                                          )
-                                 );
-        Assert.True (clicked);
-
-        Application.End (rs);
     }
 
     [Fact]

+ 1 - 1
UnitTests/Views/OverlappedTests.cs

@@ -903,7 +903,7 @@ public class OverlappedTests
                                                            new MouseEvent { X = 1, Y = 1, Flags = MouseFlags.Button1Pressed }
                                                           )
                                  );
-        Assert.Equal (win2, Application.MouseGrabView);
+        Assert.Equal (win2.Border, Application.MouseGrabView);
 
         Application.OnMouseEvent (
                                   new MouseEventEventArgs (