PowerLauncherSettings unit tests (#2276)

This commit is contained in:
Tomas Agustin Raies
2020-04-26 13:15:40 -07:00
committed by GitHub
parent ca7b6f139f
commit 7ec8d02c1f
5 changed files with 383 additions and 198 deletions

View File

@@ -12,19 +12,36 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class PowerLauncherViewModel : Observable
{
private const string POWERTOYNAME = "PowerLauncher";
private PowerLauncherSettings settings;
public delegate void SendCallback(PowerLauncherSettings settings);
private readonly SendCallback callback;
public PowerLauncherViewModel()
{
if (SettingsUtils.SettingsExists(POWERTOYNAME))
if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME))
{
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);
}
else
{
settings = new PowerLauncherSettings();
}
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
var propertiesJson = JsonSerializer.Serialize(settings.properties);
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
};
}
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
{
this.settings = settings;
this.callback = callback;
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
@@ -32,17 +49,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Notify UI of property change
OnPropertyChanged(propertyName);
// Save settings to file
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
SettingsUtils.SaveSettings(JsonSerializer.Serialize(settings, options), POWERTOYNAME);
// Propagate changes to Power Launcher through IPC
var propertiesJson = JsonSerializer.Serialize(settings.properties);
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
settings.Save();
callback(settings);
}
public bool EnablePowerLauncher