Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
13 changes: 7 additions & 6 deletions WinUIGallery/Samples/ControlPages/FlipViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ExampleHeight="Auto"
HeaderText="A simple FlipView with items declared inline.">
<controls:ControlExample.Example>
<FlipView Height="270" MaxWidth="400">
<FlipView Height="270" MaxWidth="400" AutomationProperties.LocalizedControlType="FlipView">
<Image AutomationProperties.Name="Cliff" Source="ms-appx:///Assets/SampleMedia/cliff.jpg" />
<Image AutomationProperties.Name="Grapes" Source="ms-appx:///Assets/SampleMedia/grapes.jpg" />
<Image AutomationProperties.Name="Rainier" Source="ms-appx:///Assets/SampleMedia/rainier.jpg" />
Expand All @@ -32,7 +32,7 @@
</controls:ControlExample.Example>
<controls:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;FlipView MaxWidth="400" Height="270"&gt;
&lt;FlipView MaxWidth="400" Height="270" AutomationProperties.LocalizedControlType="FlipView"&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/cliff.jpg" AutomationProperties.Name="Cliff"/&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/grapes.jpg" AutomationProperties.Name="Grapes"/&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/rainier.jpg" AutomationProperties.Name="Rainier"/&gt;
Expand All @@ -49,6 +49,7 @@
MaxWidth="400"
BorderBrush="Black"
BorderThickness="1"
AutomationProperties.LocalizedControlType="FlipView"
ItemsSource="{x:Bind Items, Mode=OneWay}">
<FlipView.ItemTemplate>
<DataTemplate x:DataType="models:ControlInfoDataItem">
Expand Down Expand Up @@ -81,7 +82,7 @@
</controls:ControlExample.Example>
<controls:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;FlipView MaxWidth="400" Height="180" BorderBrush="Black" BorderThickness="1" ItemsSource="{x:Bind Items, Mode=OneWay}"&gt;
&lt;FlipView MaxWidth="400" Height="180" BorderBrush="Black" BorderThickness="1" AutomationProperties.LocalizedControlType="FlipView" ItemsSource="{x:Bind Items, Mode=OneWay}"&gt;
&lt;FlipView.ItemTemplate&gt;
&lt;DataTemplate x:DataType="data:ControlInfoDataItem"&gt;
&lt;Grid&gt;
Expand All @@ -98,7 +99,7 @@
</controls:ControlExample>
<controls:ControlExample x:Name="Example3" HeaderText="Vertical FlipView">
<controls:ControlExample.Example>
<FlipView Height="270" MaxWidth="400">
<FlipView Height="270" MaxWidth="400" AutomationProperties.LocalizedControlType="FlipView">
<Image AutomationProperties.Name="Cliff" Source="ms-appx:///Assets/SampleMedia/cliff.jpg" />
<Image AutomationProperties.Name="Grapes" Source="ms-appx:///Assets/SampleMedia/grapes.jpg" />
<Image AutomationProperties.Name="Rainier" Source="ms-appx:///Assets/SampleMedia/rainier.jpg" />
Expand All @@ -113,7 +114,7 @@
</controls:ControlExample.Example>
<controls:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;FlipView MaxWidth="400" Height="270"&gt;
&lt;FlipView MaxWidth="400" Height="270" AutomationProperties.LocalizedControlType="FlipView"&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/cliff.jpg" AutomationProperties.Name="Cliff"/&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/grapes.jpg" AutomationProperties.Name="Grapes"/&gt;
&lt;Image Source="ms-appx:///Assets/SampleMedia/rainier.jpg" AutomationProperties.Name="Rainier"/&gt;
Expand All @@ -124,7 +125,7 @@
&lt;VirtualizingStackPanel Orientation="Vertical"/&gt;
&lt;/ItemsPanelTemplate&gt;
&lt;/FlipView.ItemsPanel&gt;
&lt;FlipView&gt;
&lt;/FlipView&gt;
</x:String>
</controls:ControlExample.Xaml>
</controls:ControlExample>
Expand Down
73 changes: 73 additions & 0 deletions tests/WinUIGallery.UITests/Tests/FlipView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;

namespace WinUIGallery.UITests.Tests;

