updated header text and tests for PowerRename (#2607)

This commit is contained in:
Lavius Motileng 2020-05-05 14:28:44 -07:00 committed by GitHub
parent 462c17a0c3
commit c2adf56b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 204 additions and 11 deletions

View File

@ -15,8 +15,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
MaxMRUSize = new IntProperty();
ShowIcon = new BoolProperty();
ExtendedContextMenuOnly = new BoolProperty();
Enabled = new BoolProperty();
}
public BoolProperty Enabled { get; set; }
[JsonPropertyName("bool_persist_input")]
public BoolProperty PersistState { get; set; }

View File

@ -0,0 +1,29 @@
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 PowerRenameSettingsIPCMessage
{
[JsonPropertyName("powertoys")]
public SndPowerRenameSettings Powertoys { get; set; }
public PowerRenameSettingsIPCMessage()
{
}
public PowerRenameSettingsIPCMessage(SndPowerRenameSettings settings)
{
this.Powertoys = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@ -81,4 +81,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
}
}
}

View File

@ -12,6 +12,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
[JsonPropertyName("PowerRename")]
public PowerRenameSettings PowerRename { get; set; }
public SndPowerRenameSettings()
{
}
public SndPowerRenameSettings(PowerRenameSettings settings)
{
PowerRename = settings;

View File

@ -369,16 +369,16 @@
<value>Choose Settings color</value>
</data>
<data name="PowerRename_Toggle_EnableOnContextMenu.Header" xml:space="preserve">
<value>Show on default context menu</value>
<value>Show icon on context menu</value>
</data>
<data name="PowerRename_Toggle_EnableOnExtendedContextMenu.Header" xml:space="preserve">
<value>Only show on extended context menu (Shift + Right-click)</value>
<value>Only show the PowerRename menu item on the extended context menu (Shift + Right-click).</value>
</data>
<data name="PowerRename_Toggle_MaxDispListNum.Text" xml:space="preserve">
<value>Maximum numbers of items to show in recently used list</value>
<value>Maximum numbers of items to show in recently used list for autocomplete dropdown.</value>
</data>
<data name="PowerRename_Toggle_RestoreFlagsOnLaunch.Header" xml:space="preserve">
<value>Restore search, replace and flags values on launch from previous run</value>
<value>Restore search, replace and flags values on launch from previous run.</value>
</data>
<data name="FileEplorerPreview_ToggleSwitch_Preview_MD.Header" xml:space="preserve">
<value>Markdown Preview Handler</value>
@ -396,7 +396,7 @@
<value>Open-source notice</value>
</data>
<data name="PowerRename_Toggle_AutoComplete.Header" xml:space="preserve">
<value>Enable Auto Complete</value>
<value>Enable autocomplete and autosuggest of recently used list for autocomplete dropdown.</value>
</data>
<data name="FancyZones_BorderColor.Text" xml:space="preserve">
<value>Zone border color (Default #FFFFFF)</value>

View File

@ -75,7 +75,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
ShellPage.DefaultSndMSGCallback(snd.ToString());
_powerRenameEnabled = value;
RaisePropertyChanged();
OnPropertyChanged("IsEnabled");
}
}
}

View File

@ -50,15 +50,15 @@
IsOn="{Binding Mode=TwoWay, Path=IsEnabled}"
/>
<TextBlock x:Uid="PowerRename_ShellIntergration"
Style="{StaticResource SettingsGroupTitleStyle}"/>
<ToggleSwitch x:Uid="PowerRename_Toggle_AutoComplete"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=MRUEnabled}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"
/>
<TextBlock x:Uid="PowerRename_ShellIntergration"
Style="{StaticResource SettingsGroupTitleStyle}"/>
<ToggleSwitch x:Uid="PowerRename_Toggle_EnableOnContextMenu"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=EnabledOnContextMenu}"

View File

@ -129,6 +129,7 @@
<Compile Include="UnitTestApp.xaml.cs">
<DependentUpon>UnitTestApp.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModelTests\PowerRename.cs" />
<Compile Include="ViewModelTests\PowerPreview.cs" />
<Compile Include="ViewModelTests\ShortcutGuide.cs" />
<Compile Include="ViewModelTests\PowerLauncherViewModelTest.cs" />

View File

@ -0,0 +1,156 @@
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;
namespace ViewModelTests
{
[TestClass]
public class PowerRename
{
public const string ModuleName = "PowerRename";
public string schemaText = null;
[TestInitialize]
public void Setup()
{
// initialize creation of test settings file.
GeneralSettings generalSettings = new GeneralSettings();
PowerRenameSettings powerRename = new PowerRenameSettings();
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
SettingsUtils.SaveSettings(powerRename.ToJsonString(), powerRename.name, "power-rename-settings.json");
}
[TestCleanup]
public void CleanUp()
{
// delete folder created.
string generalSettings_file_name = string.Empty;
if (SettingsUtils.SettingsFolderExists(generalSettings_file_name))
{
DeleteFolder(generalSettings_file_name);
}
// delete folder created.
if (SettingsUtils.SettingsFolderExists(ModuleName))
{
DeleteFolder(ModuleName);
}
}
[TestMethod]
public void IsEnabled_ShouldEnableModule_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Enabled.PowerRename);
};
// act
viewModel.IsEnabled = true;
}
[TestMethod]
public void MRUEnabled_ShouldSetValue2True_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.properties.MRUEnabled.Value);
};
// act
viewModel.MRUEnabled = true;
}
[TestMethod]
public void EnabledOnContextMenu_ShouldSetValue2True_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.properties.ShowIcon.Value);
};
// act
viewModel.EnabledOnContextMenu = true;
}
[TestMethod]
public void EnabledOnContextExtendedMenu_ShouldSetValue2True_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.properties.ShowIcon.Value);
};
// act
viewModel.EnabledOnContextMenu = true;
}
[TestMethod]
public void RestoreFlagsOnLaunch_ShouldSetValue2True_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.properties.PersistState.Value);
};
// act
viewModel.RestoreFlagsOnLaunch = true;
}
[TestMethod]
public void MaxDispListNum_ShouldSetMaxSuggListTo20_WhenSuccessful()
{
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel();
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.AreEqual(20,snd.Powertoys.PowerRename.properties.MaxMRUSize.Value);
};
// act
viewModel.MaxDispListNum = 20;
}
public void DeleteFolder(string powertoy)
{
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
}
}
}