Skip to content

Commit

Permalink
NumberBox: Heaps of bug fixes (#1618)
Browse files Browse the repository at this point in the history
* Many fixes.
  • Loading branch information
teaP authored Nov 19, 2019
1 parent c9ea0e2 commit 6ae29b7
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 79 deletions.
35 changes: 29 additions & 6 deletions dev/Generated/NumberBox.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CppWinRTActivatableClassWithDPFactory(NumberBox)
GlobalDependencyProperty NumberBoxProperties::s_AcceptsCalculationProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_BasicValidationModeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderTemplateProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HyperScrollEnabledProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MaximumProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MinimumProperty{ nullptr };
Expand Down Expand Up @@ -57,10 +58,21 @@ void NumberBoxProperties::EnsureProperties()
s_HeaderProperty =
InitializeDependencyProperty(
L"Header",
winrt::name_of<winrt::hstring>(),
winrt::name_of<winrt::IInspectable>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<winrt::hstring>::BoxedDefaultValue(),
ValueHelper<winrt::IInspectable>::BoxedDefaultValue(),
nullptr);
}
if (!s_HeaderTemplateProperty)
{
s_HeaderTemplateProperty =
InitializeDependencyProperty(
L"HeaderTemplate",
winrt::name_of<winrt::DataTemplate>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<winrt::DataTemplate>::BoxedDefaultValue(),
nullptr);
}
if (!s_HyperScrollEnabledProperty)
Expand Down Expand Up @@ -180,6 +192,7 @@ void NumberBoxProperties::ClearProperties()
s_AcceptsCalculationProperty = nullptr;
s_BasicValidationModeProperty = nullptr;
s_HeaderProperty = nullptr;
s_HeaderTemplateProperty = nullptr;
s_HyperScrollEnabledProperty = nullptr;
s_MaximumProperty = nullptr;
s_MinimumProperty = nullptr;
Expand Down Expand Up @@ -278,14 +291,24 @@ winrt::NumberBoxBasicValidationMode NumberBoxProperties::BasicValidationMode()
return ValueHelper<winrt::NumberBoxBasicValidationMode>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_BasicValidationModeProperty));
}

void NumberBoxProperties::Header(winrt::hstring const& value)
void NumberBoxProperties::Header(winrt::IInspectable const& value)
{
static_cast<NumberBox*>(this)->SetValue(s_HeaderProperty, ValueHelper<winrt::IInspectable>::BoxValueIfNecessary(value));
}

winrt::IInspectable NumberBoxProperties::Header()
{
return ValueHelper<winrt::IInspectable>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_HeaderProperty));
}

void NumberBoxProperties::HeaderTemplate(winrt::DataTemplate const& value)
{
static_cast<NumberBox*>(this)->SetValue(s_HeaderProperty, ValueHelper<winrt::hstring>::BoxValueIfNecessary(value));
static_cast<NumberBox*>(this)->SetValue(s_HeaderTemplateProperty, ValueHelper<winrt::DataTemplate>::BoxValueIfNecessary(value));
}

winrt::hstring NumberBoxProperties::Header()
winrt::DataTemplate NumberBoxProperties::HeaderTemplate()
{
return ValueHelper<winrt::hstring>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_HeaderProperty));
return ValueHelper<winrt::DataTemplate>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_HeaderTemplateProperty));
}

void NumberBoxProperties::HyperScrollEnabled(bool value)
Expand Down
9 changes: 7 additions & 2 deletions dev/Generated/NumberBox.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ class NumberBoxProperties
void BasicValidationMode(winrt::NumberBoxBasicValidationMode const& value);
winrt::NumberBoxBasicValidationMode BasicValidationMode();

void Header(winrt::hstring const& value);
winrt::hstring Header();
void Header(winrt::IInspectable const& value);
winrt::IInspectable Header();

void HeaderTemplate(winrt::DataTemplate const& value);
winrt::DataTemplate HeaderTemplate();

