Skip to content

Commit

Permalink
Updating UI tests
Browse files Browse the repository at this point in the history
Updated new XAMLTest library
Added DeciamlUpDown tests
  • Loading branch information
Keboo committed Nov 7, 2024
1 parent 946a7fa commit fc6d306
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Directory.packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
<PackageVersion Include="XAMLTest" Version="1.2.1" />
<PackageVersion Include="XAMLTest" Version="1.0.0-ci569" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageVersion Include="Xunit.StaFact" Version="1.1.11" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/MaterialDesignThemes.Wpf/DecimalUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace MaterialDesignThemes.Wpf;

public class DecimalUpDown
#if NET8_0_OR_GREATER
: UpDownBase2<decimal>
: UpDownBase<decimal>
#else
: UpDownBase2<decimal, DecimalArithmetic>
: UpDownBase<decimal, DecimalArithmetic>
#endif
{
static DecimalUpDown()
Expand Down
4 changes: 2 additions & 2 deletions src/MaterialDesignThemes.Wpf/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace MaterialDesignThemes.Wpf;

public class NumericUpDown
#if NET8_0_OR_GREATER
: UpDownBase2<int>
: UpDownBase<int>
#else
: UpDownBase2<int, IntArithmetic>
: UpDownBase<int, IntArithmetic>
#endif
{
static NumericUpDown()
Expand Down
14 changes: 6 additions & 8 deletions src/MaterialDesignThemes.Wpf/UpDownBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ namespace MaterialDesignThemes.Wpf;


#if NET8_0_OR_GREATER

using System.Numerics;
public class UpDownBase2<T> : UpDownBase
public class UpDownBase<T> : UpDownBase
where T : INumber<T>, IMinMaxValue<T>
{
private static readonly Type SelfType = typeof(UpDownBase2<T>);
private static readonly Type SelfType = typeof(UpDownBase<T>);

private static UpDownBase2<T> ToUpDownBase(DependencyObject dependencyObject) => (UpDownBase2<T>)dependencyObject;
private static UpDownBase<T> ToUpDownBase(DependencyObject dependencyObject) => (UpDownBase<T>)dependencyObject;

private static T MinValue => T.MinValue;
private static T MaxValue => T.MaxValue;
Expand All @@ -25,13 +24,13 @@ private static bool TryParse(string text, IFormatProvider? formatProvider, out T
=> T.TryParse(text, formatProvider, out value);
private static int Compare(T value1, T value2) => value1.CompareTo(value2);
#else
public class UpDownBase2<T, TArithmetic> : UpDownBase
public class UpDownBase<T, TArithmetic> : UpDownBase
where TArithmetic : IArithmetic<T>, new()
{
private static readonly Type SelfType = typeof(UpDownBase2<T, TArithmetic>);
private static readonly Type SelfType = typeof(UpDownBase<T, TArithmetic>);
private static readonly TArithmetic _arithmetic = new();

private static UpDownBase2<T, TArithmetic> ToUpDownBase(DependencyObject dependencyObject) => (UpDownBase2<T, TArithmetic>)dependencyObject;
private static UpDownBase<T, TArithmetic> ToUpDownBase(DependencyObject dependencyObject) => (UpDownBase<T, TArithmetic>)dependencyObject;

private static T MinValue => _arithmetic.MinValue();
private static T MaxValue => _arithmetic.MaxValue();
Expand All @@ -43,7 +42,6 @@ public class UpDownBase2<T, TArithmetic> : UpDownBase
private static bool TryParse(string text, IFormatProvider? formatProvider, out T? value)
=> _arithmetic.TryParse(text, formatProvider, out value);
private static int Compare(T value1, T value2) => _arithmetic.Compare(value1, value2);

#endif

#region DependencyProperties
Expand Down
2 changes: 1 addition & 1 deletion tests/MaterialDesignThemes.UITests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: GenerateHelpers(typeof(AutoSuggestBox))]
[assembly: GenerateHelpers(typeof(ColorPicker))]
//[assembly: GenerateHelpers(typeof(DecimalUpDown))]
[assembly: GenerateHelpers(typeof(DecimalUpDown))]
[assembly: GenerateHelpers(typeof(DialogHost))]
[assembly: GenerateHelpers(typeof(DrawerHost))]
[assembly: GenerateHelpers(typeof(NumericUpDown))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace MaterialDesignThemes.UITests.WPF.UpDownControls;

public class DecimalUpDownTests(ITestOutputHelper output) : TestBase(output)
{
[Fact]
public async Task NumericButtons_IncreaseAndDecreaseValue()
{
await using var recorder = new TestRecorder(App);

var numericUpDown = await LoadXaml<DecimalUpDown>("""
<materialDesign:DecimalUpDown Value="1" />
""");
var plusButton = await numericUpDown.GetElement<RepeatButton>("PART_IncreaseButton");
var minusButton = await numericUpDown.GetElement<RepeatButton>("PART_DecreaseButton");
var textBox = await numericUpDown.GetElement<TextBox>("PART_TextBox");

Assert.Equal("1", await textBox.GetText());
Assert.Equal(1, await numericUpDown.GetValue());

await plusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("2", await textBox.GetText());
Assert.Equal(2, await numericUpDown.GetValue());
});

await minusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("1", await textBox.GetText());
Assert.Equal(1, await numericUpDown.GetValue());
});
}

[Fact]
public async Task NumericButtons_WithMaximum_DisablesPlusButton()
{
await using var recorder = new TestRecorder(App);

var numericUpDown = await LoadXaml<DecimalUpDown>("""
<materialDesign:DecimalUpDown Value="1" Maximum="2" />
""");
var plusButton = await numericUpDown.GetElement<RepeatButton>("PART_IncreaseButton");
var minusButton = await numericUpDown.GetElement<RepeatButton>("PART_DecreaseButton");
var textBox = await numericUpDown.GetElement<TextBox>("PART_TextBox");

await plusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("2", await textBox.GetText());
Assert.Equal(2, await numericUpDown.GetValue());
});

Assert.False(await plusButton.GetIsEnabled());

await minusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("1", await textBox.GetText());
Assert.Equal(1, await numericUpDown.GetValue());
});

