mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
added shortcut guide settings (#2247)
This commit is contained in:
@@ -126,7 +126,7 @@
|
||||
<Compile Include="UnitTestApp.xaml.cs">
|
||||
<DependentUpon>UnitTestApp.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModelTests\GeneralSettingsViewModelTest.cs" />
|
||||
<Compile Include="ViewModelTests\ShortcutGuideViewModelTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="UnitTestApp.xaml">
|
||||
@@ -153,10 +153,10 @@
|
||||
<Version>6.2.9</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MSTest.TestAdapter">
|
||||
<Version>1.4.0</Version>
|
||||
<Version>2.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MSTest.TestFramework">
|
||||
<Version>1.4.0</Version>
|
||||
<Version>2.1.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Schema;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class GeneralSettingsViewModelTest
|
||||
{
|
||||
[TestMethod]
|
||||
[DebuggerStepThrough]
|
||||
public void Packaged_ShouldSendConfigsWithUpdatedPackageValue_WhenSuccessful()
|
||||
{
|
||||
//GeneralViewModel viewModel = new GeneralViewModel();
|
||||
//viewModel.Packaged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Schema;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Windows.UI.Popups;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ShortcutGuideViewModelTest
|
||||
{
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
// initialize creation of test settings file.
|
||||
// Test base path:
|
||||
// C:\Users\<user name>\AppData\Local\Packages\08e1807b-8b6d-4bfa-adc4-79c64aae8e78_9abkseg265h2m\LocalState\Microsoft\PowerToys\
|
||||
GeneralSettings generalSettings = new GeneralSettings();
|
||||
ShortcutGuideSettings shortcutGuide = new ShortcutGuideSettings();
|
||||
|
||||
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
|
||||
SettingsUtils.SaveSettings(shortcutGuide.ToJsonString(), shortcutGuide.Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEnabled_ShouldEnableModule_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
|
||||
|
||||
// Assert
|
||||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.general.Enabled.ShortcutGuide);
|
||||
};
|
||||
|
||||
// Act
|
||||
viewModel.IsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ThemeIndex_ShouldSetThemeToDark_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
|
||||
|
||||
// Assert
|
||||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
Assert.AreEqual("dark", snd.powertoys.Properties.Theme.Value);
|
||||
Assert.AreEqual("hey", msg);
|
||||
};
|
||||
|
||||
// Act
|
||||
viewModel.ThemeIndex = 0;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PressTime_ShouldSetPressTimeToOneHundred_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
|
||||
|
||||
// Assert
|
||||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
// https://stackoverflow.com/questions/59198417/deserialization-of-reference-types-without-parameterless-constructor-is-not-supp
|
||||
Assert.AreEqual(100, snd.powertoys.Properties.PressTime.Value);
|
||||
};
|
||||
|
||||
// Act
|
||||
viewModel.PressTime = 100;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OverlayOpacity_ShouldSeOverlayOpacityToOneHundred_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
|
||||
|
||||
// Assert
|
||||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
// Serialisation not working as expected in the test project:
|
||||
// https://stackoverflow.com/questions/59198417/deserialization-of-reference-types-without-parameterless-constructor-is-not-supp
|
||||
Assert.AreEqual(100, snd.powertoys.Properties.OverlayOpacity.Value);
|
||||
};
|
||||
|
||||
// Act
|
||||
viewModel.OverlayOpacity = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user