From 3f52b2cfc9f3852e8df8c2a964a1d4a8e3b3d825 Mon Sep 17 00:00:00 2001 From: Yu Leng <42196638+moooyo@users.noreply.github.com> Date: Mon, 21 Jul 2025 18:06:51 +0800 Subject: [PATCH] [CmdPal][UI Tests] Add some indexer extension's test cases (#40731) ## Summary of the Pull Request 1. Add some test cases to cover indexer extension's ability. 2. Add CommandPaletteTestBase class to make us can easily implement test case. ## PR Checklist - [x] **Closes:** #40732 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Co-authored-by: Yu Leng (from Dev Box) --- .../Microsoft.CmdPal.UITests/BasicTests.cs | 23 +- .../CommandPaletteTestBase.cs | 48 ++++ .../Microsoft.CmdPal.UITests/IndexerTests.cs | 226 ++++++++++++++++++ 3 files changed, 275 insertions(+), 22 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UITests/CommandPaletteTestBase.cs create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UITests/IndexerTests.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs b/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs index c1eea18d98..872f1270f1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs @@ -10,33 +10,12 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.CmdPal.UITests; [TestClass] -public class BasicTests : UITestBase +public class BasicTests : CommandPaletteTestBase { public BasicTests() - : base(PowerToysModule.CommandPalette) { } - private void SetSearchBox(string text) - { - Assert.AreEqual(this.Find("Type here to search...").SetText(text, true).Text, text); - } - - private void SetFilesExtensionSearchBox(string text) - { - Assert.AreEqual(this.Find("Search for files and folders...").SetText(text, true).Text, text); - } - - private void SetCalculatorExtensionSearchBox(string text) - { - Assert.AreEqual(this.Find("Type an equation...").SetText(text, true).Text, text); - } - - private void SetTimeAndDaterExtensionSearchBox(string text) - { - Assert.AreEqual(this.Find("Search values or type a custom time stamp...").SetText(text, true).Text, text); - } - [TestMethod] public void BasicFileSearchTest() { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UITests/CommandPaletteTestBase.cs b/src/modules/cmdpal/Microsoft.CmdPal.UITests/CommandPaletteTestBase.cs new file mode 100644 index 0000000000..da259e3b18 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UITests/CommandPaletteTestBase.cs @@ -0,0 +1,48 @@ +// 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 Microsoft.CmdPal.UITests; + +public class CommandPaletteTestBase : UITestBase +{ + public CommandPaletteTestBase() + : base(PowerToysModule.CommandPalette) + { + } + + protected void SetSearchBox(string text) + { + Assert.AreEqual(this.Find("Type here to search...").SetText(text, true).Text, text); + } + + protected void SetFilesExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Search for files and folders...").SetText(text, true).Text, text); + } + + protected void SetCalculatorExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Type an equation...").SetText(text, true).Text, text); + } + + protected void SetTimeAndDaterExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Search values or type a custom time stamp...").SetText(text, true).Text, text); + } + + protected void OpenContextMenu() + { + var contextMenuButton = this.Find