mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[PT Run] System commands plugin: Update dev docs and UnitTests (#15832)
* update UnitTests * dev docs * fix plugin name * fix spelling * fix path * improvement * fix table
This commit is contained in:
@@ -27,11 +27,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
|
||||
[DataRow("sleep", "Images\\sleep.dark.png")]
|
||||
[DataRow("hibernate", "Images\\sleep.dark.png")]
|
||||
[DataRow("empty recycle", "Images\\recyclebin.dark.png")]
|
||||
[DataRow("uefi firmware settings", "Images\\firmwareSettings.dark.png")]
|
||||
public void IconThemeDarkTest(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new Mock<Main>();
|
||||
main.Object.IconTheme = "dark";
|
||||
main.Object.IsBootedInUefiMode = true; // Set to true that we can test, regardless of the environment we run on.
|
||||
Query expectedQuery = new Query(typedString);
|
||||
|
||||
// Act
|
||||
@@ -49,11 +51,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
|
||||
[DataRow("sleep", "Images\\sleep.light.png")]
|
||||
[DataRow("hibernate", "Images\\sleep.light.png")]
|
||||
[DataRow("empty recycle", "Images\\recyclebin.light.png")]
|
||||
[DataRow("uefi firmware settings", "Images\\firmwareSettings.light.png")]
|
||||
public void IconThemeLightTest(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new Mock<Main>();
|
||||
main.Object.IconTheme = "light";
|
||||
main.Object.IsBootedInUefiMode = true; // Set to true that we can test, regardless of the environment we run on.
|
||||
Query expectedQuery = new Query(typedString);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
|
||||
[DataRow("sleep", "Put computer to sleep")]
|
||||
[DataRow("hibernate", "Hibernate computer")]
|
||||
[DataRow("empty recycle", "Empty Recycle Bin")]
|
||||
public void QueryResults(string typedString, string expectedResult)
|
||||
public void EnvironmentIndependentQueryResults(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new Mock<Main>();
|
||||
@@ -39,5 +39,35 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
|
||||
// Assert
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UefiCommandIsAvailableOnUefiSystems()
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new Mock<Main>();
|
||||
main.Object.IsBootedInUefiMode = true; // Simulate system with UEFI.
|
||||
Query expectedQuery = new Query("uefi firm");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Reboot computer into UEFI Firmware Settings (Requires administrative permissions.)", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UefiCommandIsNotAvailableOnSystemsWithoutUefi()
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new Mock<Main>();
|
||||
main.Object.IsBootedInUefiMode = false; // Simulate system without UEFI.
|
||||
Query expectedQuery = new Query("uefi firm");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault();
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
|
||||
public string IconTheme { get; set; }
|
||||
|
||||
public bool IsBootedInUefiMode { get; set; }
|
||||
|
||||
public ICommand Command { get; set; }
|
||||
|
||||
public string Name => Resources.Microsoft_plugin_sys_plugin_name;
|
||||
@@ -43,8 +45,6 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
private bool _confirmSystemCommands;
|
||||
private bool _localizeSystemCommands;
|
||||
|
||||
private bool isBootedInUefiMode = NativeMethods.GetSystemFirmwareType() == NativeMethods.FirmwareTypes.Uefi;
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
@@ -66,10 +66,11 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
_context = context;
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconTheme(_context.API.GetCurrentTheme());
|
||||
IsBootedInUefiMode = NativeMethods.GetSystemFirmwareType() == NativeMethods.FirmwareTypes.Uefi;
|
||||
|
||||
// Log info if the system hasn't boot in uefi mode.
|
||||
// (Because this is only going into the log we can ignore the fact that normally UEFI and BIOS are written upper case. No need to convert the enumeration value to upper case.)
|
||||
if (!isBootedInUefiMode)
|
||||
if (!IsBootedInUefiMode)
|
||||
{
|
||||
Wox.Plugin.Logger.Log.Info($"The UEFI command will not show to the user. The system has not booted in UEFI mode or the system does not have an UEFI firmware! (Detected type: {NativeMethods.GetSystemFirmwareType()})", typeof(Main));
|
||||
}
|
||||
@@ -196,7 +197,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
});
|
||||
|
||||
// UEFI command/result. It is only available on systems booted in UEFI mode.
|
||||
if (isBootedInUefiMode)
|
||||
if (IsBootedInUefiMode)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user