test: enhance accessibility tests for form controls

This commit is contained in:
Dong Bin
2025-11-07 23:18:19 +08:00
parent e46a6edbeb
commit 3c29764af4

View File

@@ -1,8 +1,10 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Headless; using Avalonia.Headless;
using Avalonia.Headless.XUnit; using Avalonia.Headless.XUnit;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using Ursa.Controls; using Ursa.Controls;
namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests; namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests;
@@ -19,6 +21,11 @@ public class FormAccessibilityTests
Assert.False(form.NameBox.IsFocused); Assert.False(form.NameBox.IsFocused);
Assert.False(form.EmailBox.IsFocused); Assert.False(form.EmailBox.IsFocused);
var label1 = form.GetVisualDescendants().OfType<Label>().First();
Assert.Equal("_Name", label1.Content);
var position1 = label1.TranslatePoint(new Point(), window);
Assert.NotNull(position1);
window.MouseDown(position1.Value, MouseButton.Left);
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt); window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
Assert.True(form.NameBox.IsFocused); Assert.True(form.NameBox.IsFocused);
Assert.False(form.EmailBox.IsFocused); Assert.False(form.EmailBox.IsFocused);
@@ -37,6 +44,11 @@ public class FormAccessibilityTests
Assert.False(form.NameBox.IsFocused); Assert.False(form.NameBox.IsFocused);
Assert.False(form.EmailBox.IsFocused); Assert.False(form.EmailBox.IsFocused);
var label1 = form.GetVisualDescendants().OfType<Label>().First();
Assert.Equal("_Name", label1.Content);
var position1 = label1.TranslatePoint(new Point(), window);
Assert.NotNull(position1);
window.MouseDown(position1.Value, MouseButton.Left);
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt); window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
Assert.True(form.NameBox.IsFocused); Assert.True(form.NameBox.IsFocused);
Assert.False(form.EmailBox.IsFocused); Assert.False(form.EmailBox.IsFocused);
@@ -68,6 +80,11 @@ public class FormAccessibilityTests
Assert.False(text1.IsFocused); Assert.False(text1.IsFocused);
Assert.False(text2.IsFocused); Assert.False(text2.IsFocused);
var label1 = form.GetVisualDescendants().OfType<Label>().First();
Assert.Equal("_Name", label1.Content);
var position1 = label1.TranslatePoint(new Point(), window);
Assert.NotNull(position1);
window.MouseDown(position1.Value, MouseButton.Left);
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt); window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
Assert.True(text1.IsFocused); Assert.True(text1.IsFocused);
Assert.False(text2.IsFocused); Assert.False(text2.IsFocused);