mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[Settings] Migrate Fancy Zones Settings Tests (#5762)
* added MSTest project * [Settings] Migrate Fancy Zones Settings Tests * fixed errors * reverted changes to xaml file * updated varibale for test folder * add ignore case flag * fixed Sttings.UI.csproj file * fixed Sttings.UI.csproj file
This commit is contained in:
@@ -2,15 +2,12 @@
|
|||||||
// 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.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels.Commands;
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
|
||||||
using Microsoft.Toolkit.Uwp.Helpers;
|
|
||||||
using Windows.UI;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
||||||
{
|
{
|
||||||
public class FancyZonesViewModel : Observable
|
public class FancyZonesViewModel : Observable
|
||||||
{
|
{
|
||||||
@@ -20,44 +17,53 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
private FancyZonesSettings Settings { get; set; }
|
private FancyZonesSettings Settings { get; set; }
|
||||||
|
|
||||||
public FancyZonesViewModel()
|
private Func<string, int> SendConfigMSG { get; }
|
||||||
|
|
||||||
|
private string settingsConfigFileFolder = string.Empty;
|
||||||
|
|
||||||
|
public FancyZonesViewModel(Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||||
{
|
{
|
||||||
|
settingsConfigFileFolder = configFileSubfolder;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Settings = SettingsUtils.GetSettings<FancyZonesSettings>(ModuleName);
|
Settings = SettingsUtils.GetSettings<FancyZonesSettings>(GetSettingsSubPath());
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Settings = new FancyZonesSettings();
|
Settings = new FancyZonesSettings();
|
||||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
SettingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
|
this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
|
||||||
|
|
||||||
|
this._shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
|
||||||
|
this._mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
|
||||||
|
this._overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
|
||||||
|
this._moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
|
||||||
|
this._displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
|
||||||
|
this._zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
|
||||||
|
this._appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
|
||||||
|
this._openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
|
||||||
|
this._restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
|
||||||
|
this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
|
||||||
|
this._showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
|
||||||
|
this._makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
|
||||||
|
this._highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
|
||||||
|
this._excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
|
||||||
|
this.EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
|
||||||
|
|
||||||
|
// set the callback functions value to hangle outgoing IPC message.
|
||||||
|
SendConfigMSG = ipcMSGCallBackFunc;
|
||||||
|
|
||||||
_shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
|
|
||||||
_mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
|
|
||||||
_overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
|
|
||||||
_moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
|
|
||||||
_displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
|
|
||||||
_zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
|
|
||||||
_appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
|
|
||||||
_openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
|
|
||||||
_restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
|
|
||||||
_useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
|
|
||||||
_showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
|
|
||||||
_spanZonesAcrossMonitors = Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value;
|
|
||||||
_makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
|
|
||||||
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
|
|
||||||
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
|
|
||||||
EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
|
|
||||||
string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
|
string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
|
||||||
_zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor.ToColor() : "#F5FCFF".ToColor();
|
this._zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor : "#F5FCFF";
|
||||||
|
|
||||||
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
|
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
|
||||||
_zoneBorderColor = borderColor != string.Empty ? borderColor.ToColor() : "#FFFFFF".ToColor();
|
this._zoneBorderColor = borderColor != string.Empty ? borderColor : "#FFFFFF";
|
||||||
|
|
||||||
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
|
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
|
||||||
_zoneHighlightColor = highlightColor != string.Empty ? highlightColor.ToColor() : "#0078D7".ToColor();
|
this._zoneHighlightColor = highlightColor != string.Empty ? highlightColor : "#0078D7";
|
||||||
|
|
||||||
GeneralSettings generalSettings;
|
GeneralSettings generalSettings;
|
||||||
try
|
try
|
||||||
@@ -70,7 +76,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
|
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
_isEnabled = generalSettings.Enabled.FancyZones;
|
this._isEnabled = generalSettings.Enabled.FancyZones;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isEnabled;
|
private bool _isEnabled;
|
||||||
@@ -91,9 +97,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
private int _highlightOpacity;
|
private int _highlightOpacity;
|
||||||
private string _excludedApps;
|
private string _excludedApps;
|
||||||
private HotkeySettings _editorHotkey;
|
private HotkeySettings _editorHotkey;
|
||||||
private Color _zoneInActiveColor;
|
private string _zoneInActiveColor;
|
||||||
private Color _zoneBorderColor;
|
private string _zoneBorderColor;
|
||||||
private Color _zoneHighlightColor;
|
private string _zoneHighlightColor;
|
||||||
|
|
||||||
public bool IsEnabled
|
public bool IsEnabled
|
||||||
{
|
{
|
||||||
@@ -111,7 +117,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
generalSettings.Enabled.FancyZones = value;
|
generalSettings.Enabled.FancyZones = value;
|
||||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
|
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
|
||||||
|
|
||||||
ShellPage.DefaultSndMSGCallback(snd.ToString());
|
SendConfigMSG(snd.ToString());
|
||||||
OnPropertyChanged("IsEnabled");
|
OnPropertyChanged("IsEnabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,6 +159,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetSettingsSubPath()
|
||||||
|
{
|
||||||
|
return settingsConfigFileFolder + "\\" + ModuleName;
|
||||||
|
}
|
||||||
|
|
||||||
public bool OverrideSnapHotkeys
|
public bool OverrideSnapHotkeys
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -351,7 +362,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color ZoneHighlightColor
|
public string ZoneHighlightColor
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -360,16 +371,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != _zoneHighlightColor)
|
if (!value.Equals(_zoneHighlightColor))
|
||||||
{
|
{
|
||||||
_zoneHighlightColor = value;
|
_zoneHighlightColor = value;
|
||||||
Settings.Properties.FancyzonesZoneHighlightColor.Value = ToRGBHex(value);
|
Settings.Properties.FancyzonesZoneHighlightColor.Value = value;
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color ZoneBorderColor
|
public string ZoneBorderColor
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -378,16 +389,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != _zoneBorderColor)
|
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
_zoneBorderColor = value;
|
_zoneBorderColor = value;
|
||||||
Settings.Properties.FancyzonesBorderColor.Value = ToRGBHex(value);
|
Settings.Properties.FancyzonesBorderColor.Value = value;
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color ZoneInActiveColor
|
public string ZoneInActiveColor
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -396,10 +407,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != _zoneInActiveColor)
|
if (!value.Equals(_zoneInActiveColor))
|
||||||
{
|
{
|
||||||
_zoneInActiveColor = value;
|
_zoneInActiveColor = value;
|
||||||
Settings.Properties.FancyzonesInActiveColor.Value = ToRGBHex(value);
|
Settings.Properties.FancyzonesInActiveColor.Value = value;
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,22 +481,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
private void LaunchEditor()
|
private void LaunchEditor()
|
||||||
{
|
{
|
||||||
// send message to launch the zones editor;
|
// send message to launch the zones editor;
|
||||||
ShellPage.DefaultSndMSGCallback("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
|
SendConfigMSG("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
|
||||||
}
|
|
||||||
|
|
||||||
private string ToRGBHex(Color color)
|
|
||||||
{
|
|
||||||
return "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
{
|
{
|
||||||
OnPropertyChanged(propertyName);
|
OnPropertyChanged(propertyName);
|
||||||
if (ShellPage.DefaultSndMSGCallback != null)
|
if (SendConfigMSG != null)
|
||||||
{
|
{
|
||||||
SndFancyZonesSettings outsettings = new SndFancyZonesSettings(Settings);
|
SndFancyZonesSettings outsettings = new SndFancyZonesSettings(Settings);
|
||||||
SndModuleSettings<SndFancyZonesSettings> ipcMessage = new SndModuleSettings<SndFancyZonesSettings>(outsettings);
|
SndModuleSettings<SndFancyZonesSettings> ipcMessage = new SndModuleSettings<SndFancyZonesSettings>(outsettings);
|
||||||
ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
|
SendConfigMSG(ipcMessage.ToJsonString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
// 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.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using CommonLibTest;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace ViewModelTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class FancyZones
|
||||||
|
{
|
||||||
|
public const string FancyZonesTestFolderName = "Test\\FancyZones";
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
// initialize creation of test settings file.
|
||||||
|
GeneralSettings generalSettings = new GeneralSettings();
|
||||||
|
FZConfigProperties fZConfigProperties = new FZConfigProperties();
|
||||||
|
|
||||||
|
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
|
||||||
|
SettingsUtils.SaveSettings(fZConfigProperties.ToJsonString(), FancyZonesTestFolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCleanup]
|
||||||
|
public void CleanUp()
|
||||||
|
{
|
||||||
|
// delete general settings folder created.
|
||||||
|
string generalSettings_file_name = string.Empty;
|
||||||
|
if (SettingsUtils.SettingsFolderExists(string.Empty))
|
||||||
|
{
|
||||||
|
DeleteFolder(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete fancy zones folder created.
|
||||||
|
if (SettingsUtils.SettingsFolderExists(FancyZonesTestFolderName))
|
||||||
|
{
|
||||||
|
DeleteFolder(FancyZonesTestFolderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteFolder(string powertoy)
|
||||||
|
{
|
||||||
|
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void IsEnabled_ShouldDisableModule_WhenSuccessful()
|
||||||
|
{
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||||
|
Assert.IsFalse(snd.GeneralSettings.Enabled.FancyZones);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsTrue(viewModel.IsEnabled); // check if the module is enabled.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.IsEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShiftDrag_ShouldSetValue2False_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsFalse(snd.Powertoys.FancyZones.Properties.FancyzonesShiftDrag.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsTrue(viewModel.ShiftDrag); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ShiftDrag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OverrideSnapHotkeys_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOverrideSnapHotkeys.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.OverrideSnapHotkeys); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.OverrideSnapHotkeys = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ZoneSetChangeFlashZones_ShouldSetValue2False_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMakeDraggedWindowTransparent.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.MakeDraggedWindowsTransparent); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.MakeDraggedWindowsTransparent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MouseSwitch_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMouseSwitch.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.MouseSwitch); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.MouseSwitch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DisplayChangeMoveWindows_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesDisplayChangeMoveWindows.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.DisplayChangeMoveWindows); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.DisplayChangeMoveWindows = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ZoneSetChangeMoveWindows_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesZoneSetChangeMoveWindows.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.ZoneSetChangeMoveWindows); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ZoneSetChangeMoveWindows = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AppLastZoneMoveWindows_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesAppLastZoneMoveWindows.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.AppLastZoneMoveWindows); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.AppLastZoneMoveWindows = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenWindowOnActiveMonitor_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOpenWindowOnActiveMonitor.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.OpenWindowOnActiveMonitor); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.OpenWindowOnActiveMonitor = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void RestoreSize_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesRestoreSize.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.RestoreSize); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.RestoreSize = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UseCursorPosEditorStartupScreen_ShouldSetValue2False_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.UseCursorposEditorStartupscreen.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsTrue(viewModel.UseCursorPosEditorStartupScreen); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.UseCursorPosEditorStartupScreen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShowOnAllMonitors_ShouldSetValue2True_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesShowOnAllMonitors.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.IsFalse(viewModel.ShowOnAllMonitors); // check if value was initialized to false.
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ShowOnAllMonitors = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ZoneHighlightColor_ShouldSetColorValue2White_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesZoneHighlightColor.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesZoneHighlightColor, viewModel.ZoneHighlightColor);
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ZoneHighlightColor = "#FFFFFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ZoneBorderColor_ShouldSetColorValue2White_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesBorderColor.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.AreEqual(ConfigDefaults.DefaultFancyzonesBorderColor, viewModel.ZoneBorderColor);
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ZoneBorderColor = "#FFFFFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ZoneInActiveColor_ShouldSetColorValue2White_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesInActiveColor.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesInActiveColor, viewModel.ZoneInActiveColor);
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ZoneInActiveColor = "#FFFFFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ExcludedApps_ShouldSetColorValue2White_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.AreEqual("Sample", snd.Powertoys.FancyZones.Properties.FancyzonesExcludedApps.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.AreEqual(string.Empty, viewModel.ExcludedApps);
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.ExcludedApps = "Sample";
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void HighlightOpacity_ShouldSetOpacityValueTo60_WhenSuccessful()
|
||||||
|
{
|
||||||
|
// Assert
|
||||||
|
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||||
|
{
|
||||||
|
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
|
||||||
|
Assert.AreEqual(60, snd.Powertoys.FancyZones.Properties.FancyzonesHighlightOpacity.Value);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// arrange
|
||||||
|
FancyZonesViewModel viewModel = new FancyZonesViewModel(SendMockIPCConfigMSG, FancyZonesTestFolderName);
|
||||||
|
Assert.AreEqual(50, viewModel.HighlightOpacity);
|
||||||
|
|
||||||
|
// act
|
||||||
|
viewModel.HighlightOpacity = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ToRGBHex(Color color)
|
||||||
|
{
|
||||||
|
return "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,7 +109,6 @@
|
|||||||
<Compile Include="Services\ActivationService.cs" />
|
<Compile Include="Services\ActivationService.cs" />
|
||||||
<Compile Include="Services\NavigationService.cs" />
|
<Compile Include="Services\NavigationService.cs" />
|
||||||
<Compile Include="ViewModels\Commands\ButtonClickCommand.cs" />
|
<Compile Include="ViewModels\Commands\ButtonClickCommand.cs" />
|
||||||
<Compile Include="ViewModels\FancyZonesViewModel.cs" />
|
|
||||||
<Compile Include="ViewModels\PowerLauncherViewModel.cs" />
|
<Compile Include="ViewModels\PowerLauncherViewModel.cs" />
|
||||||
<Compile Include="ViewModels\ShellViewModel.cs" />
|
<Compile Include="ViewModels\ShellViewModel.cs" />
|
||||||
<Compile Include="Views\ColorPickerPage.xaml.cs">
|
<Compile Include="Views\ColorPickerPage.xaml.cs">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Page
|
<Page
|
||||||
x:Class="Microsoft.PowerToys.Settings.UI.Views.FancyZonesPage"
|
x:Class="Microsoft.PowerToys.Settings.UI.Views.FancyZonesPage"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
|
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<viewModel:FancyZonesViewModel x:Key="eventViewModel"/>
|
|
||||||
<converters:StringFormatConverter x:Key="StringFormatConverter"/>
|
<converters:StringFormatConverter x:Key="StringFormatConverter"/>
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
@@ -173,7 +172,7 @@
|
|||||||
FontSize="16"
|
FontSize="16"
|
||||||
Margin="0,16,0,0"
|
Margin="0,16,0,0"
|
||||||
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
|
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock x:Uid="FancyZones_ZoneHighlightColor"
|
<TextBlock x:Uid="FancyZones_ZoneHighlightColor"
|
||||||
|
|||||||
@@ -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,9 +13,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
|
|
||||||
public FancyZonesPage()
|
public FancyZonesPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
this.InitializeComponent();
|
||||||
ViewModel = new FancyZonesViewModel();
|
ViewModel = new FancyZonesViewModel(ShellPage.SendDefaultIPCMessage);
|
||||||
MainView.DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user