[Settings Tests] Migrate General Settings tests (#5753)

* added MSTest project

* migrated general settings tests

* enabled settings tests run in the build pipeline

* added tests

* move relay command class to separate file

* added a foldername parameter for general settings view model
This commit is contained in:
Nkateko
2020-08-13 15:02:05 -07:00
committed by GitHub
parent e4ea8d2abd
commit 24d7232559
14 changed files with 725 additions and 83 deletions

View File

@@ -3,7 +3,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Views"
xmlns:viewModel="using:Microsoft.PowerToys.Settings.UI.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
@@ -14,7 +13,6 @@
<Page.Resources>
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible"/>
<converters:BoolToVisibilityConverter x:Key="VisibleIfTrueConverter"/>
<viewModel:GeneralViewModel x:Key="eventViewModel"/>
</Page.Resources>
<Grid RowSpacing="{StaticResource DefaultRowSpacing}">
@@ -56,25 +54,25 @@
<TextBlock x:Uid="Admin_Mode" FontWeight="SemiBold"
Style="{StaticResource SubtitleTextBlockStyle}"/>
<TextBlock Text="{Binding Mode=TwoWay, Path=RunningAsText, Source={StaticResource eventViewModel}}"
<TextBlock Text="{x:Bind Mode=TwoWay, Path=ViewModel.RunningAsText}"
Margin="{StaticResource SmallTopMargin}"/>
<Button x:Uid="GeneralPage_RestartAsAdmin_Button"
Margin="{StaticResource SmallTopMargin}"
Style="{StaticResource AccentButtonStyle}"
Command = "{Binding RestartElevatedButtonEventHandler, Source={StaticResource eventViewModel}}"
IsEnabled="{Binding Mode=TwoWay, Path=IsAdminButtonEnabled, Source={StaticResource eventViewModel}}"
Command = "{Binding RestartElevatedButtonEventHandler}"
IsEnabled="{Binding Mode=TwoWay, Path=IsAdminButtonEnabled}"
/>
<TextBlock x:Uid="General_RunAsAdminRequired"
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}"
Visibility="{Binding Mode=TwoWay, Path=IsElevated, Source={StaticResource eventViewModel}, Converter={StaticResource BoolToVisibilityConverter}}"
Visibility="{Binding Mode=TwoWay, Path=IsElevated, Converter={StaticResource BoolToVisibilityConverter}}"
Margin="0,24,0,-8" />
<ToggleSwitch Margin="{StaticResource SmallTopMargin}"
x:Uid="GeneralSettings_AlwaysRunAsAdminText"
IsEnabled="{Binding Mode=TwoWay, Path=IsElevated, Source={StaticResource eventViewModel}}"
IsOn="{Binding Mode=TwoWay, Path=RunElevated, Source={StaticResource eventViewModel}}"/>
IsEnabled="{Binding Mode=TwoWay, Path=IsElevated}"
IsOn="{Binding Mode=TwoWay, Path=RunElevated}"/>
<HyperlinkButton NavigateUri="https://aka.ms/powertoysDetectedElevatedHelp">
<TextBlock x:Uid="GeneralPage_ToggleSwitch_AlwaysRunElevated_Link" />
@@ -88,20 +86,20 @@
Margin="{StaticResource SmallTopMargin}">
<RadioButton x:Uid="GeneralPage_Radio_Theme_Dark"
Content="Dark"
IsChecked="{ Binding Mode=TwoWay, Path=IsDarkThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsDarkThemeRadioButtonChecked}"/>
<RadioButton x:Uid="GeneralPage_Radio_Theme_Light"
Content="Light"
IsChecked="{ Binding Mode=TwoWay, Path=IsLightThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsLightThemeRadioButtonChecked}"/>
<RadioButton x:Uid="GeneralPage_Radio_Theme_Default"
Content="System default"
IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked}"/>
</muxc:RadioButtons>
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_RunAtStartUp"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=Startup, Source={StaticResource eventViewModel}}"/>
IsOn="{Binding Mode=TwoWay, Path=Startup}"/>
@@ -109,7 +107,7 @@
Style="{StaticResource SettingsGroupTitleStyle}"/>
<StackPanel Orientation="Horizontal" Margin="{StaticResource SmallTopMargin}">
<TextBlock Text="Version: " x:Uid="General_Version" />
<HyperlinkButton NavigateUri="https://aka.ms/installpowertoys" Margin="4,-6,0,0">
<HyperlinkButton NavigateUri="https://github.com/microsoft/PowerToys/releases" Margin="4,-6,0,0">
<TextBlock Text="{x:Bind ViewModel.PowerToysVersion }" />
</HyperlinkButton>
</StackPanel>
@@ -118,13 +116,13 @@
<Button x:Uid="GeneralPage_CheckForUpdates"
Style="{StaticResource AccentButtonStyle}"
Foreground="White"
Command="{Binding CheckFoUpdatesEventHandler, Source={StaticResource eventViewModel}}"
Command="{Binding CheckFoUpdatesEventHandler}"
/>
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_AutoDownloadUpdates"
Margin="{StaticResource MediumTopMargin}"
Visibility="{Binding Mode=TwoWay, Path=IsAdmin, Source={StaticResource eventViewModel}, Converter={StaticResource VisibleIfTrueConverter}}"
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/>
Visibility="{Binding Mode=TwoWay, Path=IsAdmin, Converter={StaticResource VisibleIfTrueConverter}}"
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates}"/>
</StackPanel>
@@ -159,15 +157,15 @@
<TextBlock x:Uid="General_Repository"/>
</HyperlinkButton>
<HyperlinkButton NavigateUri="https://aka.ms/powerToysReportBug">
<HyperlinkButton NavigateUri="https://github.com/microsoft/PowerToys/issues">
<TextBlock x:Uid="GeneralPage_ReportAbug"/>
</HyperlinkButton>
<HyperlinkButton NavigateUri="https://aka.ms/powerToysRequestFeature">
<HyperlinkButton NavigateUri="https://github.com/microsoft/PowerToys/issues">
<TextBlock x:Uid="GeneralPage_RequestAFeature_URL"/>
</HyperlinkButton>
<HyperlinkButton NavigateUri=" https://go.microsoft.com/fwlink/?LinkId=521839">
<HyperlinkButton NavigateUri=" http://go.microsoft.com/fwlink/?LinkId=521839">
<TextBlock x:Uid="GeneralPage_PrivacyStatement_URL"/>
</HyperlinkButton>

