Browse Source

Added a couple of TabIndex tests.

pull/5996/head
Steven Kirk 5 years ago
parent
commit
91ef212434
  1. 93
      tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs

93
tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs

@ -1,3 +1,4 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Xunit;
@ -1132,5 +1133,97 @@ namespace Avalonia.Input.UnitTests
Assert.Null(result);
}
[Fact]
public void Respects_TabIndex_Moving_Forwards()
{
Button start;
var top = new StackPanel
{
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
Children =
{
new StackPanel
{
Children =
{
new Button { Name = "Button1", TabIndex = 5 },
(start = new Button { Name = "Button2", TabIndex = 2 }),
new Button { Name = "Button3", TabIndex = 1 },
}
},
new StackPanel
{
Children =
{
new Button { Name = "Button4", TabIndex = 3 },
new Button { Name = "Button5", TabIndex = 6 },
new Button { Name = "Button6", TabIndex = 4 },
}
},
}
};
var result = new List<string>();
var current = (IInputElement)start;
do
{
result.Add(((IControl)current).Name);
current = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
} while (current is object && current != start);
Assert.Equal(new[]
{
"Button2", "Button4", "Button6", "Button1", "Button5", "Button3"
}, result);
}
[Fact]
public void Respects_TabIndex_Moving_Backwards()
{
Button start;
var top = new StackPanel
{
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
Children =
{
new StackPanel
{
Children =
{
new Button { Name = "Button1", TabIndex = 5 },
(start = new Button { Name = "Button2", TabIndex = 2 }),
new Button { Name = "Button3", TabIndex = 1 },
}
},
new StackPanel
{
Children =
{
new Button { Name = "Button4", TabIndex = 3 },
new Button { Name = "Button5", TabIndex = 6 },
new Button { Name = "Button6", TabIndex = 4 },
}
},
}
};
var result = new List<string>();
var current = (IInputElement)start;
do
{
result.Add(((IControl)current).Name);
current = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
} while (current is object && current != start);
Assert.Equal(new[]
{
"Button2", "Button3", "Button5", "Button1", "Button6", "Button4"
}, result);
}
}
}

Loading…
Cancel
Save