[Settings V2] Upated Fancy Zone and Shortcut Guid default values. (#2786)

* upated Fancy Zone and Shortcut Guid default values.

* upated fz tests
This commit is contained in:
Lavius Motileng 2020-05-08 08:22:57 -07:00 committed by GitHub
parent dad65998cc
commit 1ab0a5182f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 425 additions and 32 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
@ -9,23 +10,32 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
public FZConfigProperties()
{
this.FancyzonesShiftDrag = new BoolProperty();
this.FancyzonesMouseSwitch = new BoolProperty();
this.FancyzonesShiftDrag = new BoolProperty(true);
this.FancyzonesOverrideSnapHotkeys = new BoolProperty();
this.FancyzonesMouseSwitch = new BoolProperty();
this.FancyzonesMoveWindowsAcrossMonitors = new BoolProperty();
this.FancyzonesDisplayChangeMoveWindows = new BoolProperty();
this.FancyzonesZoneSetChangeMoveWindows = new BoolProperty();
this.FancyzonesVirtualDesktopChangeMoveWindows = new BoolProperty();
this.FancyzonesAppLastZoneMoveWindows = new BoolProperty();
this.UseCursorposEditorStartupscreen = new BoolProperty();
this.UseCursorposEditorStartupscreen = new BoolProperty(true);
this.FancyzonesShowOnAllMonitors = new BoolProperty();
this.FancyzonesZoneHighlightColor = new StringProperty("#F5FCFF");
this.FancyzonesHighlightOpacity = new IntProperty(50);
this.FancyzonesEditorHotkey = new KeyBoardKeysProperty(
new HotkeySettings()
{
Win = true,
Ctrl = false,
Alt = false,
Shift = false,
Key = "`",
Code = 192,
});
this.FancyzonesMakeDraggedWindowTransparent = new BoolProperty();
this.FancyzonesZoneHighlightColor = new StringProperty();
this.FancyzonesHighlightOpacity = new IntProperty();
this.FancyzonesEditorHotkey = new KeyBoardKeysProperty();
this.FancyzonesExcludedApps = new StringProperty();
this.FancyzonesInActiveColor = new StringProperty();
this.FancyzonesBorderColor = new StringProperty();
this.FancyzonesInActiveColor = new StringProperty("#F5FCFF");
this.FancyzonesBorderColor = new StringProperty("#F5FCFF");
}
[JsonPropertyName("fancyzones_shiftDrag")]
@ -78,5 +88,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
[JsonPropertyName("fancyzones_zoneColor")]
public StringProperty FancyzonesInActiveColor { get; set; }
// converts the current to a json string.
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class FancyZonesSettingsIPCMessage
{
[JsonPropertyName("powertoys")]
public SndFancyZonesSettings Powertoys { get; set; }
public FancyZonesSettingsIPCMessage()
{
}
public FancyZonesSettingsIPCMessage(SndFancyZonesSettings settings)
{
this.Powertoys = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@ -20,6 +20,16 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.Code = 0;
}
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, string key, int code)
{
Win = win;
Ctrl = ctrl;
Alt = alt;
Shift = shift;
Key = key;
Code = code;
}
[JsonPropertyName("win")]
public bool Win { get; set; }

View File

@ -16,6 +16,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.Value = new HotkeySettings();
}
public KeyBoardKeysProperty(HotkeySettings hkSettings)
{
this.Value = hkSettings;
}
[JsonPropertyName("value")]
public HotkeySettings Value { get; set; }
}

View File

@ -14,9 +14,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
public ShortcutGuideProperties()
{
OverlayOpacity = new IntProperty();
PressTime = new IntProperty();
Theme = new StringProperty();
OverlayOpacity = new IntProperty(90);
PressTime = new IntProperty(900);
Theme = new StringProperty("light");
}
[JsonPropertyName("overlay_opacity")]

View File

