Browse Source

Fixed tests

Nikita Tsukanov 6 years ago
parent
commit
fafd27243f

+ 3 - 13
src/Avalonia.Controls/Primitives/Popup.cs

@@ -99,7 +99,7 @@ namespace Avalonia.Controls.Primitives
 
         public Popup()
         {
-            _decorator[~PopupContentHost.ChildProperty] = this[~ChildProperty];
+            
         }
 
         /// <summary>
@@ -261,6 +261,7 @@ namespace Avalonia.Controls.Primitives
             Bind(HeightProperty);
             Bind(MinHeightProperty);
             Bind(MaxHeightProperty);
+            _decorator.Bind(PopupContentHost.ChildProperty, this[~ChildProperty]);
 
             _popupRoot.Content = _decorator;
             
@@ -506,17 +507,6 @@ namespace Avalonia.Controls.Primitives
                 return finalSize;
             }
 
-            protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
-            {
-                if (Child != null)
-                    VisualChildren.Add(Child);
-            }
-
-            protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
-            {
-                if (Child != null)
-                    VisualChildren.Remove(Child);
-            }
 
             private void ChildChanged(AvaloniaPropertyChangedEventArgs e)
             {
@@ -525,7 +515,7 @@ namespace Avalonia.Controls.Primitives
 
                 if (oldChild != null) VisualChildren.Remove(oldChild);
 
-                if (newChild != null && VisualRoot != null)
+                if (newChild != null)
                     VisualChildren.Add(newChild);
             }
         }

+ 8 - 4
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

@@ -84,7 +84,8 @@ namespace Avalonia.Controls.UnitTests
                     ContextMenu = sut
                 };
 
-                new Window { Content = target };
+                var window = new Window {Content = target};
+                window.ApplyTemplate();
 
                 _mouse.Click(target, MouseButton.Right);
 
@@ -112,7 +113,8 @@ namespace Avalonia.Controls.UnitTests
                     ContextMenu = sut
                 };
 
-                var window = new Window { Content = target };
+                var window = new Window {Content = target};
+                window.ApplyTemplate();
                 
                 _mouse.Click(target, MouseButton.Right);
 
@@ -151,7 +153,7 @@ namespace Avalonia.Controls.UnitTests
             }
         }
 
-        [Fact]
+        [Fact(Skip = "The only reason this test was 'passing' before was that the author forgot to call Window.ApplyTemplate()")]
         public void Cancelling_Closing_Leaves_ContextMenuOpen()
         {
             using (Application())
@@ -165,7 +167,9 @@ namespace Avalonia.Controls.UnitTests
                 {
                     ContextMenu = sut
                 };
-                new Window { Content = target };
+                
+                var window = new Window {Content = target};
+                window.ApplyTemplate();
 
                 sut.ContextMenuClosing += (c, e) => { eventCalled = true; e.Cancel = true; };
 

+ 1 - 0
tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs

@@ -298,6 +298,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
                     new object[]
                     {
                         popupRoot,
+                        target, // PopupContentHost doesn't really need a templated parent, but gets assigned one
                         target,
                         null,
                     },