Skip to content

Commit

Permalink
TabView workaround for Issues #2455 and #2457 (#2634)
Browse files Browse the repository at this point in the history
* TabView fix for Issues #2455 & #2457

* Adding regression test for TabView fixes

* auto&& for tracker_ref getters
  • Loading branch information
RBrid authored Jun 11, 2020
1 parent f3da94f commit ac7ce43
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 57 deletions.
10 changes: 9 additions & 1 deletion dev/Generated/TabView.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void TabViewProperties::EnsureProperties()
winrt::name_of<winrt::TabView>(),
false /* isAttached */,
ValueHelper<winrt::IInspectable>::BoxedDefaultValue(),
nullptr);
winrt::PropertyChangedCallback(&OnTabItemsSourcePropertyChanged));
}
if (!s_TabItemTemplateProperty)
{
Expand Down Expand Up @@ -294,6 +294,14 @@ void TabViewProperties::OnSelectedItemPropertyChanged(
winrt::get_self<TabView>(owner)->OnSelectedItemPropertyChanged(args);
}

void TabViewProperties::OnTabItemsSourcePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
{
auto owner = sender.as<winrt::TabView>();
winrt::get_self<TabView>(owner)->OnTabItemsSourcePropertyChanged(args);
}

void TabViewProperties::OnTabWidthModePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
Expand Down
4 changes: 4 additions & 0 deletions dev/Generated/TabView.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class TabViewProperties
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnTabItemsSourcePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnTabWidthModePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);
Expand Down
68 changes: 57 additions & 11 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ public void SelectionTest()
selectItemButton.InvokeAndWait();

TextBlock selectedIndexTextBlock = FindElement.ByName<TextBlock>("SelectedIndexTextBlock");
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "1");
Verify.AreEqual("1", selectedIndexTextBlock.DocumentText);

Log.Comment("Verify that setting SelectedIndex changes selection.");
Button selectIndexButton = FindElement.ByName<Button>("SelectIndexButton");
selectIndexButton.InvokeAndWait();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "2");
Verify.AreEqual("2", selectedIndexTextBlock.DocumentText);

Log.Comment("Verify that ctrl-click on tab selects it.");
UIObject firstTab = FindElement.ByName("FirstTab");
KeyboardHelper.PressDownModifierKey(ModifierKey.Control);
firstTab.Click();
KeyboardHelper.ReleaseModifierKey(ModifierKey.Control);
Wait.ForIdle();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");
Verify.AreEqual("0", selectedIndexTextBlock.DocumentText);

Log.Comment("Verify that ctrl-click on tab does not deselect.");
KeyboardHelper.PressDownModifierKey(ModifierKey.Control);
firstTab.Click();
KeyboardHelper.ReleaseModifierKey(ModifierKey.Control);
Wait.ForIdle();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");
Verify.AreEqual("0", selectedIndexTextBlock.DocumentText);
}
}

Expand Down Expand Up @@ -238,27 +238,27 @@ public void CloseSelectionTest()
Verify.IsNotNull(closeButton);

TextBlock selectedIndexTextBlock = FindElement.ByName<TextBlock>("SelectedIndexTextBlock");
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");
Verify.AreEqual("0", selectedIndexTextBlock.DocumentText);

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");
Verify.AreEqual("0", selectedIndexTextBlock.DocumentText);

Log.Comment("Select last tab.");
UIObject lastTab = FindElement.ByName("LastTab");
lastTab.Click();
Wait.ForIdle();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "3");
Verify.AreEqual("3", selectedIndexTextBlock.DocumentText);

Log.Comment("When the selected tab is last and is closed, selection should move to the previous item.");

// Use Middle Click to close the tab:
lastTab.Click(PointerButtons.Middle);
Wait.ForIdle();
VerifyElement.NotFound("LastTab", FindBy.Name);
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "2");
Verify.AreEqual("2", selectedIndexTextBlock.DocumentText);
}
}

Expand Down Expand Up @@ -348,6 +348,53 @@ public void DragBetweenTabViewsTest()
}
}

[TestMethod]
public void ReorderItemsTest()
{
if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
{
// TODO 19727004: Re-enable this on versions below RS5 after fixing the bug where mouse click-and-drag doesn't work.
Log.Warning("This test relies on touch input, the injection of which is only supported in RS5 and up. Test is disabled.");
return;
}

using (var setup = new TestSetupHelper("TabView Tests"))
{
Button tabItemsSourcePageButton = FindElement.ByName<Button>("TabViewTabItemsSourcePageButton");
tabItemsSourcePageButton.InvokeAndWait();

UIObject sourceTab = null;
int attempts = 0;

do
{
Wait.ForMilliseconds(100);
ElementCache.Refresh();

sourceTab = FindElement.ByName("tabViewItem0");
attempts++;
}
while (sourceTab == null && attempts < 4);

Verify.IsNotNull(sourceTab);

UIObject dropTab = FindElement.ByName("tabViewItem2");
Verify.IsNotNull(dropTab);

Log.Comment("Reordering tabs with drag-drop operation...");
InputHelper.DragToTarget(sourceTab, dropTab);
Wait.ForIdle();
ElementCache.Refresh();
Log.Comment("...reordering done. Expecting a TabView.TabItemsChanged event was raised with CollectionChange=ItemInserted and Index=1.");

TextBlock tblIVectorChangedEventArgsCollectionChange = FindElement.ByName<TextBlock>("tblIVectorChangedEventArgsCollectionChange");
Verify.AreEqual("ItemInserted", tblIVectorChangedEventArgsCollectionChange.DocumentText);

TextBlock tblIVectorChangedEventArgsIndex = FindElement.ByName<TextBlock>("tblIVectorChangedEventArgsIndex");
Verify.AreEqual("1", tblIVectorChangedEventArgsIndex.DocumentText);
}
}

[TestMethod]
public void AddButtonTest()
{
Expand Down Expand Up @@ -484,7 +531,6 @@ public void CloseButtonOverlayModeTests()
closeUnselectedButton = FindCloseButton(FindElement.ByName("LongHeaderTab"));
Verify.IsNotNull(closeUnselectedButton);
Verify.IsNotNull(closeSelectedButton);

}
}

Expand Down Expand Up @@ -530,15 +576,15 @@ public void DragOutsideTest()
using (var setup = new TestSetupHelper("TabView Tests"))
{
TextBlock dragOutsideTextBlock = FindElement.ByName<TextBlock>("TabDroppedOutsideTextBlock");
Verify.AreEqual(dragOutsideTextBlock.DocumentText, "");
Verify.AreEqual("", dragOutsideTextBlock.DocumentText);

Log.Comment("Drag tab out");
UIObject firstTab = TryFindElement.ByName("FirstTab");
InputHelper.DragDistance(firstTab, 50, Direction.South);
Wait.ForIdle();

Log.Comment("Verify event fired");
Verify.AreEqual(dragOutsideTextBlock.DocumentText, "Home");
Verify.AreEqual("Home", dragOutsideTextBlock.DocumentText);
}
}

Expand Down
Loading

0 comments on commit ac7ce43

Please sign in to comment.