void HyperScrollEnabled(bool value);
bool HyperScrollEnabled();
Expand Down Expand Up @@ -51,6 +54,7 @@ class NumberBoxProperties
static winrt::DependencyProperty AcceptsCalculationProperty() { return s_AcceptsCalculationProperty; }
static winrt::DependencyProperty BasicValidationModeProperty() { return s_BasicValidationModeProperty; }
static winrt::DependencyProperty HeaderProperty() { return s_HeaderProperty; }
static winrt::DependencyProperty HeaderTemplateProperty() { return s_HeaderTemplateProperty; }
static winrt::DependencyProperty HyperScrollEnabledProperty() { return s_HyperScrollEnabledProperty; }
static winrt::DependencyProperty MaximumProperty() { return s_MaximumProperty; }
static winrt::DependencyProperty MinimumProperty() { return s_MinimumProperty; }
Expand All @@ -65,6 +69,7 @@ class NumberBoxProperties
static GlobalDependencyProperty s_AcceptsCalculationProperty;
static GlobalDependencyProperty s_BasicValidationModeProperty;
static GlobalDependencyProperty s_HeaderProperty;
static GlobalDependencyProperty s_HeaderTemplateProperty;
static GlobalDependencyProperty s_HyperScrollEnabledProperty;
static GlobalDependencyProperty s_MaximumProperty;
static GlobalDependencyProperty s_MinimumProperty;
Expand Down
126 changes: 120 additions & 6 deletions dev/NumberBox/InteractionTests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ public void UpDownTest()
}
}

[TestMethod]
public void ValueTextTest()
{
using (var setup = new TestSetupHelper("NumberBox Tests"))
{
RangeValueSpinner numBox = FindElement.ByName<RangeValueSpinner>("TestNumberBox");

Log.Comment("Verify that focusing the NumberBox selects the text");
numBox.SetFocus();
Wait.ForIdle();
Wait.ForSeconds(3);
Edit edit = FindTextBox(numBox);
Verify.AreEqual("0", edit.GetTextSelection());

Log.Comment("Verify that setting the value through UIA changes the textbox text");
numBox.SetValue(10);
Wait.ForIdle();
Verify.AreEqual("10", edit.GetText());

Log.Comment("Verify that setting the text programmatically changes the value and textbox text");
Button button = FindElement.ByName<Button>("SetTextButton");
button.InvokeAndWait();
Verify.AreEqual(15, numBox.Value);
Verify.AreEqual("15", edit.GetText());

Log.Comment("Verify that even if the value doesn't change, the textbox text is updated");
EnterText(numBox, " 15 ");
Verify.AreEqual("15", edit.GetText());
}
}

[TestMethod]
public void MinMaxTest()
{
Expand All @@ -111,6 +142,9 @@ public void MinMaxTest()
Check("MaxCheckBox");

RangeValueSpinner numBox = FindElement.ByName<RangeValueSpinner>("TestNumberBox");
Verify.AreEqual(0, numBox.Minimum);
Verify.AreEqual(100, numBox.Maximum);

numBox.SetValue(10);
Wait.ForIdle();

Expand All @@ -124,8 +158,22 @@ public void MinMaxTest()
Verify.AreEqual(100, numBox.Value);

Log.Comment("Changing Max to 90; verify value also changes to 90");
EnterText(FindElement.ByName<RangeValueSpinner>("MaxNumberBox"), "90");
RangeValueSpinner maxBox = FindElement.ByName<RangeValueSpinner>("MaxNumberBox");
EnterText(maxBox, "90");
Verify.AreEqual(90, numBox.Value);

Log.Comment("Verify that setting the minimum above the maximum changes the maximum");
RangeValueSpinner minBox = FindElement.ByName<RangeValueSpinner>("MinNumberBox");
EnterText(minBox, "200");
Verify.AreEqual(200, numBox.Minimum);
Verify.AreEqual(200, numBox.Maximum);
Verify.AreEqual(200, numBox.Value);

Log.Comment("Verify that setting the maximum below the minimum changes the minimum");
EnterText(maxBox, "150");
Verify.AreEqual(150, numBox.Minimum);
Verify.AreEqual(150, numBox.Maximum);
Verify.AreEqual(150, numBox.Value);
}
}

Expand All @@ -142,21 +190,26 @@ public void BasicKeyboardTest()
Wait.ForIdle();
Verify.AreEqual(8, numBox.Value);

Log.Comment("Verify that whitespace around a number still evaluates to the number");
EnterText(numBox, " 75 ", true);
Wait.ForIdle();
Verify.AreEqual(75, numBox.Value);

