diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs index 599e214b31..81908b5147 100644 --- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs @@ -108,5 +108,36 @@ namespace Avalonia.Controls.UnitTests }; }); } + + [Fact] + public void Detaching_Closed_ComboBox_Keeps_Current_Focus() + { + using (UnitTestApplication.Start(TestServices.RealFocus)) + { + var target = new ComboBox + { + Items = new[] { new Canvas() }, + SelectedIndex = 0, + Template = GetTemplate(), + }; + + var other = new Control { Focusable = true }; + + StackPanel panel; + + var root = new TestRoot { Child = panel = new StackPanel { Children = { target, other } } }; + + target.ApplyTemplate(); + target.Presenter.ApplyTemplate(); + + other.Focus(); + + Assert.True(other.IsFocused); + + panel.Children.Remove(target); + + Assert.True(other.IsFocused); + } + } } } diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs index 7cb9fccee8..1f07482617 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs @@ -223,7 +223,33 @@ namespace Avalonia.Controls.UnitTests.Primitives } } - + [Fact] + public void Popup_Close_On_Closed_Popup_Should_Not_Raise_Closed_Event() + { + using (CreateServices()) + { + var window = PreparedWindow(); + var target = new Popup() { PlacementMode = PlacementMode.Pointer }; + + window.Content = target; + window.ApplyTemplate(); + + int closedCount = 0; + + target.Closed += (sender, args) => + { + closedCount++; + }; + + target.Close(); + target.Close(); + target.Close(); + target.Close(); + + Assert.Equal(0, closedCount); + } + } + [Fact] public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent() {