[TestClass]
public class FlipView : TestBase
{
private static WindowsElement flipViewElement1 = null;
private static WindowsElement flipViewElement2 = null;
private static WindowsElement flipViewElement3 = null;

[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
OpenControlPage("FlipView");

// Wait for the page to load and find FlipView elements
System.Threading.Thread.Sleep(1000);

// Find the FlipView controls - they should have LocalizedControlType set
var flipViews = Session.FindElementsByClassName("FlipView");
Assert.IsTrue(flipViews.Count >= 3, "FlipViewPage should contain at least 3 FlipView controls");

flipViewElement1 = flipViews[0];
flipViewElement2 = flipViews[1];
flipViewElement3 = flipViews[2];

Assert.IsNotNull(flipViewElement1);
Assert.IsNotNull(flipViewElement2);
Assert.IsNotNull(flipViewElement3);
}

[TestMethod]
public void VerifyFlipViewLocalizedControlType()
{
// Verify that FlipView controls have proper LocalizedControlType for accessibility
Assert.AreEqual("FlipView", flipViewElement1.GetAttribute("LocalizedControlType"),
"First FlipView should have LocalizedControlType set to 'FlipView'");
Assert.AreEqual("FlipView", flipViewElement2.GetAttribute("LocalizedControlType"),
"Second FlipView should have LocalizedControlType set to 'FlipView'");
Assert.AreEqual("FlipView", flipViewElement3.GetAttribute("LocalizedControlType"),
"Third FlipView should have LocalizedControlType set to 'FlipView'");
}

[TestMethod]
public void BasicFlipViewNavigation()
{
// Test basic FlipView navigation functionality
Assert.IsTrue(flipViewElement1.Displayed, "FlipView should be visible");

// Get the initial selected item
var selectedItem = flipViewElement1.GetAttribute("Selection.SelectedItem");
Assert.IsNotNull(selectedItem, "FlipView should have a selected item");

// Try to navigate (this might require keyboard navigation or finding navigation buttons)
flipViewElement1.Click();
System.Threading.Thread.Sleep(500);

// Basic verification that the control is functional
Assert.IsTrue(flipViewElement1.Enabled, "FlipView should be enabled and functional");
}

[TestMethod]
public void VerifyAccessibilityCompliance()
{
// Run accessibility scan specifically for FlipView
AxeHelper.AssertNoAccessibilityErrors();
}
}
71 changes: 71 additions & 0 deletions tests/WinUIGallery.UnitTests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Threading.Tasks;
using Windows.Foundation;
using WinUIGallery.Helpers;
using WinUIGallery.ControlPages;

namespace WinUIGallery.UnitTests;

Expand Down Expand Up @@ -184,6 +185,76 @@ private void ExecuteOnUIThread(Action action)
}
}

[UITestMethod]
public void TestFlipViewAutomationProperties()
{
FlipView flipView = new()
{
Height = 270,
MaxWidth = 400
};

// Set the LocalizedControlType as done in the FlipViewPage
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLocalizedControlType(flipView, "FlipView");

// Add some test items
flipView.Items.Add(new Rectangle() { Fill = new SolidColorBrush(Colors.Red), Width = 100, Height = 100 });
flipView.Items.Add(new Rectangle() { Fill = new SolidColorBrush(Colors.Blue), Width = 100, Height = 100 });

UnitTestApp.UnitTestAppWindow.AddToVisualTree(flipView);
flipView.UpdateLayout();

// Verify that the LocalizedControlType is set correctly
var localizedControlType = Microsoft.UI.Xaml.Automation.AutomationProperties.GetLocalizedControlType(flipView);
Assert.AreEqual("FlipView", localizedControlType, "FlipView should have LocalizedControlType set to 'FlipView'");

// Verify that the control is accessible
Assert.IsNotNull(flipView, "FlipView should be created successfully");
Assert.AreEqual(2, flipView.Items.Count, "FlipView should contain 2 items");
}

[UITestMethod]
public void TestFlipViewPageAutomationProperties()
{
// Create an instance of FlipViewPage to test the actual implementation
FlipViewPage flipViewPage = new();

UnitTestApp.UnitTestAppWindow.AddToVisualTree(flipViewPage);
flipViewPage.UpdateLayout();

// Find FlipView controls in the page and verify their LocalizedControlType
var flipViews = FindVisualChildren<FlipView>(flipViewPage);

Assert.IsTrue(flipViews.Count() >= 3, "FlipViewPage should contain at least 3 FlipView controls");

foreach (var flipView in flipViews)
{
var localizedControlType = Microsoft.UI.Xaml.Automation.AutomationProperties.GetLocalizedControlType(flipView);
Assert.AreEqual("FlipView", localizedControlType,
$"FlipView should have LocalizedControlType set to 'FlipView' for accessibility compliance");
}
}

private static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}

foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}

[TestCleanup]
public void Cleanup()
{
Expand Down