Skip to content

Commit 4dbba32

Browse files
committed
Updated Carousel tests to include new Visual UI test implementation.
1 parent 3b2d965 commit 4dbba32

File tree

3 files changed

+71
-30
lines changed

3 files changed

+71
-30
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/Carousel/CarouselAutomationPeer.cs renamed to Microsoft.Toolkit.Uwp.UI.Controls.Layout/Carousel/CarouselAutomationPeer.cs

File renamed without changes.

Microsoft.Toolkit.Uwp.UI.Controls/Carousel/CarouselItemAutomationPeer.cs renamed to Microsoft.Toolkit.Uwp.UI.Controls.Layout/Carousel/CarouselItemAutomationPeer.cs

File renamed without changes.

UnitTests/UnitTests.UWP/UI/Controls/Test_Carousel.cs

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,98 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Collections.Generic;
6-
using System.Collections.ObjectModel;
7-
using System.Diagnostics;
85
using System.Linq;
6+
using System.Threading.Tasks;
97
using Windows.UI.Xaml.Automation;
10-
using Microsoft.Toolkit.Uwp.UI.Controls;
118
using Microsoft.VisualStudio.TestTools.UnitTesting;
12-
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
139
using Windows.UI.Xaml.Automation.Peers;
10+
using Windows.UI.Xaml.Controls;
11+
using Windows.UI.Xaml.Markup;
1412
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
13+
using Microsoft.Toolkit.Uwp.Extensions;
14+
using Carousel = Microsoft.Toolkit.Uwp.UI.Controls.Carousel;
1515

1616
namespace UnitTests.UWP.UI.Controls
1717
{
1818
[TestClass]
1919
[TestCategory("Test_Carousel")]
20-
public class Test_Carousel
20+
public class Test_Carousel : VisualUITestBase
2121
{
22-
[UITestMethod]
23-
public void ShouldConfigureCarouselAutomationPeer()
22+
[TestMethod]
23+
public async Task ShouldConfigureCarouselAutomationPeerAsync()
2424
{
25-
const string automationName = "MyAutomationPhotoItems";
26-
const string name = "MyPhotoItems";
25+
await App.DispatcherQueue.EnqueueAsync(async () =>
26+
{
27+
var treeRoot = XamlReader.Load(@"<Page
28+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
29+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
30+
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""
31+
xmlns:data=""using:UnitTests.UWP.UI.Controls"">
32+
<Grid>
33+
<controls:Carousel InvertPositive=""True"">
34+
<controls:Carousel.EasingFunction>
35+
<CubicEase EasingMode=""EaseOut"" />
36+
</controls:Carousel.EasingFunction>
2737
28-
var items = new ObservableCollection<PhotoDataItem> { new PhotoDataItem { Title = "Hello" }, new PhotoDataItem { Title = "World" } };
29-
var carousel = new Carousel { ItemsSource = items };
38+
<controls:CarouselItem>
39+
Hello
40+
</controls:CarouselItem>
41+
<controls:CarouselItem>
42+
World
43+
</controls:CarouselItem>
44+
</controls:Carousel>
45+
</Grid>
46+
</Page>") as Page;
3047

31-
var carouselAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
48+
// This is based on the XAML above.
49+
var expectedNumItems = 2;
50+
var expectedSelectedItem = "World";
3251

33-
Assert.IsNotNull(carouselAutomationPeer, "Verify that the AutomationPeer is CarouselAutomationPeer.");
34-
Assert.IsFalse(carouselAutomationPeer.CanSelectMultiple, "Verify that CarouselAutomationPeer.CanSelectMultiple is false.");
35-
Assert.IsTrue(carouselAutomationPeer.IsSelectionRequired, "Verify that CarouselAutomationPeer.IsSelectionRequired is false.");
52+
Assert.IsNotNull(treeRoot, "XAML for test failed to load");
3653

37-
carousel.SetValue(AutomationProperties.NameProperty, automationName);
38-
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the given AutomationProperties.Name of the Carousel.");
54+
await SetTestContentAsync(treeRoot);
3955

40-
carousel.Name = name;
41-
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the Carousel.");
42-
}
56+
var outerGrid = treeRoot.Content as Grid;
4357

44-
public class PhotoDataItem
45-
{
46-
public string Title { get; set; }
58+
Assert.IsNotNull(outerGrid, "Couldn't find Page content.");
4759

48-
public string Category { get; set; }
60+
var carousel = outerGrid.Children.FirstOrDefault() as Carousel;
4961

50-
public string Thumbnail { get; set; }
62+
Assert.IsNotNull(carousel, "Couldn't find Target Carousel.");
5163

52-
public override string ToString()
53-
{
54-
return Title;
55-
}
64+
// Sets the selected item to "World" from the XAML above.
65+
carousel.SelectedIndex = 1;
66+
67+
const string automationName = "MyAutomationPhotoItems";
68+
const string name = "MyPhotoItems";
69+
70+
var carouselAutomationPeer =
71+
FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
72+
73+
Assert.IsNotNull(carouselAutomationPeer, "Verify that the AutomationPeer is CarouselAutomationPeer.");
74+
Assert.IsFalse(carouselAutomationPeer.CanSelectMultiple, "Verify that CarouselAutomationPeer.CanSelectMultiple is false.");
75+
Assert.IsTrue(carouselAutomationPeer.IsSelectionRequired, "Verify that CarouselAutomationPeer.IsSelectionRequired is true.");
76+
77+
carousel.SetValue(AutomationProperties.NameProperty, automationName);
78+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the given AutomationProperties.Name of the Carousel.");
79+
80+
carousel.Name = name;
81+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the Carousel.");
82+
83+
var carouselItemAutomationPeers = carouselAutomationPeer.GetChildren().Cast<CarouselItemAutomationPeer>().ToList();
84+
Assert.AreEqual(expectedNumItems, carouselItemAutomationPeers.Count);
85+
86+
for (var i = 0; i < carouselItemAutomationPeers.Count; i++)
87+
{
88+
var peer = carouselItemAutomationPeers[i];
89+
Assert.AreEqual(i + 1, peer.GetPositionInSet());
90+
Assert.AreEqual(expectedNumItems, peer.GetSizeOfSet());
91+
}
92+
93+
var selected = carouselItemAutomationPeers.FirstOrDefault(peer => peer.IsSelected);
94+
Assert.IsNotNull(selected);
95+
Assert.IsTrue(selected.GetName().Contains(expectedSelectedItem));
96+
});
5697
}
5798
}
5899
}

0 commit comments

Comments
 (0)