mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-08 11:29:58 +02:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Before: <img width="1198" height="718" alt="image" src="https://github.com/user-attachments/assets/79a23cb3-93c6-4960-afc5-60c147f8ae92" /> After: <img width="1175" height="716" alt="image" src="https://github.com/user-attachments/assets/c4ea1e2d-ad47-4203-a77a-99f22bcfb448" /> <img width="630" height="434" alt="image" src="https://github.com/user-attachments/assets/8ad1d424-2907-4599-965d-1193effaf7bd" /> <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #38730 (a lot of the suggestions there were already resolved. <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **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 <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
149 lines
5.3 KiB
C#
149 lines
5.3 KiB
C#
// 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.Linq;
|
|
using Microsoft.CmdPal.Ext.System.Helpers;
|
|
using Microsoft.CmdPal.Ext.System.Pages;
|
|
using Microsoft.CmdPal.Ext.UnitTestBase;
|
|
using Microsoft.CommandPalette.Extensions;
|
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace Microsoft.CmdPal.Ext.System.UnitTests;
|
|
|
|
[TestClass]
|
|
public class QueryTests : CommandPaletteUnitTestBase
|
|
{
|
|
[DataTestMethod]
|
|
[DataRow("shutdown", "Shutdown computer")]
|
|
[DataRow("restart", "Restart computer")]
|
|
[DataRow("sign out", "Sign out of computer")]
|
|
[DataRow("lock", "Lock computer")]
|
|
[DataRow("sleep", "Put computer to sleep")]
|
|
[DataRow("hibernate", "Hibernate computer")]
|
|
[DataRow("open recycle", "Open Recycle Bin")]
|
|
[DataRow("empty recycle", "Empty Recycle Bin")]
|
|
[DataRow("uefi", "UEFI firmware settings")]
|
|
public void TopLevelPageQueryTest(string input, string matchedTitle)
|
|
{
|
|
var settings = new Settings();
|
|
var pages = new SystemCommandPage(settings);
|
|
var allCommands = pages.GetItems();
|
|
|
|
var result = Query(input, allCommands);
|
|
|
|
// Empty recycle bin command should exist
|
|
Assert.IsNotNull(result);
|
|
|
|
var firstItem = result.FirstOrDefault();
|
|
|
|
Assert.IsNotNull(firstItem, "No items matched the query.");
|
|
Assert.AreEqual(matchedTitle, firstItem.Title, $"Expected to match '{input}' but got '{firstItem.Title}'");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RecycleBinCommandTest()
|
|
{
|
|
var settings = new Settings(hideEmptyRecycleBin: true);
|
|
var pages = new SystemCommandPage(settings);
|
|
var allCommands = pages.GetItems();
|
|
|
|
var result = Query("recycle", allCommands);
|
|
|
|
// Empty recycle bin command should exist
|
|
Assert.IsNotNull(result);
|
|
|
|
foreach (var item in result)
|
|
{
|
|
if (item.Title.Contains("Open Recycle Bin") || item.Title.Contains("Empty Recycle Bin"))
|
|
{
|
|
Assert.Fail("Recycle Bin commands should not be available when hideEmptyRecycleBin is true.");
|
|
}
|
|
}
|
|
|
|
var firstItem = result.FirstOrDefault();
|
|
Assert.IsNotNull(firstItem, "No items matched the query.");
|
|
Assert.IsTrue(
|
|
firstItem.Title.Contains("Recycle Bin", StringComparison.OrdinalIgnoreCase),
|
|
$"Expected to match 'Recycle Bin' but got '{firstItem.Title}'");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void NetworkCommandsTest()
|
|
{
|
|
var settings = new Settings();
|
|
var pages = new SystemCommandPage(settings);
|
|
var allCommands = pages.GetItems();
|
|
|
|
var ipv4Result = Query("IPv4", allCommands);
|
|
|
|
Assert.IsNotNull(ipv4Result);
|
|
Assert.IsTrue(ipv4Result.Length > 0, "No IPv4 commands matched the query.");
|
|
|
|
var ipv6Result = Query("IPv6", allCommands);
|
|
Assert.IsNotNull(ipv6Result);
|
|
Assert.IsTrue(ipv6Result.Length > 0, "No IPv6 commands matched the query.");
|
|
|
|
var macResult = Query("MAC", allCommands);
|
|
Assert.IsNotNull(macResult);
|
|
Assert.IsTrue(macResult.Length > 0, "No MAC commands matched the query.");
|
|
|
|
var findDisconnectedMACResult = false;
|
|
foreach (var item in macResult)
|
|
{
|
|
if (item.Details.Body.Contains("Disconnected"))
|
|
{
|
|
findDisconnectedMACResult = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Assert.IsTrue(findDisconnectedMACResult, "No disconnected MAC address found in the results.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void HideDisconnectedNetworkInfoTest()
|
|
{
|
|
var settings = new Settings(hideDisconnectedNetworkInfo: true);
|
|
var pages = new SystemCommandPage(settings);
|
|
var allCommands = pages.GetItems();
|
|
|
|
var macResult = Query("MAC", allCommands);
|
|
Assert.IsNotNull(macResult);
|
|
Assert.IsTrue(macResult.Length > 0, "No MAC commands matched the query.");
|
|
|
|
var findDisconnectedMACResult = false;
|
|
foreach (var item in macResult)
|
|
{
|
|
if (item.Details.Body.Contains("Disconnected"))
|
|
{
|
|
findDisconnectedMACResult = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Assert.IsTrue(!findDisconnectedMACResult, "Disconnected MAC address found in the results.");
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(FirmwareType.Uefi, true)]
|
|
[DataRow(FirmwareType.Bios, false)]
|
|
[DataRow(FirmwareType.Max, false)]
|
|
[DataRow(FirmwareType.Unknown, false)]
|
|
public void FirmwareSettingsTest(FirmwareType firmwareType, bool hasCommand)
|
|
{
|
|
var settings = new Settings(firmwareType: firmwareType);
|
|
var pages = new SystemCommandPage(settings);
|
|
var allCommands = pages.GetItems();
|
|
var result = Query("UEFI", allCommands);
|
|
|
|
// UEFI Firmware Settings command should exist
|
|
Assert.IsNotNull(result);
|
|
var firstItem = result.FirstOrDefault();
|
|
var firstItemIsUefiCommand = firstItem?.Title.Contains("UEFI", StringComparison.OrdinalIgnoreCase) ?? false;
|
|
Assert.AreEqual(hasCommand, firstItemIsUefiCommand, $"Expected to match (or not match) 'UEFI firmware settings' but got '{firstItem?.Title}'");
|
|
}
|
|
}
|