Skip to content

Commit

Permalink
TabView keyboarding improvements (#1151)
Browse files Browse the repository at this point in the history
* TabView keyboard/gamepad fixes

* Fix TabView tests down-level

* Enable Middle Click to close tab

* CR feedback
  • Loading branch information
kmahone authored Aug 12, 2019
1 parent b63b502 commit 4017872
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 45 deletions.
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);
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

0 comments on commit 4017872

Please sign in to comment.