@ -10,6 +10,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
public FancyZonesSettings FancyZones { get; set; }
public SndFancyZonesSettings()
{
}
public SndFancyZonesSettings(FancyZonesSettings settings)
{
this.FancyZones = settings;

View File

@ -112,7 +112,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(snd.ToString());
RaisePropertyChanged();
OnPropertyChanged("IsEnabled");
}
}
}
@ -387,26 +387,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
/*
public int EditorHotkey
{
get
{
return _editorHotkey;
}
set
{
if (value != _editorHotkey)
{
_editorHotkey = value;
Settings.Properties.FancyzonesHighlightOpacity.Value = value;
RaisePropertyChanged();
}
}
}
*/
public HotkeySettings EditorHotkey
{
get

View File

@ -119,6 +119,7 @@
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
</ItemGroup>
<ItemGroup>
<Compile Include="ViewModelTests\FancyZones.cs" />
<Compile Include="ViewModelTests\General.cs" />
<Compile Include="ModelsTests\HelperTest.cs" />
<Compile Include="ViewModelTests\ImageResizer.cs" />

View File

@ -0,0 +1,346 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Windows.UI;
namespace ViewModelTests
{
[TestClass]
public class FancyZones
{
public const string ModuleName = "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(), ModuleName);
}
[TestCleanup]
public void CleanUp()
{
// delete folder created.
string generalSettings_file_name = string.Empty;
if (SettingsUtils.SettingsFolderExists(generalSettings_file_name))
{
DeleteFolder(generalSettings_file_name);
}
if (SettingsUtils.SettingsFolderExists(ModuleName))
{
DeleteFolder(ModuleName);
}
}
public void DeleteFolder(string powertoy)
{
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
}
[TestMethod]
public void IsEnabled_ShouldDisableModule_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsTrue(viewModel.IsEnabled); // check if the module is enabled.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsFalse(snd.GeneralSettings.Enabled.FancyZones);
};
// act
viewModel.IsEnabled = false;
}
[TestMethod]
public void ShiftDrag_ShouldSetValue2False_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsTrue(viewModel.ShiftDrag); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsFalse(snd.Powertoys.FancyZones.Properties.FancyzonesShiftDrag.Value);
};
// act
viewModel.ShiftDrag = false;
}
[TestMethod]
public void OverrideSnapHotkeys_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.OverrideSnapHotkeys); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOverrideSnapHotkeys.Value);
};
// act
viewModel.OverrideSnapHotkeys = true;
}
[TestMethod]
public void ZoneSetChangeFlashZones_ShouldSetValue2False_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.MakeDraggedWindowsTransparent); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMakeDraggedWindowTransparent.Value);
};
// act
viewModel.MakeDraggedWindowsTransparent = true;
}
[TestMethod]
public void MouseSwitch_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.MouseSwitch); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMouseSwitch.Value);
};
// act
viewModel.MouseSwitch = true;
}
[TestMethod]
public void DisplayChangeMoveWindows_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.DisplayChangeMoveWindows); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesDisplayChangeMoveWindows.Value);
};
// act
viewModel.DisplayChangeMoveWindows = true;
}
[TestMethod]
public void ZoneSetChangeMoveWindows_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.ZoneSetChangeMoveWindows); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesZoneSetChangeMoveWindows.Value);
};
// act
viewModel.ZoneSetChangeMoveWindows = true;
}
[TestMethod]
public void VirtualDesktopChangeMoveWindows_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.VirtualDesktopChangeMoveWindows); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesVirtualDesktopChangeMoveWindows.Value);
};
// act
viewModel.VirtualDesktopChangeMoveWindows = true;
}
[TestMethod]
public void AppLastZoneMoveWindows_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.AppLastZoneMoveWindows); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesAppLastZoneMoveWindows.Value);
};
// act
viewModel.AppLastZoneMoveWindows = true;
}
[TestMethod]
public void UseCursorPosEditorStartupScreen_ShouldSetValue2False_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsTrue(viewModel.UseCursorPosEditorStartupScreen); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.UseCursorposEditorStartupscreen.Value);
};
// act
viewModel.UseCursorPosEditorStartupScreen = true;
}
[TestMethod]
public void ShowOnAllMonitors_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.ShowOnAllMonitors); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesShowOnAllMonitors.Value);
};
// act
viewModel.ShowOnAllMonitors = true;
}
[TestMethod]
public void ZoneHighlightColor_ShouldSetColorValue2White_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.AreEqual("#F5FCFF", ToRGBHex(viewModel.ZoneHighlightColor));
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#E1E1E1", snd.Powertoys.FancyZones.Properties.FancyzonesZoneHighlightColor.Value);
};
// act
viewModel.ZoneHighlightColor = Color.FromArgb(0, 225,225,225);
}
[TestMethod]
public void ZoneBorderColor_ShouldSetColorValue2White_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.AreEqual("#F5FCFF", ToRGBHex(viewModel.ZoneBorderColor));
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#E1E1E1", snd.Powertoys.FancyZones.Properties.FancyzonesBorderColor.Value);
};
// act
viewModel.ZoneBorderColor = Color.FromArgb(0, 225, 225, 225);
}
[TestMethod]
public void ZoneInActiveColor_ShouldSetColorValue2White_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.AreEqual("#F5FCFF", ToRGBHex(viewModel.ZoneInActiveColor));
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#E1E1E1", snd.Powertoys.FancyZones.Properties.FancyzonesInActiveColor.Value);
};
// act
viewModel.ZoneInActiveColor = Color.FromArgb(0, 225, 225, 225);
}
[TestMethod]
public void ExcludedApps_ShouldSetColorValue2White_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.AreEqual("", viewModel.ExcludedApps);
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("Sample", snd.Powertoys.FancyZones.Properties.FancyzonesExcludedApps.Value);
};
// act
viewModel.ExcludedApps = "Sample";
}
[TestMethod]
public void HighlightOpacity_ShouldSetOpacityValueTo60_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.AreEqual(50, viewModel.HighlightOpacity);
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual(60, snd.Powertoys.FancyZones.Properties.FancyzonesHighlightOpacity.Value);
};
// act
viewModel.HighlightOpacity = 60;
}
private String ToRGBHex(Color color)
{
return "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
}
}
}

View File

@ -74,6 +74,7 @@ namespace ViewModelTests
{
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
Assert.AreEqual(1, viewModel.ThemeIndex);
// Assert
// Initilize mock function of sending IPC message.
@ -92,6 +93,7 @@ namespace ViewModelTests
{
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
Assert.AreEqual(900, viewModel.PressTime);
// Assert
// Initilize mock function of sending IPC message.
@ -110,6 +112,7 @@ namespace ViewModelTests
{
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel();
Assert.AreEqual(90, viewModel.OverlayOpacity);
// Assert
// Initilize mock function of sending IPC message.