Assert.True(await plusButton.GetIsEnabled());
}

[Fact]
public async Task NumericButtons_WithMinimum_DisablesMinusButton()
{
await using var recorder = new TestRecorder(App);

var numericUpDown = await LoadXaml<DecimalUpDown>("""
<materialDesign:DecimalUpDown Value="2" Minimum="1" />
""");
var plusButton = await numericUpDown.GetElement<RepeatButton>("PART_IncreaseButton");
var minusButton = await numericUpDown.GetElement<RepeatButton>("PART_DecreaseButton");
var textBox = await numericUpDown.GetElement<TextBox>("PART_TextBox");

await minusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("1", await textBox.GetText());
Assert.Equal(1, await numericUpDown.GetValue());
});

Assert.False(await minusButton.GetIsEnabled());

await plusButton.LeftClick();
await Wait.For(async () =>
{
Assert.Equal("2", await textBox.GetText());
Assert.Equal(2, await numericUpDown.GetValue());
});

Assert.True(await minusButton.GetIsEnabled());
}

[Fact]
public async Task MaxAndMinAssignments_CoerceValueToBeInRange()
{
await using var recorder = new TestRecorder(App);

var numericUpDown = await LoadXaml<DecimalUpDown>("""
<materialDesign:DecimalUpDown Value="2" />
""");

await numericUpDown.SetMaximum(1);
Assert.Equal(1, await numericUpDown.GetValue());

await numericUpDown.SetMinimum(3);
Assert.Equal(3, await numericUpDown.GetValue());
Assert.Equal(3, await numericUpDown.GetMaximum());

await numericUpDown.SetMaximum(2);
Assert.Equal(3, await numericUpDown.GetValue());
Assert.Equal(3, await numericUpDown.GetMinimum());
Assert.Equal(3, await numericUpDown.GetMaximum());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace MaterialDesignThemes.UITests.WPF.NumericUpDowns;
namespace MaterialDesignThemes.UITests.WPF.UpDownControls;


public class NumericUpDownTests(ITestOutputHelper output) : TestBase(output)
{
Expand Down

0 comments on commit fc6d306

Please sign in to comment.