Browse Source

Add tests

Max Katz 3 years ago
parent
commit
bc6d5ec87d

+ 21 - 0
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

@@ -446,6 +446,27 @@ namespace Avalonia.Controls.UnitTests
             }
         }
 
+        [Fact]
+        public void Should_Reset_Popup_Parent_On_Target_Detached()
+        {
+            using (Application())
+            {
+                var userControl = new UserControl();
+                var window = PreparedWindow(userControl);
+                window.Show();
+                
+                var menu = new ContextMenu();
+                userControl.ContextMenu = menu;
+                menu.Open();
+                
+                var popup = Assert.IsType<Popup>(menu.Parent);
+                Assert.NotNull(popup.Parent);
+                
+                window.Content = null;
+                Assert.Null(popup.Parent);
+            }
+        }
+
         [Fact]
         public void Context_Menu_In_Resources_Can_Be_Shared()
         {

+ 25 - 0
tests/Avalonia.Controls.UnitTests/FlyoutTests.cs

@@ -432,6 +432,26 @@ namespace Avalonia.Controls.UnitTests
             }
         }
 
+        [Fact]
+        public void Should_Reset_Popup_Parent_On_Target_Detached()
+        {
+            using (CreateServicesWithFocus())
+            {
+                var userControl = new UserControl();
+                var window = PreparedWindow(userControl);
+                window.Show();
+                
+                var flyout = new TestFlyout();
+                flyout.ShowAt(userControl);
+                
+                var popup = Assert.IsType<Popup>(flyout.Popup);
+                Assert.NotNull(popup.Parent);
+                
+                window.Content = null;
+                Assert.Null(popup.Parent);
+            }
+        }
+
         [Fact]
         public void ContextFlyout_Can_Be_Set_In_Styles()
         {
@@ -549,5 +569,10 @@ namespace Avalonia.Controls.UnitTests
                 new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed),
                 KeyModifiers.None);
         }
+        
+        public class TestFlyout : Flyout
+        {
+            public new Popup Popup => base.Popup;
+        }
     }
 }