mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[Settings] Migrate Color Picker Settings Tests (#5759)
* added MSTest project * migrated color picker settings * undo changes for the .xaml page
This commit is contained in:
@@ -1,20 +1,21 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|
||||||
{
|
{
|
||||||
public class ColorPickerViewModel : Observable
|
public class ColorPickerViewModel : Observable
|
||||||
{
|
{
|
||||||
private ColorPickerSettings _colorPickerSettings;
|
private ColorPickerSettings _colorPickerSettings;
|
||||||
private bool _isEnabled;
|
private bool _isEnabled;
|
||||||
|
|
||||||
public ColorPickerViewModel()
|
private Func<string, int> SendConfigMSG { get; }
|
||||||
|
|
||||||
|
public ColorPickerViewModel(Func<string, int> ipcMSGCallBackFunc)
|
||||||
{
|
{
|
||||||
if (SettingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
if (SettingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
||||||
_isEnabled = generalSettings.Enabled.ColorPicker;
|
_isEnabled = generalSettings.Enabled.ColorPicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the callback functions value to hangle outgoing IPC message.
|
||||||
|
SendConfigMSG = ipcMSGCallBackFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEnabled
|
public bool IsEnabled
|
||||||
@@ -50,7 +54,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
||||||
generalSettings.Enabled.ColorPicker = value;
|
generalSettings.Enabled.ColorPicker = value;
|
||||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
|
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
|
||||||
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
|
SendConfigMSG(outgoing.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +115,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
private void NotifySettingsChanged()
|
private void NotifySettingsChanged()
|
||||||
{
|
{
|
||||||
ShellPage.DefaultSndMSGCallback(
|
SendConfigMSG(
|
||||||
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ColorPickerSettings.ModuleName, JsonSerializer.Serialize(_colorPickerSettings)));
|
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ColorPickerSettings.ModuleName, JsonSerializer.Serialize(_colorPickerSettings)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// 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.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace ViewModelTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ColorPicker
|
||||||
|
{
|
||||||
|
private const string ModuleName = "ColorPicker";
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
var generalSettings = new GeneralSettings();
|
||||||
|
var colorPickerSettings = new ColorPickerSettings();
|
||||||
|
|
||||||
|
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
|
||||||
|
SettingsUtils.SaveSettings(colorPickerSettings.ToJsonString(), colorPickerSettings.Name, ModuleName + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCleanup]
|
||||||
|
public void CleanUp()
|
||||||
|
{
|
||||||
|
string generalSettings_file_name = string.Empty;
|
||||||
|
if (SettingsUtils.SettingsFolderExists(generalSettings_file_name))
|
||||||
|
{
|
||||||
|
DeleteFolder(generalSettings_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SettingsUtils.SettingsFolderExists(ModuleName))
|
||||||
|
{
|
||||||
|
DeleteFolder(ModuleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColorPickerIsEnabledByDefault()
|
||||||
|
{
|
||||||
|
var viewModel = new ColorPickerViewModel(ColorPickerIsEnabledByDefault_IPC);
|
||||||
|
|
||||||
|
Assert.IsTrue(viewModel.IsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ColorPickerIsEnabledByDefault_IPC(string msg)
|
||||||
|
{
|
||||||
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||||
|
Assert.IsTrue(snd.GeneralSettings.Enabled.ColorPicker);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DeleteFolder(string powertoy)
|
||||||
|
{
|
||||||
|
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -108,7 +108,6 @@
|
|||||||
<Compile Include="Interop.cs" />
|
<Compile Include="Interop.cs" />
|
||||||
<Compile Include="Services\ActivationService.cs" />
|
<Compile Include="Services\ActivationService.cs" />
|
||||||
<Compile Include="Services\NavigationService.cs" />
|
<Compile Include="Services\NavigationService.cs" />
|
||||||
<Compile Include="ViewModels\ColorPickerViewModel.cs" />
|
|
||||||
<Compile Include="ViewModels\Commands\ButtonClickCommand.cs" />
|
<Compile Include="ViewModels\Commands\ButtonClickCommand.cs" />
|
||||||
<Compile Include="ViewModels\FancyZonesViewModel.cs" />
|
<Compile Include="ViewModels\FancyZonesViewModel.cs" />
|
||||||
<Compile Include="ViewModels\ImageResizerViewModel.cs" />
|
<Compile Include="ViewModels\ImageResizerViewModel.cs" />
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||||
@@ -13,7 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
|
|
||||||
public ColorPickerPage()
|
public ColorPickerPage()
|
||||||
{
|
{
|
||||||
ViewModel = new ColorPickerViewModel();
|
ViewModel = new ColorPickerViewModel(ShellPage.SendDefaultIPCMessage);
|
||||||
DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user