Browse Source

Added tests for #8335.

pull/8405/head
Steven Kirk 4 years ago
parent
commit
4f84950c41
  1. 1
      samples/IntegrationTestApp/MainWindow.axaml
  2. 17
      samples/IntegrationTestApp/MainWindow.axaml.cs
  3. 29
      tests/Avalonia.IntegrationTests.Appium/PlatformTheoryAttribute.cs
  4. 26
      tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

1
samples/IntegrationTestApp/MainWindow.axaml

@ -112,6 +112,7 @@
<Button Name="ShowWindow">Show Window</Button>
<Button Name="SendToBack">Send to Back</Button>
<Button Name="ExitFullscreen">Exit Fullscreen</Button>
<Button Name="RestoreAll">Restore All</Button>
</StackPanel>
</TabItem>
</TabControl>

17
samples/IntegrationTestApp/MainWindow.axaml.cs

@ -82,7 +82,7 @@ namespace IntegrationTestApp
break;
}
}
private void SendToBack()
{
var lifetime = (ClassicDesktopStyleApplicationLifetime)Application.Current!.ApplicationLifetime!;
@ -92,7 +92,18 @@ namespace IntegrationTestApp
window.Activate();
}
}
private void RestoreAll()
{
var lifetime = (ClassicDesktopStyleApplicationLifetime)Application.Current!.ApplicationLifetime!;
foreach (var window in lifetime.Windows)
{
if (window.WindowState == WindowState.Minimized)
window.WindowState = WindowState.Normal;
}
}
private void MenuClicked(object? sender, RoutedEventArgs e)
{
var clickedMenuItemTextBlock = this.FindControl<TextBlock>("ClickedMenuItem");
@ -117,6 +128,8 @@ namespace IntegrationTestApp
SendToBack();
if (source?.Name == "ExitFullscreen")
WindowState = WindowState.Normal;
if (source?.Name == "RestoreAll")
RestoreAll();
}
}
}

29
tests/Avalonia.IntegrationTests.Appium/PlatformTheoryAttribute.cs

@ -0,0 +1,29 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;
namespace Avalonia.IntegrationTests.Appium
{
internal class PlatformTheoryAttribute : TheoryAttribute
{
public PlatformTheoryAttribute(TestPlatforms platforms = TestPlatforms.All) => Platforms = platforms;
public TestPlatforms Platforms { get; }
public override string? Skip
{
get => IsSupported() ? null : $"Ignored on {RuntimeInformation.OSDescription}";
set => throw new NotSupportedException();
}
private bool IsSupported()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Platforms.HasAnyFlag(TestPlatforms.Windows);
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return Platforms.HasAnyFlag(TestPlatforms.MacOS);
return false;
}
}
}

26
tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

@ -185,6 +185,32 @@ namespace Avalonia.IntegrationTests.Appium
}
}
[PlatformTheory(TestPlatforms.MacOS)]
[InlineData(ShowWindowMode.NonOwned)]
[InlineData(ShowWindowMode.Owned)]
public void Minimize_Button_Minimizes_Window(ShowWindowMode mode)
{
using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual))
{
var secondaryWindow = FindWindow(_session, "SecondaryWindow");
var (_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons();
miniaturizeButton.Click();
Thread.Sleep(1000);
var hittable = _session.FindElementsByXPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")
.Select(x => x.GetAttribute("hittable")).ToList();
Assert.Equal(new[] { "true", "false" }, hittable);
_session.FindElementByAccessibilityId("RestoreAll").Click();
Thread.Sleep(1000);
hittable = _session.FindElementsByXPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")
.Select(x => x.GetAttribute("hittable")).ToList();
Assert.Equal(new[] { "true", "true" }, hittable);
}
}
private IDisposable OpenWindow(PixelSize? size, ShowWindowMode mode, WindowStartupLocation location)
{
var sizeTextBox = _session.FindElementByAccessibilityId("ShowWindowSize");

Loading…
Cancel
Save