fix(settings): apply a theme as soon as it is selected and restore it on cancel
PLAN 5.6 asks for the theme to take effect immediately, but it was applied only on OK. Selecting a theme now previews it; OK saves it, and cancel, Escape or closing the window restores the theme the dialog opened with.
This commit is contained in:
1 parent
1ecb48316d
commit
4a88033695
5 files changed
+109
-7
No files matched your search
@@ -0,0 +1,63 @@
|
||||
using YKanBan.Storage.AppData;
|
||||
using YKanBan.ViewModels.Dialogs;
|
||||
|
||||
namespace YKanBan.Tests.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the settings dialog: the theme is previewed as soon as it is
|
||||
/// selected, saved on accept and restored on cancel.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class SettingsDialogViewModelTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void OpeningTheDialogAppliesNothing()
|
||||
{
|
||||
var applied = new List<ThemeOption>();
|
||||
|
||||
_ = new SettingsDialogViewModel(new AppConfig(), AppConfig.DefaultLanguage, applied.Add);
|
||||
|
||||
Assert.AreEqual(0, applied.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SelectingAThemeAppliesItImmediatelyWithoutSavingIt()
|
||||
{
|
||||
var config = new AppConfig();
|
||||
var applied = new List<ThemeOption>();
|
||||
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||
|
||||
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Dark));
|
||||
|
||||
CollectionAssert.AreEqual(new[] { ThemeOption.Dark }, applied);
|
||||
Assert.AreEqual(ThemeOption.FollowSystem, config.Theme);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AcceptSavesThePreviewedTheme()
|
||||
{
|
||||
var config = new AppConfig();
|
||||
var applied = new List<ThemeOption>();
|
||||
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Light));
|
||||
|
||||
dialog.Accept();
|
||||
|
||||
Assert.AreEqual(ThemeOption.Light, config.Theme);
|
||||
CollectionAssert.AreEqual(new[] { ThemeOption.Light }, applied);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CancelRestoresTheThemeTheDialogOpenedWith()
|
||||
{
|
||||
var config = new AppConfig { Theme = ThemeOption.Light };
|
||||
var applied = new List<ThemeOption>();
|
||||
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Dark));
|
||||
|
||||
dialog.Cancel();
|
||||
|
||||
Assert.AreEqual(ThemeOption.Light, config.Theme);
|
||||
CollectionAssert.AreEqual(new[] { ThemeOption.Dark, ThemeOption.Light }, applied);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user