Skip to content

Commit

Permalink
Fix issue with invoke pattern being provided for top navview item (#2819
Browse files Browse the repository at this point in the history
)

* Fix issue with invoke pattern being provided for top navview item

* Add test

* Fix failing tests

* Remove invoke pattern completely

* Fix tests using invoke instead of click
  • Loading branch information
marcelwgn authored Jul 21, 2020
1 parent 725166e commit 67fb89b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions dev/NavigationView/NavigationViewItemAutomationPeer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -47,7 +47,6 @@ winrt::hstring NavigationViewItemAutomationPeer::GetNameCore()
winrt::IInspectable NavigationViewItemAutomationPeer::GetPatternCore(winrt::PatternInterface const& pattern)
{
if (pattern == winrt::PatternInterface::SelectionItem ||
pattern == winrt::PatternInterface::Invoke ||
// Only provide expand collapse pattern if we have children!
(pattern == winrt::PatternInterface::ExpandCollapse && HasChildren()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,15 @@ public void VerifyNavigationItemUIAType()
Verify.AreEqual(
AutomationControlType.ListItem,
NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetAutomationControlType());
Verify.IsNull(NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetPattern(PatternInterface.Invoke));

navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top;
Content.UpdateLayout();
Verify.AreEqual(
AutomationControlType.TabItem,
NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetAutomationControlType());

// Tabs should only provide SelectionItem pattern but not Invoke pattern
Verify.IsNull(NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetPattern(PatternInterface.Invoke));
});
}

Expand Down
15 changes: 6 additions & 9 deletions dev/NavigationView/NavigationView_InteractionTests/EventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void MenuItemInvokedTest()
}

[TestMethod]
public void SettingsItemInvokeTest()
public void SettingsItemClickTest()
{
var testScenarios = RegressionTestScenario.BuildAllRegressionTestScenarios();
foreach (var testScenario in testScenarios)
Expand All @@ -281,11 +281,8 @@ public void SettingsItemInvokeTest()
settingsItem.SetFocus();
Wait.ForIdle();

AutomationElement ae = AutomationElement.FocusedElement;
InvokePattern invokePattern = ae.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;

Log.Comment("Invoking settings");
invokePattern.Invoke();
Log.Comment("Click settings");
settingsItem.Click();
Wait.ForIdle();

Log.Comment("Verify settings is selected");
Expand All @@ -305,20 +302,20 @@ public void VerifyNavigationViewItemResponseToClickAfterBeingMovedBetweenFrames(
var result = new TextBlock(FindElement.ByName("MyLocationResult"));

Log.Comment("Click on MyLocation Item and verify it's on Frame1");
myLocationButton.Invoke();
myLocationButton.Click();
Wait.ForIdle();
Verify.AreEqual(result.GetText(), "Frame1");

Log.Comment("Click on SwitchFrame");
switchFrameButton.Invoke();
switchFrameButton.Click();
Wait.ForIdle();

// tree structure changed and rebuild the cache.
ElementCache.Clear();

Log.Comment("Click on MyLocation Item and verify it's on Frame2");
myLocationButton = FindElement.ByName<Button>("MyLocation");
myLocationButton.Invoke();
myLocationButton.Click();
Wait.ForIdle();
Verify.AreEqual(result.GetText(), "Frame2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void EnsureTopSettingsRetainsFocusAfterOrientationChanges()
var SettingsSelectionStateTextBlock = new TextBlock(FindElement.ByName("SettingsSelectedState"));

var leftSettingsItem = new Button(FindElement.ByName("Settings"));
leftSettingsItem.Invoke();
leftSettingsItem.Click();

Log.Comment("Verify the left settings item is selected.");
readSettingsSelectedButton.Invoke();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void EnsureLeftSettingsRetainsFocusAfterOrientationChanges()
Wait.ForIdle();

var topSettingsItem = new Button(FindElement.ByName("SettingsTopNavPaneItem"));
topSettingsItem.Invoke();
topSettingsItem.Click();

Log.Comment("Verify the top settings item is selected.");
readSettingsSelectedButton.Invoke();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected void OpenOverflowMenuAndInvokeItem(string itemName)

var itemToBeClicked = items.ElementAt(0);
Log.Comment("Invoke the item " + UIObjectToString(itemToBeClicked));
new Button(itemToBeClicked).Invoke();
new Button(itemToBeClicked).Click();
Wait.ForIdle();
//When a overflow item is clicked, NavView depends on another UI ticket to update the layout.
Wait.ForSeconds(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void PaneOpenCloseTestPartTwo() // Otherwise this test will exceed the 30

Log.Comment("Invoke Music item to close the pane");
var music = new Button(FindElement.ByName("Music"));
music.Invoke();
music.Click();
Wait.ForIdle();

Verify.AreEqual(ToggleState.Off, isPaneOpenCheckBox.ToggleState, "IsPaneOpen expected to be False after invoking Music item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void SettingsCanBeUnselected()
var SettingsSelectionStateTextBlock = new TextBlock(FindElement.ByName("SettingsSelectedState"));

var settings = new Button(FindElement.ByName("Settings"));
settings.Invoke();
settings.Click();
Wait.ForIdle();

Log.Comment("Verify the top settings item is selected.");
Expand Down Expand Up @@ -373,13 +373,13 @@ public void VerifyNoCrashWhenSelectedItemIsInvalidItem()
// Select apps
using (var waiter = new ValueChangedEventWaiter(invokeResult))
{
apps.Invoke();
apps.Click();
waiter.Wait();
}

Verify.AreEqual(selectResult.Value, "Apps");

setInvalidSelectedItemButton.Invoke();
setInvalidSelectedItemButton.Click();
Wait.ForIdle();

Verify.AreEqual(selectResult.Value, "Null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void TopNavigationOverflowWidthLongNavItemTest()

Log.Comment("Add a long navigationview item which text includes " + longNavItemPartialContent);
Button button = new Button(FindElement.ByName("AddLongNavItem"));
button.Invoke();
button.Click();
Wait.ForIdle();

var count = GetTopNavigationItems(TopNavPosition.Primary).Count;
Expand Down

0 comments on commit 67fb89b

Please sign in to comment.