Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabView keyboarding improvements #1151

Merged
merged 4 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 100 additions & 15 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public void CloseSelectionTest()
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");

Log.Comment("When the selected tab is closed, selection should move to the next one.");
// Use Tab's close button:
closeButton.InvokeAndWait();
VerifyElement.NotFound("FirstTab", FindBy.Name);
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");

Log.Comment("Select last tab.");
Expand All @@ -140,9 +142,11 @@ public void CloseSelectionTest()
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "3");

Log.Comment("When the selected tab is last and is closed, selection should move to the previous item.");
closeButton = FindCloseButton(lastTab);
Verify.IsNotNull(closeButton);
closeButton.InvokeAndWait();

// Use Middle Click to close the tab:
lastTab.Click(PointerButtons.Middle);
kmahone marked this conversation as resolved.
Show resolved Hide resolved
Wait.ForIdle();
VerifyElement.NotFound("LastTab", FindBy.Name);
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "2");
}
}
Expand Down Expand Up @@ -264,27 +268,108 @@ public void AddButtonTest()
[TestMethod]
public void KeyboardTest()
{
if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone3))
{
Log.Warning("This test requires RS3+ functionality (specifically, KeyboardAccelerators)");
return;
}

using (var setup = new TestSetupHelper("TabView Tests"))
{
Log.Comment("Set focus inside the TabView");
UIObject tabContent = FindElement.ByName("FirstTabContent");
tabContent.SetFocus();

TabItem firstTab = FindElement.ByName<TabItem>("FirstTab");
TabItem secondTab = FindElement.ByName<TabItem>("SecondTab");
TabItem lastTab = FindElement.ByName<TabItem>("LastTab");

Button addButton = FindElement.ById<Button>("AddButton");

Verify.IsTrue(firstTab.IsSelected, "First Tab should be selected initially");
Button firstTabButton = FindElement.ByName<Button>("FirstTabButton");
Verify.IsTrue(firstTabButton.HasKeyboardFocus, "Focus should start in the First Tab");

// Ctrl+Tab to the second tab:
KeyboardHelper.PressKey(Key.Tab, ModifierKey.Control);
Verify.IsTrue(secondTab.IsSelected, "Ctrl+Tab should move selection to Second Tab");
Button secondTabButton = FindElement.ByName<Button>("SecondTabButton");
Verify.IsTrue(secondTabButton.HasKeyboardFocus, "Focus should move to the content of the Second Tab");

// Ctrl+Shift+Tab to the first tab:
KeyboardHelper.PressKey(Key.Tab, ModifierKey.Control | ModifierKey.Shift);
Verify.IsTrue(firstTab.IsSelected, "Ctrl+Shift+Tab should move selection to First Tab");
Verify.IsTrue(firstTabButton.HasKeyboardFocus, "Focus should move to the content of the First Tab");

// Ctrl+Shift+Tab to the last tab:
KeyboardHelper.PressKey(Key.Tab, ModifierKey.Control | ModifierKey.Shift);
Verify.IsTrue(lastTab.IsSelected, "Ctrl+Shift+Tab should move selection to Last Tab");
Verify.IsTrue(lastTab.HasKeyboardFocus, "Focus should move to the last tab (since it has no focusable content)");

// Ctrl+Tab to the first tab:
KeyboardHelper.PressKey(Key.Tab, ModifierKey.Control);
Verify.IsTrue(firstTab.IsSelected, "Ctrl+Tab should move selection to First Tab");
Verify.IsTrue(firstTab.HasKeyboardFocus, "Focus should move to the first tab");

KeyboardHelper.PressKey(Key.Up);
Verify.IsTrue(firstTab.HasKeyboardFocus, "Up key should not move focus");

KeyboardHelper.PressKey(Key.Down);
Verify.IsTrue(firstTab.HasKeyboardFocus, "Down key should not move focus");

KeyboardHelper.PressKey(Key.Right);
Verify.IsTrue(secondTab.HasKeyboardFocus, "Right Key should move focus to the second tab");

KeyboardHelper.PressKey(Key.Left);
Verify.IsTrue(firstTab.HasKeyboardFocus, "Left Key should move focus to the first tab");

addButton.SetFocus();
Verify.IsTrue(addButton.HasKeyboardFocus, "AddButton should have keyboard focus");

KeyboardHelper.PressKey(Key.Left);
Verify.IsTrue(lastTab.HasKeyboardFocus, "Left Key from AddButton should move focus to last tab");

KeyboardHelper.PressKey(Key.Right);
Verify.IsTrue(addButton.HasKeyboardFocus, "Right Key from Last Tab should move focus to Add Button");

firstTab.SetFocus();

// Ctrl+f4 to close the tab:
Log.Comment("Verify that pressing ctrl-f4 closes the tab");
KeyboardHelper.PressDownModifierKey(ModifierKey.Control);
TextInput.SendText("{F4}");
KeyboardHelper.ReleaseModifierKey(ModifierKey.Control);
KeyboardHelper.PressKey(Key.F4, ModifierKey.Control);
Wait.ForIdle();

ElementCache.Refresh();
UIObject firstTab = TryFindElement.ByName("FirstTab");
Verify.IsNull(firstTab);
VerifyElement.NotFound("FirstTab", FindBy.Name);
}
}

[TestMethod]
public void GamePadTest()
{
using (var setup = new TestSetupHelper("TabView Tests"))
{
Button tabContent = FindElement.ByName<Button>("FirstTabButton");
Button backButton = FindElement.ById<Button>("__BackButton");
TabItem firstTab = FindElement.ByName<TabItem>("FirstTab");
TabItem secondTab = FindElement.ByName<TabItem>("SecondTab");
TabItem lastTab = FindElement.ByName<TabItem>("LastTab");
Button addButton = FindElement.ById<Button>("AddButton");

firstTab.SetFocus();

GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickRight);
Wait.ForIdle();
Verify.IsTrue(secondTab.HasKeyboardFocus, "GamePad Right should move focus to second tab");

GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickLeft);
Wait.ForIdle();
Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Left should move focus to first tab");

GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickDown);
Wait.ForIdle();
Verify.IsTrue(tabContent.HasKeyboardFocus, "GamePad Down should move focus to tab content");

GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
Wait.ForIdle();
Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Up should move focus to tabs");

GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
Wait.ForIdle();
Verify.IsTrue(backButton.HasKeyboardFocus, "GamePad Up should move to back button");
}
}

Expand Down
Loading