mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[Settings UI] Updated General Settings (#2676)
* updated general settings view * moved text to string resource * Update App.xaml.cs * set run-elevated as a start-up argument
This commit is contained in:
@@ -119,6 +119,7 @@
|
||||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ViewModelTests\General.cs" />
|
||||
<Compile Include="ModelsTests\HelperTest.cs" />
|
||||
<Compile Include="ViewModelTests\ImageResizer.cs" />
|
||||
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
||||
@@ -185,4 +186,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,161 @@
|
||||
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 General
|
||||
{
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
// initialize creation of test settings file.
|
||||
GeneralSettings generalSettings = new GeneralSettings();
|
||||
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
|
||||
}
|
||||
|
||||
[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(string.Empty))
|
||||
{
|
||||
DeleteFolder(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFolder(string powertoy)
|
||||
{
|
||||
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsElevated_ShouldUpdateRunasAdminStatusAttrs_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
|
||||
string runningAsUserText = "Running as user.";
|
||||
string runningAsAdminText = "Running as Adminstrator.";
|
||||
string runningAsUser_AlwaysRunAsAdminText = "Always run as administrator";
|
||||
string runningAsAdmin_AlwaysRunAsAdminText = "Always run as administrator (Restart as administrator to change this)";
|
||||
|
||||
Assert.AreEqual(runningAsUserText, viewModel.RunningAsAdminText);
|
||||
Assert.AreEqual(runningAsAdmin_AlwaysRunAsAdminText, viewModel.AlwaysRunAsAdminText);
|
||||
Assert.IsFalse(viewModel.IsElevated);
|
||||
|
||||
// Act
|
||||
viewModel.IsElevated = true;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(runningAsAdminText, viewModel.RunningAsAdminText);
|
||||
Assert.AreEqual(runningAsUser_AlwaysRunAsAdminText, viewModel.AlwaysRunAsAdminText);
|
||||
Assert.IsTrue(viewModel.IsElevated);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Startup_ShouldEnableRunOnStartUp_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
Assert.IsFalse(viewModel.Startup);
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.GeneralSettings.Startup);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.Startup = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RunElevated_ShouldEnableAlwaysRunElevated_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
Assert.IsFalse(viewModel.RunElevated);
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.GeneralSettings.RunElevated);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.RunElevated = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AutoDownloadUpdates_ShouldEnableAutoDownloadUpdates_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
Assert.IsFalse(viewModel.AutoDownloadUpdates);
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.GeneralSettings.AutoDownloadUpdates);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.AutoDownloadUpdates = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsLightThemeRadioButtonChecked_ShouldThemeToLight_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
Assert.IsFalse(viewModel.IsLightThemeRadioButtonChecked);
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.AreEqual("light", snd.GeneralSettings.Theme);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.IsLightThemeRadioButtonChecked = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsDarkThemeRadioButtonChecked_ShouldThemeToDark_WhenSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel();
|
||||
Assert.IsFalse(viewModel.IsDarkThemeRadioButtonChecked);
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.AreEqual("dark", snd.GeneralSettings.Theme);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.IsDarkThemeRadioButtonChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user