From 237d1d5537208c2b341ac43102cdf46174e342a7 Mon Sep 17 00:00:00 2001 From: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:36:39 -0400 Subject: [PATCH] Updated UI tests for Light Switch to match new UI --- .../Tests/LightSwitch.UITests/TestHelper.cs | 30 +++++++------- .../TestUserSelectedLocation.cs | 32 --------------- .../Controls/Timeline/Timeline.xaml.cs | 6 +++ .../Timeline/TimelineAutomationPeer.cs | 39 +++++++++++++++++++ 4 files changed, 62 insertions(+), 45 deletions(-) delete mode 100644 src/modules/LightSwitch/Tests/LightSwitch.UITests/TestUserSelectedLocation.cs create mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/TimelineAutomationPeer.cs diff --git a/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestHelper.cs b/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestHelper.cs index 7bb4e77af3..7b586301f6 100644 --- a/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestHelper.cs +++ b/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestHelper.cs @@ -150,7 +150,7 @@ namespace LightSwitch.UITests var modeCombobox = testBase.Session.Find(By.AccessibilityId("ModeSelection_LightSwitch"), 5000); Assert.IsNotNull(modeCombobox, "Mode combobox not found."); - var neededTabs = 5; + var neededTabs = 6; if (modeCombobox.Text != "Manual") { @@ -167,7 +167,7 @@ namespace LightSwitch.UITests Assert.IsNotNull(timeline, "Timeline not found."); var helpText = timeline.GetAttribute("HelpText"); - string originalStartValue = GetHelpTextValue(helpText, "Start"); + string originalEndValue = GetHelpTextValue(helpText, "End"); for (int i = 0; i < neededTabs; i++) { @@ -179,12 +179,12 @@ namespace LightSwitch.UITests testBase.Session.SendKeys(Key.Enter); helpText = timeline.GetAttribute("HelpText"); - string updatedStartValue = GetHelpTextValue(helpText, "Start"); + string updatedEndValue = GetHelpTextValue(helpText, "End"); - Assert.AreNotEqual(originalStartValue, updatedStartValue, "Timeline start time should have been updated."); + Assert.AreNotEqual(originalEndValue, updatedEndValue, "Timeline end time should have been updated."); helpText = timeline.GetAttribute("HelpText"); - string originalEndValue = GetHelpTextValue(helpText, "End"); + string originalStartValue = GetHelpTextValue(helpText, "Start"); testBase.Session.SendKeys(Key.Tab); testBase.Session.SendKeys(Key.Enter); @@ -192,9 +192,9 @@ namespace LightSwitch.UITests testBase.Session.SendKeys(Key.Enter); helpText = timeline.GetAttribute("HelpText"); - string updatedEndValue = GetHelpTextValue(helpText, "End"); + string updatedStartValue = GetHelpTextValue(helpText, "Start"); - Assert.AreNotEqual(originalEndValue, updatedEndValue, "Timeline end time should have been updated."); + Assert.AreNotEqual(originalStartValue, updatedStartValue, "Timeline start time should have been updated."); } /// @@ -259,11 +259,7 @@ namespace LightSwitch.UITests // Click the select city button var setLocationButton = testBase.Session.Find(By.AccessibilityId("SetLocationButton_LightSwitch"), 5000); Assert.IsNotNull(setLocationButton, "Set location button not found."); - setLocationButton.Click(); - - var syncLocationButton = testBase.Session.Find(By.AccessibilityId("SyncLocationButton_LightSwitch"), 5000); - Assert.IsNotNull(syncLocationButton, "Sync location button not found."); - syncLocationButton.Click(msPostAction: 8000); + setLocationButton.Click(msPostAction: 8000); var latLong = testBase.Session.Find(By.AccessibilityId("LocationResultText_LightSwitch"), 5000); Assert.IsFalse(string.IsNullOrWhiteSpace(latLong.Text)); @@ -305,6 +301,7 @@ namespace LightSwitch.UITests string originalStartValue = GetHelpTextValue(helpText, "Start"); sunriseOffset.Click(); + testBase.Session.SendKeys(Key.Up); helpText = timeline.GetAttribute("HelpText"); string updatedStartValue = GetHelpTextValue(helpText, "Start"); @@ -319,6 +316,7 @@ namespace LightSwitch.UITests string originalEndValue = GetHelpTextValue(helpText, "End"); sunsetOffset.Click(); + testBase.Session.SendKeys(Key.Up); helpText = timeline.GetAttribute("HelpText"); string updatedEndValue = GetHelpTextValue(helpText, "End"); @@ -338,9 +336,15 @@ namespace LightSwitch.UITests var scrollViewer = testBase.Session.Find(By.AccessibilityId("PageScrollViewer")); systemCheckbox.EnsureVisible(scrollViewer); - // How do I handle when something is off screen? + int neededTabs = 10; + if (!systemCheckbox.Selected) { + for (int i = 0; i < neededTabs; i++) + { + testBase.Session.SendKeys(Key.Tab); + } + systemCheckbox.Click(); } diff --git a/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestUserSelectedLocation.cs b/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestUserSelectedLocation.cs deleted file mode 100644 index 924a04d9d9..0000000000 --- a/src/modules/LightSwitch/Tests/LightSwitch.UITests/TestUserSelectedLocation.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.PowerToys.UITest; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace LightSwitch.UITests -{ - [TestClass] - public class TestUserSelectedLocation : UITestBase - { - public TestUserSelectedLocation() - : base(PowerToysModule.PowerToysSettings, WindowSize.Large) - { - } - - [TestMethod("LightSwitch.UserSelectedLocation")] - [TestCategory("Location")] - public void TestUserSelectedLocationUpdate() - { - TestHelper.InitializeTest(this, "user selected location test"); - TestHelper.PerformUserSelectedLocationTest(this); - TestHelper.CleanupTest(this); - } - } -} diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/Timeline.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/Timeline.xaml.cs index 189556ee84..307d499fac 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/Timeline.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/Timeline.xaml.cs @@ -8,6 +8,7 @@ using System.Globalization; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; +using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Shapes; using Windows.Foundation; @@ -79,6 +80,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls this.IsEnabledChanged += Timeline_IsEnabledChanged; } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new TimelineAutomationPeer(this); + } + private void Timeline_Loaded(object sender, RoutedEventArgs e) { CheckEnabledState(); diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/TimelineAutomationPeer.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/TimelineAutomationPeer.cs new file mode 100644 index 0000000000..a32f99059a --- /dev/null +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/Timeline/TimelineAutomationPeer.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Automation; +using Microsoft.UI.Xaml.Automation.Peers; + +namespace Microsoft.PowerToys.Settings.UI.Controls +{ + public partial class TimelineAutomationPeer : FrameworkElementAutomationPeer + { + public TimelineAutomationPeer(Timeline owner) + : base(owner) + { + } + + protected override string GetClassNameCore() => "Timeline"; + + protected override AutomationControlType GetAutomationControlTypeCore() + => AutomationControlType.Custom; + + protected override string GetAutomationIdCore() + { + var owner = (Timeline)Owner; + var id = AutomationProperties.GetAutomationId(owner); + return string.IsNullOrEmpty(id) ? base.GetAutomationIdCore() : id; + } + + protected override string GetNameCore() + { + var owner = (Timeline)Owner; + var name = AutomationProperties.GetName(owner); + return !string.IsNullOrEmpty(name) + ? name + : $"Timeline from {owner.StartTime} to {owner.EndTime}"; + } + } +}