[Settings] Migrated Image Resizer Tests (#5765)

* added MSTest project

* Migrated Image Resizer Tests

* fixed links

* removed exception
This commit is contained in:
Nkateko
2020-08-18 13:43:58 -07:00
committed by GitHub
parent 8c98c7df29
commit 5e13152c73
5 changed files with 318 additions and 82 deletions

View File

@@ -2,17 +2,17 @@
x:Class="Microsoft.PowerToys.Settings.UI.Views.ImageResizerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModel="using:Microsoft.PowerToys.Settings.UI.ViewModels"
xmlns:CustomControls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:models="using:Microsoft.PowerToys.Settings.UI.Lib"
xmlns:viewModels="using:Microsoft.PowerToys.Settings.UI.Lib.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<viewModel:ImageResizerViewModel x:Key="ViewModel"/>
<!--<viewModel:ImageResizerViewModel x:Key="ViewModel"/>-->
</Page.Resources>
<Grid RowSpacing="{StaticResource DefaultRowSpacing}">
@@ -58,7 +58,7 @@
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
<ListView x:Name="ImagesSizesListView"
ItemsSource="{Binding Sizes, Mode=TwoWay, Source={StaticResource ViewModel}}"
ItemsSource="{x:Bind ViewModel.Sizes, Mode=TwoWay}"
Padding="0"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}"
SelectionMode="None">
@@ -146,16 +146,17 @@
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Percent" />
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Pixels" />
</ComboBox>
<Button x:Name="RemoveButton"
Background="Transparent"
Command = "{Binding DeleteImageSizeEventHandler, Source={StaticResource ViewModel}}"
CommandParameter="{Binding Id}"
FontFamily="Segoe MDL2 Assets"
Height="34"
Width="34"
Content="&#xE74D;"
VerticalAlignment="Center"
Margin="{StaticResource SmallTopMargin}" UseLayoutRounding="False"/>
<Button x:Name="RemoveButton"
Background="Transparent"
FontFamily="Segoe MDL2 Assets"
Height="34"
Width="34"
Content="&#xE74D;"
VerticalAlignment="Center"
Margin="{StaticResource SmallTopMargin}"
UseLayoutRounding="False"
Click="DeleteCustomSize"
CommandParameter="{Binding Id}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
@@ -169,8 +170,9 @@
Style="{StaticResource AddItemAppBarButtonStyle}"
IsEnabled="{x:Bind Mode=TwoWay, Path=ViewModel.IsEnabled}"
x:Uid="ImageResizer_AddSizeButton"
Click="AddSizeButton_Click"
Margin="{StaticResource AddItemButtonMargin}"
Command = "{Binding AddImageSizeEventHandler, Source={StaticResource ViewModel}}"
/>
</StackPanel>
@@ -179,7 +181,7 @@
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
<ComboBox x:Uid="ImageResizer_FallBackEncoderText"
SelectedIndex="{Binding Path=Encoder, Mode=TwoWay, Source={StaticResource ViewModel}}"
SelectedIndex="{x:Bind Path=ViewModel.Encoder, Mode=TwoWay}"
Width="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
@@ -194,10 +196,10 @@
<TextBlock x:Uid="ImageResizer_Encoding"
Margin="{StaticResource SmallTopMargin}"
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
<muxc:NumberBox Minimum="0"
Maximum="100"
Value="{ Binding Mode=TwoWay, Path=JPEGQualityLevel, Source={StaticResource ViewModel}}"
Value="{x:Bind Mode=TwoWay, Path=ViewModel.JPEGQualityLevel}"
Width="240"
Margin="{StaticResource HeaderTextTopMargin}"
SpinButtonPlacementMode="Compact"
@@ -206,7 +208,7 @@
/>
<ComboBox x:Uid="ImageResizer_PNGInterlacing"
SelectedIndex="{ Binding Mode=TwoWay, Path=PngInterlaceOption, Source={StaticResource ViewModel}}"
SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.PngInterlaceOption}"
Width="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
@@ -216,7 +218,7 @@
</ComboBox>
<ComboBox x:Uid="ImageResizer_TIFFCompression"
SelectedIndex="{ Binding Mode=TwoWay, Path=TiffCompressOption, Source={StaticResource ViewModel}}"
SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.TiffCompressOption}"
Width="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
@@ -293,7 +295,7 @@
<CheckBox x:Uid="ImageResizer_UseOriginalDate"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}"
Margin="{StaticResource SmallTopMargin}"
IsChecked="{Binding Mode=TwoWay, Path=KeepDateModified, Source={StaticResource ViewModel}}"/>
IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.KeepDateModified}"/>
</StackPanel>
<RelativePanel x:Name="SidePanel"
@@ -318,7 +320,7 @@
RelativePanel.Below="DescriptionPanel">
<Image Source="ms-appx:///Assets/Modules/ImageResizer.png" />
</Border>
<StackPanel x:Name="LinksPanel"
Margin="0,1,0,0"
RelativePanel.Below="AboutImage"

View File

@@ -2,21 +2,48 @@
// 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 System;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class ImageResizerPage : Page
{
private ImageResizerViewModel ViewModel { get; set; }
public ImageResizerViewModel ViewModel { get; set; }
public ImageResizerPage()
{
InitializeComponent();
ViewModel = new ImageResizerViewModel();
ViewModel = new ImageResizerViewModel(ShellPage.SendDefaultIPCMessage);
DataContext = ViewModel;
}
public void DeleteCustomSize(object sender, RoutedEventArgs e)
{
try
{
Button deleteRowButton = (Button)sender;
int rowNum = int.Parse(deleteRowButton.CommandParameter.ToString());
ViewModel.DeleteImageSize(rowNum);
}
catch (Exception exp)
{
}
}
private void AddSizeButton_Click(object sender, RoutedEventArgs e)
{
try
{
ViewModel.AddRow();
}
catch (Exception exp)
{
}
}
}
}