mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Settings] Adding Tests to Verify Backward Compatibility (#6161)
* compare config files * create settings files * updated path check * reverted color picker changes * added test files * removed settings uralted files * Modifying directory structure and adding properties for backcompat test. * Updating Unit test to use mock repositories. 1) BackCompatTestProperties exposes mock repository implementation because SettingsRepository is a singleton, and settings utils isn't typed. 2) BackCompatTestProperties, encapsulates logic to verify that the correct file was read from. 3) Validating each file is read twice. Once by the original file, and once via the view model. * Adding 18.2 settings files. * Fix compiler errors from latest merge * Adding v0.19.2 test files. * Adding in 0.20.1 settings. Removing 0.20.2 (as this was a dev build number) * Adding settings tests for 22.1 * General Settings should update version when they don't match * Adding v0.22.0 files * Removing not settings related files from TestData for PT Run 21.1 * Referencing module name as *Settings.ModuleName in tests. Except for ImageResizer * Using ImageResizerSettings to use Settings for the module name. * Setting AllPlugins to empty list in case PluginManager.Save/Load/ReloadData is called before plugins are loaded * Fixing fxcop errors * using named parameters as per review feedback Co-authored-by: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com>
This commit is contained in:
@@ -5,7 +5,11 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using Moq;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using System.Globalization;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
@@ -37,6 +41,49 @@ namespace ViewModelTests
|
||||
new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the original settings files were modified.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[DataRow("v0.18.2", "settings.json")]
|
||||
[DataRow("v0.19.2", "settings.json")]
|
||||
[DataRow("v0.20.1", "settings.json")]
|
||||
[DataRow("v0.21.1", "settings.json")]
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerLauncherSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
PowerLauncherSettings originalSettings = mockSettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG, 32);
|
||||
|
||||
// Verifiy that the old settings persisted
|
||||
Assert.AreEqual(originalGeneralSettings.Enabled.PowerLauncher, viewModel.EnablePowerLauncher);
|
||||
Assert.AreEqual(originalSettings.Properties.ClearInputOnLaunch, viewModel.ClearInputOnLaunch);
|
||||
Assert.AreEqual(originalSettings.Properties.CopyPathLocation.ToString(), viewModel.CopyPathLocation.ToString());
|
||||
Assert.AreEqual(originalSettings.Properties.DisableDriveDetectionWarning, viewModel.DisableDriveDetectionWarning);
|
||||
Assert.AreEqual(originalSettings.Properties.IgnoreHotkeysInFullscreen, viewModel.IgnoreHotkeysInFullScreen);
|
||||
Assert.AreEqual(originalSettings.Properties.MaximumNumberOfResults, viewModel.MaximumNumberOfResults);
|
||||
Assert.AreEqual(originalSettings.Properties.OpenPowerLauncher.ToString(), viewModel.OpenPowerLauncher.ToString());
|
||||
Assert.AreEqual(originalSettings.Properties.OverrideWinkeyR, viewModel.OverrideWinRKey);
|
||||
Assert.AreEqual(originalSettings.Properties.OverrideWinkeyS, viewModel.OverrideWinSKey);
|
||||
Assert.AreEqual(originalSettings.Properties.SearchResultPreference, viewModel.SearchResultPreference);
|
||||
Assert.AreEqual(originalSettings.Properties.SearchTypePreference, viewModel.SearchTypePreference);
|
||||
|
||||
//Verify that the stub file was used
|
||||
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerLauncherSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SearchPreferenceShouldUpdatePreferences()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user