Log.Comment("Verify that pressing escape cancels entered text");
EnterText(numBox, "3", false);
KeyboardHelper.PressKey(Key.Escape);
Wait.ForIdle();
Verify.AreEqual(8, numBox.Value);
Verify.AreEqual(75, numBox.Value);

Log.Comment("Verify that pressing up arrow increases the value");
KeyboardHelper.PressKey(Key.Up);
Wait.ForIdle();
Verify.AreEqual(9, numBox.Value);
Verify.AreEqual(76, numBox.Value);

Log.Comment("Verify that pressing down arrow decreases the value");
KeyboardHelper.PressKey(Key.Down);
Wait.ForIdle();
Verify.AreEqual(8, numBox.Value);
Verify.AreEqual(75, numBox.Value);
}
}

Expand Down Expand Up @@ -217,12 +270,16 @@ public void CustomFormatterTest()
Button button = FindElement.ByName<Button>("CustomFormatterButton");
button.InvokeAndWait();

Verify.AreEqual("8.00", edit.GetText());
Verify.AreEqual("8,00", edit.GetText());

Log.Comment("Verify that using a formatter with a different decimal symbol works as expected.");
EnterText(numBox, "7,45");
Verify.AreEqual(7.45, numBox.Value);
}
}

[TestMethod]
public void CoersionTest()
public void ValidationDisabledTest()
{
using (var setup = new TestSetupHelper("NumberBox Tests"))
{
Expand All @@ -245,6 +302,63 @@ public void CoersionTest()
}
}

[TestMethod]
public void ValueChangedTest()
{
using (var setup = new TestSetupHelper("NumberBox Tests"))
{
RangeValueSpinner numBox = FindElement.ByName<RangeValueSpinner>("TestNumberBox");

TextBlock newValueTextBlock = FindElement.ByName<TextBlock>("NewValueTextBox");
TextBlock oldValueTextBlock = FindElement.ByName<TextBlock>("OldValueTextBox");
TextBlock textTextBlock = FindElement.ByName<TextBlock>("TextTextBox");

Check("MinCheckBox");
Check("MaxCheckBox");

Log.Comment("Verify that entering a new number fires ValueChanged event.");
EnterText(numBox, "12");
Verify.AreEqual("12", textTextBlock.GetText());
Verify.AreEqual("12", newValueTextBlock.GetText());
Verify.AreEqual("0", oldValueTextBlock.GetText());

Log.Comment("Verify that setting value through UIA fires ValueChanged event.");
Button button = FindElement.ByName<Button>("SetValueButton");
button.InvokeAndWait();
Verify.AreEqual("42", textTextBlock.GetText());
Verify.AreEqual("42", newValueTextBlock.GetText());
Verify.AreEqual("12", oldValueTextBlock.GetText());

Log.Comment("Verify that setting value below min gives proper values.");
EnterText(numBox, "-5");
Verify.AreEqual("0", textTextBlock.GetText());
Verify.AreEqual("0", newValueTextBlock.GetText());
Verify.AreEqual("42", oldValueTextBlock.GetText());

Log.Comment("Verify that setting value above max gives proper values.");
EnterText(numBox, "150");
Verify.AreEqual("100", textTextBlock.GetText());
Verify.AreEqual("100", newValueTextBlock.GetText());
Verify.AreEqual("0", oldValueTextBlock.GetText());

Log.Comment("Verify that setting value to NaN is invalid and does not fire an event.");
Button nanbutton = FindElement.ByName<Button>("SetValueNaNButton");
nanbutton.InvokeAndWait();
Verify.AreEqual("100", textTextBlock.GetText());
Verify.AreEqual("100", newValueTextBlock.GetText());
Verify.AreEqual("0", oldValueTextBlock.GetText());

Log.Comment("Verify that setting value to NaN is valid when validation is disabled.");
ComboBox validationComboBox = FindElement.ByName<ComboBox>("ValidationComboBox");
validationComboBox.SelectItemByName("Disabled");
Wait.ForIdle();
nanbutton.InvokeAndWait();
Verify.AreEqual("NaN", textTextBlock.GetText());
Verify.AreEqual("NaN", newValueTextBlock.GetText());
Verify.AreEqual("100", oldValueTextBlock.GetText());
}
}

[TestMethod]
public void BasicCalculationTest()
{
Expand Down
Loading

0 comments on commit 6ae29b7

Please sign in to comment.