View File

@@ -2,7 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Windows.ApplicationModel.Resources;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
@@ -23,10 +25,40 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// </summary>
public GeneralPage()
{
InitializeComponent();
this.InitializeComponent();
ViewModel = new GeneralViewModel();
GeneralView.DataContext = ViewModel;
// Load string resources
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
this.ViewModel = new GeneralViewModel(
loader.GetString("GeneralSettings_RunningAsAdminText"),
loader.GetString("GeneralSettings_RunningAsUserText"),
ShellPage.IsElevated,
ShellPage.IsUserAnAdmin,
UpdateUIThemeMethod,
ShellPage.SendDefaultIPCMessage,
ShellPage.SendRestartAdminIPCMessage,
ShellPage.SendCheckForUpdatesIPCMessage);
DataContext = ViewModel;
}
public int UpdateUIThemeMethod(string themeName)
{
switch (themeName)
{
case "light":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
break;
case "dark":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
break;
case "system":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
break;
}
return 0;
}
}
}

View File

@@ -61,6 +61,24 @@ namespace Microsoft.PowerToys.Settings.UI.Views
shellFrame.Navigate(typeof(GeneralPage));
}
public static int SendDefaultIPCMessage(string msg)
{
DefaultSndMSGCallback(msg);
return 0;
}
public static int SendCheckForUpdatesIPCMessage(string msg)
{
CheckForUpdatesMsgCallback(msg);
return 0;
}
public static int SendRestartAdminIPCMessage(string msg)
{
SndRestartAsAdminMsgCallback(msg);
return 0;
}
/// <summary>
/// Set Default IPC Message callback function.
/// </summary>