From b67c0af62867dc8e7bd53bda8847c04fd82d671b Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Fri, 26 Apr 2024 10:00:48 +0200 Subject: [PATCH 01/14] test: SelectorBar API tests --- .../SelectorBar/SelectorBarTests.cs | 255 ++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/SelectorBar/SelectorBarTests.cs diff --git a/src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/SelectorBar/SelectorBarTests.cs b/src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/SelectorBar/SelectorBarTests.cs new file mode 100644 index 000000000000..d72b40a09270 --- /dev/null +++ b/src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/SelectorBar/SelectorBarTests.cs @@ -0,0 +1,255 @@ +#if HAS_UNO_WINUI +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using Common; +using System; +using System.Collections.Generic; +using System.Threading; +using Microsoft.UI.Private.Controls; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; +using MUXControlsTestApp.Utilities; + +namespace Microsoft.UI.Xaml.Tests.MUXControls.ApiTests; + +[TestClass] +#if !__SKIA__ +[Ignore("Only works properly on Skia")] +#endif +public class SelectorBarTests : MUXApiTestBase +{ + private const int c_MaxWaitDuration = 5000; + + private const double c_defaultUISelectorBarParentWidth = 400.0; + private const double c_defaultUISelectorBarParentHeight = 200.0; + + [TestMethod] + public void VerifyDefaultSelectorBarItemPropertyValues() + { + RunOnUIThread.Execute(() => + { + SelectorBarItem selectorBarItem = new SelectorBarItem(); + Verify.IsNotNull(selectorBarItem); + Verify.AreEqual("", selectorBarItem.Text); + Verify.IsNull(selectorBarItem.Icon); + Verify.IsNull(selectorBarItem.Child); + Verify.IsFalse(selectorBarItem.IsSelected); + }); + } + + [TestMethod] + public void VerifyDefaultSelectorBarPropertyValues() + { + RunOnUIThread.Execute(() => + { + SelectorBar selectorBar = new SelectorBar(); + Verify.IsNotNull(selectorBar); + Verify.IsNotNull(selectorBar.Items); + Verify.IsNull(selectorBar.SelectedItem); + }); + } + + [TestMethod] + public void VerifySelectorBarItems() + { + //using (PrivateLoggingHelper privateIVLoggingHelper = new PrivateLoggingHelper("ItemsView", "ScrollView")) + { + SelectorBar selectorBar = null; + AutoResetEvent selectorBarLoadedEvent = new AutoResetEvent(false); + AutoResetEvent selectorBarUnloadedEvent = new AutoResetEvent(false); + + RunOnUIThread.Execute(() => + { + selectorBar = new SelectorBar(); + Verify.IsNotNull(selectorBar); + Verify.IsNotNull(selectorBar.Items); + + SelectorBarItem selectorBarItemDeleted = new SelectorBarItem() + { + Text = "Deleted", + Icon = new SymbolIcon(Symbol.Delete), + IsEnabled = false + }; + + selectorBar.Items.Add(selectorBarItemDeleted); + + SelectorBarItem selectorBarItemRemote = new SelectorBarItem() + { + Text = "Remote", + Icon = new SymbolIcon(Symbol.Remote), + IsSelected = true + }; + + selectorBar.Items.Add(selectorBarItemRemote); + + SelectorBarItem selectorBarItemShared = new SelectorBarItem() + { + Text = "Shared", + Icon = new SymbolIcon(Symbol.Share) + }; + + selectorBar.Items.Add(selectorBarItemShared); + + SelectorBarItem selectorBarItemFavorites = new SelectorBarItem() + { + Text = "Favorites", + Icon = new SymbolIcon(Symbol.Favorite) + }; + + selectorBar.Items.Add(selectorBarItemFavorites); + + Verify.AreEqual(4, selectorBar.Items.Count); + + SetupDefaultUI(selectorBar, selectorBarLoadedEvent, selectorBarUnloadedEvent); + }); + + WaitForEvent("Waiting for Loaded event", selectorBarLoadedEvent); + + RunOnUIThread.Execute(() => + { + Log.Comment("Logging SelectorBar property values after Loaded event"); + LogSelectorBarProperties(selectorBar); + + Log.Comment("Verifying SelectorBar property values after Loaded event"); + Verify.AreEqual(selectorBar.Items[1], selectorBar.SelectedItem); + Verify.IsTrue(selectorBar.IsEnabled); + Verify.IsFalse(selectorBar.IsTabStop); + Verify.AreEqual(XYFocusKeyboardNavigationMode.Auto, selectorBar.XYFocusKeyboardNavigation); + Verify.AreEqual(KeyboardNavigationMode.Once, selectorBar.TabNavigation); + + ItemsView itemsView = SelectorBarTestHooks.GetItemsViewPart(selectorBar); + + Log.Comment("Logging ItemsView property values after Loaded event"); + LogItemsViewProperties(itemsView); + + Log.Comment("Verifying ItemsView property values after Loaded event"); + Verify.IsNotNull(itemsView); + Verify.AreEqual(XYFocusKeyboardNavigationMode.Disabled, itemsView.XYFocusKeyboardNavigation); + Verify.AreEqual(KeyboardNavigationMode.Once, itemsView.TabNavigation); + Verify.AreEqual(ItemsViewSelectionMode.Single, itemsView.SelectionMode); + Verify.AreEqual(1, itemsView.SelectedItems.Count); + Verify.AreEqual(-1, itemsView.CurrentItemIndex); + Verify.AreEqual(selectorBar.Items[1], itemsView.SelectedItem); + + Log.Comment("Removing 2nd SelectorBarItem."); + selectorBar.Items.RemoveAt(1); + Verify.AreEqual(3, selectorBar.Items.Count); + Verify.IsNull(selectorBar.SelectedItem); + + Log.Comment("Clearing all SelectorBarItems."); + selectorBar.Items.Clear(); + Verify.AreEqual(0, selectorBar.Items.Count); + + Log.Comment("Resetting window content and SelectorBar"); + Content = null; + selectorBar = null; + }); + + WaitForEvent("Waiting for Unloaded event", selectorBarUnloadedEvent); + IdleSynchronizer.Wait(); + Log.Comment("Done"); + } + } + + private void SetupDefaultUI( + SelectorBar selectorBar, + AutoResetEvent selectorBarLoadedEvent = null, + AutoResetEvent selectorBarUnloadedEvent = null, + bool setAsContentRoot = true, + bool useParentGrid = false) + { + Log.Comment("Setting up default UI with SelectorBar"); + + Verify.IsNotNull(selectorBar); + selectorBar.Name = "selectorBar"; + + if (selectorBarLoadedEvent != null) + { + selectorBar.Loaded += (object sender, RoutedEventArgs e) => + { + Log.Comment("SelectorBar.Loaded event handler"); + selectorBarLoadedEvent.Set(); + }; + } + + if (selectorBarUnloadedEvent != null) + { + selectorBar.Unloaded += (object sender, RoutedEventArgs e) => + { + Log.Comment("SelectorBar.Unloaded event handler"); + selectorBarUnloadedEvent.Set(); + }; + } + + Grid parentGrid = null; + + if (useParentGrid) + { + parentGrid = new Grid(); + parentGrid.Width = c_defaultUISelectorBarParentWidth; + parentGrid.Height = c_defaultUISelectorBarParentHeight; + + selectorBar.HorizontalAlignment = HorizontalAlignment.Left; + selectorBar.VerticalAlignment = VerticalAlignment.Top; + + parentGrid.Children.Add(selectorBar); + } + + if (setAsContentRoot) + { + Log.Comment("Setting window content"); + if (useParentGrid) + { + Content = parentGrid; + } + else + { + Content = selectorBar; + } + } + } + + private string GetStringFromSelectorBarItem(SelectorBarItem selectorBarItem) + { + return "Icon:" + (selectorBarItem.Icon == null ? "null" : selectorBarItem.Icon.ToString()) + ", Text:" + selectorBarItem.Text + ", Child:" + (selectorBarItem.Child == null ? "null" : selectorBarItem.Child.ToString()); + } + + private void LogSelectorBarProperties(SelectorBar selectorBar) + { + Log.Comment(" - selectorBar.SelectedItem: " + (selectorBar.SelectedItem == null ? "null" : GetStringFromSelectorBarItem(selectorBar.SelectedItem))); + foreach (var selectorBarItem in selectorBar.Items) + { + Log.Comment(" - selectorBar.Item: " + GetStringFromSelectorBarItem(selectorBarItem)); + } + Log.Comment(" - selectorBar.IsEnabled: " + selectorBar.IsEnabled); + Log.Comment(" - selectorBar.IsTabStop: " + selectorBar.IsTabStop); + Log.Comment(" - selectorBar.XYFocusKeyboardNavigation: " + selectorBar.XYFocusKeyboardNavigation); + Log.Comment(" - selectorBar.TabNavigation: " + selectorBar.TabNavigation); + } + + private void LogItemsViewProperties(ItemsView itemsView) + { + Log.Comment(" - itemsView.ItemTemplate: " + (itemsView.ItemTemplate == null ? "null" : "non-null")); + Log.Comment(" - itemsView.ItemsSource: " + (itemsView.ItemsSource == null ? "null" : "non-null")); + Log.Comment(" - itemsView.SelectedItem: " + (itemsView.SelectedItem == null ? "null" : "non-null")); + Log.Comment(" - itemsView.CurrentItemIndex: " + itemsView.CurrentItemIndex); + Log.Comment(" - itemsView.Layout: " + (itemsView.Layout == null ? "null" : "non-null")); + Log.Comment(" - itemsView.Layout as StackLayout: " + ((itemsView.Layout as StackLayout) == null ? "null" : "non-null")); + Log.Comment(" - itemsView.IsEnabled: " + itemsView.IsEnabled); + Log.Comment(" - itemsView.IsTabStop: " + itemsView.IsTabStop); + Log.Comment(" - itemsView.XYFocusKeyboardNavigation: " + itemsView.XYFocusKeyboardNavigation); + Log.Comment(" - itemsView.TabNavigation: " + itemsView.TabNavigation); + Log.Comment(" - itemsView.SelectionMode: " + itemsView.SelectionMode); + } + + private void WaitForEvent(string logComment, EventWaitHandle eventWaitHandle) + { + Log.Comment(logComment); + if (!eventWaitHandle.WaitOne(TimeSpan.FromMilliseconds(c_MaxWaitDuration))) + { + throw new Exception("Timeout expiration in WaitForEvent."); + } + } +} +#endif From 9930fb354f97d267360e8980bd0fb3dcd9a128fd Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Fri, 26 Apr 2024 11:12:35 +0200 Subject: [PATCH 02/14] test: SelectorBar sample pages --- .../SelectorBarTests/SelectorBarPage.xaml | 29 + .../SelectorBarTests/SelectorBarPage.xaml.cs | 63 + .../SelectorBarSamplePage.xaml | 47 + .../SelectorBarSamplePage.xaml.cs | 71 + .../SelectorBarSummaryPage.xaml | 277 +++ .../SelectorBarSummaryPage.xaml.cs | 1779 +++++++++++++++++ .../UITests.Shared/UITests.Shared.projitems | 21 + 7 files changed, 2287 insertions(+) create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml.cs create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml.cs create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSummaryPage.xaml create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSummaryPage.xaml.cs diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml new file mode 100644 index 000000000000..686f0b6ba553 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml @@ -0,0 +1,29 @@ + + + + + + + + None + Info + Verbose + + + + + + + + + + + + diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml.cs new file mode 100644 index 000000000000..1b065b0181d5 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarPage.xaml.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using Common; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Private.Controls; + +//using WEX.TestExecution; +//using WEX.TestExecution.Markup; +//using WEX.Logging.Interop; +using Uno.UI.Samples.Controls; + +namespace MUXControlsTestApp +{ + [Sample("SelectorBar")] + public sealed partial class SelectorBarPage : TestPage + { + public SelectorBarPage() + { + LogController.InitializeLogging(); + this.InitializeComponent(); + + navigateToSummary.Click += delegate { Frame.NavigateWithoutAnimation(typeof(SelectorBarSummaryPage), 0); }; + navigateToSample.Click += delegate { Frame.NavigateWithoutAnimation(typeof(SelectorBarSamplePage), 0); }; + } + + private void CmbSelectorBarOutputDebugStringLevel_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + //if (chkSelectorBar != null && chkSelectorBar.IsChecked == true) + //{ + // MUXControlsTestHooks.SetOutputDebugStringLevelForType( + // "SelectorBar", + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2, + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2); + //} + + //if (chkItemsView != null && chkItemsView.IsChecked == true) + //{ + // MUXControlsTestHooks.SetOutputDebugStringLevelForType( + // "ItemsView", + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2, + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2); + //} + + //if (chkItemContainer != null && chkItemContainer.IsChecked == true) + //{ + // MUXControlsTestHooks.SetOutputDebugStringLevelForType( + // "ItemContainer", + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2, + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2); + //} + + //if (chkItemsRepeater != null && chkItemsRepeater.IsChecked == true) + //{ + // MUXControlsTestHooks.SetOutputDebugStringLevelForType( + // "ItemsRepeater", + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 1 || cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2, + // cmbSelectorBarOutputDebugStringLevel.SelectedIndex == 2); + //} + } + } +} diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml new file mode 100644 index 000000000000..5e19a0944314 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml.cs new file mode 100644 index 000000000000..8a6ea8805a3e --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSamplePage.xaml.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using Microsoft.UI.Xaml.Controls; +using MUXControlsTestApp.Samples.Model; +using System; +using System.Collections.ObjectModel; +using Uno.UI.Samples.Controls; + +namespace MUXControlsTestApp +{ + [Sample("SelectorBar")] + public sealed partial class SelectorBarSamplePage : TestPage + { + private ObservableCollection _colRemotePhotos = null; + private ObservableCollection _colSharedPhotos = null; + private ObservableCollection _colFavoritePhotos = null; + + public SelectorBarSamplePage() + { + this.InitializeComponent(); + + _colRemotePhotos = new ObservableCollection(); + _colSharedPhotos = new ObservableCollection(); + _colFavoritePhotos = new ObservableCollection(); + + int imageCount = 20; + + for (int itemIndex = 0; itemIndex < imageCount; itemIndex++) + { + _colRemotePhotos.Add(new Recipe() + { + ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + 1)) + }); + _colSharedPhotos.Add(new Recipe() + { + ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + imageCount + 1)) + }); + _colFavoritePhotos.Add(new Recipe() + { + ImageUri = new Uri(string.Format("ms-appx:///Images/vette{0}.jpg", itemIndex % 126 + 2 * imageCount + 1)) + }); + } + } + + ~SelectorBarSamplePage() + { + } + + private void SelectorBar_SelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args) + { + if (sender.SelectedItem == selectorBarItemRemote) + { + photos.ItemsSource = _colRemotePhotos; + } + else if (sender.SelectedItem == selectorBarItemShared) + { + photos.ItemsSource = _colSharedPhotos; + } + else + { + photos.ItemsSource = _colFavoritePhotos; + } + + if (tblSelectedSelectorBarItem != null) + { + tblSelectedSelectorBarItem.Text = sender.SelectedItem == null ? "null" : sender.SelectedItem.Name; + } + } + } +} diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSummaryPage.xaml b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSummaryPage.xaml new file mode 100644 index 000000000000..7ddcf2543f93 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/SelectorBarTests/SelectorBarSummaryPage.xaml @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + +