feat: add headless tests.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus.FocusDialog">
|
||||
<TextBox Text="Hello" u:FocusHelper.DialogFocusHint="True"></TextBox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus;
|
||||
|
||||
public partial class FocusDialog : UserControl
|
||||
{
|
||||
public FocusDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus.NormalDialog">
|
||||
<TextBox Text="Hello"></TextBox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus;
|
||||
|
||||
public partial class NormalDialog : UserControl
|
||||
{
|
||||
public NormalDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus;
|
||||
|
||||
public class Test
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public void Normal_Dialog_Focus_On_Border()
|
||||
{
|
||||
var ursaWindow = new TestWindow();
|
||||
ursaWindow.Show();
|
||||
ursaWindow.InvokeNormalDialog();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
var dialog = ursaWindow.GetVisualDescendants().OfType<DefaultDialogControl>().FirstOrDefault();
|
||||
Assert.NotNull(dialog);
|
||||
var border = dialog.GetVisualDescendants().OfType<Border>().FirstOrDefault(a=>a.Name == "PART_Border");
|
||||
var text = dialog.GetVisualDescendants().OfType<TextBox>().FirstOrDefault();
|
||||
Assert.True(border?.IsFocused);
|
||||
Assert.False(text?.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Focus_Dialog_Focus_On_Primary()
|
||||
{
|
||||
var ursaWindow = new TestWindow();
|
||||
ursaWindow.Show();
|
||||
ursaWindow.InvokeFocusDialog();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
var dialog = ursaWindow.GetVisualDescendants().OfType<DefaultDialogControl>().FirstOrDefault();
|
||||
Assert.NotNull(dialog);
|
||||
var border = dialog.GetVisualDescendants().OfType<Border>().FirstOrDefault(a=>a.Name == "PART_Border");
|
||||
var text = dialog.GetVisualDescendants().OfType<TextBox>().FirstOrDefault();
|
||||
Assert.False(border?.IsFocused);
|
||||
Assert.True(text?.IsFocused);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<u:UrsaWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus.TestWindow"
|
||||
Title="TestWindow">
|
||||
Welcome to Avalonia!
|
||||
</u:UrsaWindow>
|
||||
@@ -0,0 +1,23 @@
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.OverlayShared.Dialog_Primary_Focus;
|
||||
|
||||
public partial class TestWindow : UrsaWindow
|
||||
{
|
||||
public TestWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void InvokeNormalDialog()
|
||||
{
|
||||
OverlayDialog.ShowModal<NormalDialog, object>("Hello World",
|
||||
options: new OverlayDialogOptions { TopLevelHashCode = GetHashCode() });
|
||||
}
|
||||
|
||||
public void InvokeFocusDialog()
|
||||
{
|
||||
OverlayDialog.ShowModal<FocusDialog, object>("Hello World",
|
||||
options: new OverlayDialogOptions { TopLevelHashCode = GetHashCode() });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user