mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[CmdPal][UnitTest] Refactor system command unit test (#40874)
<!-- 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 Ok... The AI generated and migrated ut's quality is very poor. We need to refactor it. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #40875 - [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 <!-- 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: Yu Leng (from Dev Box) <yuleng@microsoft.com>
This commit is contained in:
@@ -12,16 +12,16 @@ namespace Microsoft.CmdPal.Ext.System;
|
||||
|
||||
internal sealed partial class FallbackSystemCommandItem : FallbackCommandItem
|
||||
{
|
||||
public FallbackSystemCommandItem(SettingsManager settings)
|
||||
public FallbackSystemCommandItem(ISettingsInterface settings)
|
||||
: base(new NoOpCommand(), Resources.Microsoft_plugin_ext_fallback_display_title)
|
||||
{
|
||||
Title = string.Empty;
|
||||
Subtitle = string.Empty;
|
||||
|
||||
var isBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi;
|
||||
var hideEmptyRB = settings.HideEmptyRecycleBin;
|
||||
var confirmSystemCommands = settings.ShowDialogToConfirmCommand;
|
||||
var showSuccessOnEmptyRB = settings.ShowSuccessMessageAfterEmptyingRecycleBin;
|
||||
var isBootedInUefiMode = settings.GetSystemFirmwareType() == FirmwareType.Uefi;
|
||||
var hideEmptyRB = settings.HideEmptyRecycleBin();
|
||||
var confirmSystemCommands = settings.ShowDialogToConfirmCommand();
|
||||
var showSuccessOnEmptyRB = settings.ShowSuccessMessageAfterEmptyingRecycleBin();
|
||||
|
||||
systemCommands = Commands.GetSystemCommands(isBootedInUefiMode, hideEmptyRB, confirmSystemCommands, showSuccessOnEmptyRB);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ internal static class Commands
|
||||
/// </summary>
|
||||
/// <param name="manager">The tSettingsManager instance</param>
|
||||
/// <returns>The list of available results</returns>
|
||||
public static List<IListItem> GetNetworkConnectionResults(SettingsManager manager)
|
||||
public static List<IListItem> GetNetworkConnectionResults(ISettingsInterface manager)
|
||||
{
|
||||
var results = new List<IListItem>();
|
||||
|
||||
@@ -151,7 +151,7 @@ internal static class Commands
|
||||
CompositeFormat sysIpv4DescriptionCompositeFormate = CompositeFormat.Parse(Resources.Microsoft_plugin_sys_ip4_description);
|
||||
CompositeFormat sysIpv6DescriptionCompositeFormate = CompositeFormat.Parse(Resources.Microsoft_plugin_sys_ip6_description);
|
||||
CompositeFormat sysMacDescriptionCompositeFormate = CompositeFormat.Parse(Resources.Microsoft_plugin_sys_mac_description);
|
||||
var hideDisconnectedNetworkInfo = manager.HideDisconnectedNetworkInfo;
|
||||
var hideDisconnectedNetworkInfo = manager.HideDisconnectedNetworkInfo();
|
||||
|
||||
foreach (NetworkConnectionProperties intInfo in networkPropertiesCache)
|
||||
{
|
||||
@@ -200,7 +200,7 @@ internal static class Commands
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<IListItem> GetAllCommands(SettingsManager manager)
|
||||
public static List<IListItem> GetAllCommands(ISettingsInterface manager)
|
||||
{
|
||||
var list = new List<IListItem>();
|
||||
var listLock = new object();
|
||||
@@ -209,11 +209,11 @@ internal static class Commands
|
||||
// On global queries the first word/part has to be 'ip', 'mac' or 'address' for network results
|
||||
var networkConnectionResults = Commands.GetNetworkConnectionResults(manager);
|
||||
|
||||
var isBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi;
|
||||
var isBootedInUefiMode = manager.GetSystemFirmwareType() == FirmwareType.Uefi;
|
||||
|
||||
var hideEmptyRB = manager.HideEmptyRecycleBin;
|
||||
var confirmSystemCommands = manager.ShowDialogToConfirmCommand;
|
||||
var showSuccessOnEmptyRB = manager.ShowSuccessMessageAfterEmptyingRecycleBin;
|
||||
var hideEmptyRB = manager.HideEmptyRecycleBin();
|
||||
var confirmSystemCommands = manager.ShowDialogToConfirmCommand();
|
||||
var showSuccessOnEmptyRB = manager.ShowSuccessMessageAfterEmptyingRecycleBin();
|
||||
|
||||
// normal system commands are fast and can be returned immediately
|
||||
var systemCommands = Commands.GetSystemCommands(isBootedInUefiMode, hideEmptyRB, confirmSystemCommands, showSuccessOnEmptyRB);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.System.Helpers;
|
||||
|
||||
public interface ISettingsInterface
|
||||
{
|
||||
public bool ShowDialogToConfirmCommand();
|
||||
|
||||
public bool ShowSuccessMessageAfterEmptyingRecycleBin();
|
||||
|
||||
public bool HideEmptyRecycleBin();
|
||||
|
||||
public bool HideDisconnectedNetworkInfo();
|
||||
|
||||
public FirmwareType GetSystemFirmwareType();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.System.Helpers;
|
||||
|
||||
public class SettingsManager : JsonSettingsManager
|
||||
public class SettingsManager : JsonSettingsManager, ISettingsInterface
|
||||
{
|
||||
private static readonly string _namespace = "system";
|
||||
|
||||
@@ -37,14 +37,6 @@ public class SettingsManager : JsonSettingsManager
|
||||
Resources.Microsoft_plugin_ext_settings_hideDisconnectedNetworkInfo,
|
||||
false);
|
||||
|
||||
public bool ShowDialogToConfirmCommand => _showDialogToConfirmCommand.Value;
|
||||
|
||||
public bool ShowSuccessMessageAfterEmptyingRecycleBin => _showSuccessMessageAfterEmptyingRecycleBin.Value;
|
||||
|
||||
public bool HideEmptyRecycleBin => _hideEmptyRecycleBin.Value;
|
||||
|
||||
public bool HideDisconnectedNetworkInfo => _hideDisconnectedNetworkInfo.Value;
|
||||
|
||||
internal static string SettingsJsonPath()
|
||||
{
|
||||
var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal");
|
||||
@@ -54,6 +46,16 @@ public class SettingsManager : JsonSettingsManager
|
||||
return Path.Combine(directory, "settings.json");
|
||||
}
|
||||
|
||||
public bool ShowDialogToConfirmCommand() => _showDialogToConfirmCommand.Value;
|
||||
|
||||
public bool ShowSuccessMessageAfterEmptyingRecycleBin() => _showSuccessMessageAfterEmptyingRecycleBin.Value;
|
||||
|
||||
public bool HideEmptyRecycleBin() => _hideEmptyRecycleBin.Value;
|
||||
|
||||
public bool HideDisconnectedNetworkInfo() => _hideDisconnectedNetworkInfo.Value;
|
||||
|
||||
public FirmwareType GetSystemFirmwareType() => Win32Helpers.GetSystemFirmwareType();
|
||||
|
||||
public SettingsManager()
|
||||
{
|
||||
FilePath = SettingsJsonPath();
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Microsoft.CmdPal.Ext.System.Pages;
|
||||
|
||||
public sealed partial class SystemCommandPage : ListPage
|
||||
{
|
||||
private readonly SettingsManager _settingsManager;
|
||||
private readonly ISettingsInterface _settingsManager;
|
||||
|
||||
public SystemCommandPage(SettingsManager settingsManager)
|
||||
public SystemCommandPage(ISettingsInterface settingsManager)
|
||||
{
|
||||
Title = Resources.Microsoft_plugin_ext_system_page_title;
|
||||
Name = Resources.Microsoft_plugin_command_name_open;
|
||||
|
||||
Reference in New Issue
Block a user