|
|
@@ -6,7 +6,6 @@ using Avalonia.Markup.Xaml;
|
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.Rendering;
|
|
|
using Avalonia.UnitTests;
|
|
|
-using Avalonia.VisualTree;
|
|
|
|
|
|
using Moq;
|
|
|
using Xunit;
|
|
|
@@ -18,6 +17,107 @@ namespace Avalonia.Controls.UnitTests
|
|
|
private Mock<IPopupImpl> popupImpl;
|
|
|
private MouseTestHelper _mouse = new MouseTestHelper();
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public void ContextRequested_Opens_ContextMenu()
|
|
|
+ {
|
|
|
+ using (Application())
|
|
|
+ {
|
|
|
+ var sut = new ContextMenu();
|
|
|
+ var target = new Panel
|
|
|
+ {
|
|
|
+ ContextMenu = sut
|
|
|
+ };
|
|
|
+
|
|
|
+ var window = new Window { Content = target };
|
|
|
+ window.ApplyTemplate();
|
|
|
+ window.Presenter.ApplyTemplate();
|
|
|
+
|
|
|
+ int openedCount = 0;
|
|
|
+
|
|
|
+ sut.MenuOpened += (sender, args) =>
|
|
|
+ {
|
|
|
+ openedCount++;
|
|
|
+ };
|
|
|
+
|
|
|
+ target.RaiseEvent(new ContextRequestedEventArgs());
|
|
|
+
|
|
|
+ Assert.True(sut.IsOpen);
|
|
|
+ Assert.Equal(1, openedCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void ContextMenu_Is_Opened_When_ContextFlyout_Is_Also_Set()
|
|
|
+ {
|
|
|
+ // We have this test for backwards compatability with the code that already sets custom ContextMenu.
|
|
|
+ using (Application())
|
|
|
+ {
|
|
|
+ var sut = new ContextMenu();
|
|
|
+ var flyout = new Flyout();
|
|
|
+ var target = new Panel
|
|
|
+ {
|
|
|
+ ContextMenu = sut,
|
|
|
+ ContextFlyout = flyout
|
|
|
+ };
|
|
|
+
|
|
|
+ var window = new Window { Content = target };
|
|
|
+ window.ApplyTemplate();
|
|
|
+ window.Presenter.ApplyTemplate();
|
|
|
+
|
|
|
+ target.RaiseEvent(new ContextRequestedEventArgs());
|
|
|
+
|
|
|
+ Assert.True(sut.IsOpen);
|
|
|
+ Assert.False(flyout.IsOpen);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void KeyUp_Raised_On_Target_Opens_ContextFlyout()
|
|
|
+ {
|
|
|
+ using (Application())
|
|
|
+ {
|
|
|
+ var sut = new ContextMenu();
|
|
|
+ var target = new Panel
|
|
|
+ {
|
|
|
+ ContextMenu = sut
|
|
|
+ };
|
|
|
+ var contextRequestedCount = 0;
|
|
|
+ target.AddHandler(Control.ContextRequestedEvent, (s, a) => contextRequestedCount++, Interactivity.RoutingStrategies.Tunnel);
|
|
|
+
|
|
|
+ var window = PreparedWindow(target);
|
|
|
+ window.Show();
|
|
|
+
|
|
|
+ target.RaiseEvent(new KeyEventArgs { RoutedEvent = InputElement.KeyUpEvent, Key = Key.Apps, Source = window });
|
|
|
+
|
|
|
+ Assert.True(sut.IsOpen);
|
|
|
+ Assert.Equal(1, contextRequestedCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void KeyUp_Raised_On_Flyout_Closes_Opened_ContextMenu()
|
|
|
+ {
|
|
|
+ using (Application())
|
|
|
+ {
|
|
|
+ var sut = new ContextMenu();
|
|
|
+ var target = new Panel
|
|
|
+ {
|
|
|
+ ContextMenu = sut
|
|
|
+ };
|
|
|
+
|
|
|
+ var window = PreparedWindow(target);
|
|
|
+ window.Show();
|
|
|
+
|
|
|
+ target.RaiseEvent(new ContextRequestedEventArgs());
|
|
|
+
|
|
|
+ Assert.True(sut.IsOpen);
|
|
|
+
|
|
|
+ sut.RaiseEvent(new KeyEventArgs { RoutedEvent = InputElement.KeyUpEvent, Key = Key.Apps, Source = window });
|
|
|
+
|
|
|
+ Assert.False(sut.IsOpen);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void Opening_Raises_Single_Opened_Event()
|
|
|
{
|
|
|
@@ -225,8 +325,7 @@ namespace Avalonia.Controls.UnitTests
|
|
|
};
|
|
|
|
|
|
var window = PreparedWindow(target);
|
|
|
- window.ApplyTemplate();
|
|
|
- window.Presenter.ApplyTemplate();
|
|
|
+ window.Show();
|
|
|
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
|
|
|
|
|
_mouse.Click(target, MouseButton.Right);
|
|
|
@@ -257,8 +356,8 @@ namespace Avalonia.Controls.UnitTests
|
|
|
};
|
|
|
|
|
|
var window = PreparedWindow(target);
|
|
|
- window.ApplyTemplate();
|
|
|
- window.Presenter.ApplyTemplate();
|
|
|
+ window.Show();
|
|
|
+
|
|
|
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
|
|
|
|
|
_mouse.Click(target, MouseButton.Right);
|
|
|
@@ -475,6 +574,7 @@ namespace Avalonia.Controls.UnitTests
|
|
|
|
|
|
var w = new Window(windowImpl.Object) { Content = content };
|
|
|
w.ApplyTemplate();
|
|
|
+ w.Presenter.ApplyTemplate();
|
|
|
return w;
|
|
|
}
|
|
|
|