* Fixes issue #1409 Copy pasting into Currency locks the editor. Skipping the validation of full editor lock when backspace or clear button is clicked. * Adding code review feedback. * Adding code review feedback.
This commit is contained in:
parent
15ae66626a
commit
483dacbeff
@ -474,7 +474,9 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object ^ parameter)
|
||||
|
||||
static constexpr UCM::Command OPERANDS[] = { UCM::Command::Zero, UCM::Command::One, UCM::Command::Two, UCM::Command::Three, UCM::Command::Four,
|
||||
UCM::Command::Five, UCM::Command::Six, UCM::Command::Seven, UCM::Command::Eight, UCM::Command::Nine };
|
||||
if (m_isInputBlocked)
|
||||
if (m_isInputBlocked &&
|
||||
command != UCM::Command::Clear &&
|
||||
command != UCM::Command::Backspace)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
17
src/CalculatorUITestFramework/UnitConverterOperatorsPanel.cs
Normal file
17
src/CalculatorUITestFramework/UnitConverterOperatorsPanel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class UnitConverterOperatorsPanel
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
public NumberPad NumberPad = new NumberPad();
|
||||
public WindowsElement ClearButton => this.session.TryFindElementByAccessibilityId("ClearEntryButtonPos0");
|
||||
public WindowsElement BackSpaceButton => this.session.TryFindElementByAccessibilityId("BackSpaceButtonSmall");
|
||||
}
|
||||
}
|
68
src/CalculatorUITestFramework/UnitConverterPage.cs
Normal file
68
src/CalculatorUITestFramework/UnitConverterPage.cs
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class UnitConverterPage
|
||||
{
|
||||
public UnitConverterOperatorsPanel UnitConverterOperators = new UnitConverterOperatorsPanel();
|
||||
public NavigationMenu NavigationMenu = new NavigationMenu();
|
||||
public UnitConverterResults UnitConverterResults = new UnitConverterResults();
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
/// <summary>
|
||||
/// Clear the Calculator display
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
this.UnitConverterOperators.ClearButton.Click();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Ensures that the calculator result text is zero; if not, clears all
|
||||
///// </summary>
|
||||
public void EnsureCalculatorResultTextIsZero()
|
||||
{
|
||||
if ("0" != this.UnitConverterResults.GetCalculationResult1Text())
|
||||
{
|
||||
this.ClearAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Navigates the calculator is in currency mode
|
||||
/// </summary>
|
||||
public void NavigateToUnitConverter()
|
||||
{
|
||||
// Ensure that calculator is in Currency Mode
|
||||
this.NavigationMenu.ChangeCalculatorMode(CalculatorMode.Currency);
|
||||
this.UnitConverterResults.IsResultsDisplayPresent();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Ensures that the calculator is in Currency Mode
|
||||
///// </summary>
|
||||
public void EnsureCalculatorIsCurrencyMode()
|
||||
{
|
||||
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
|
||||
if (source.Contains("Header"))
|
||||
{
|
||||
string header = CalculatorApp.Header.Text;
|
||||
if (header == "Currency")
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.NavigateToUnitConverter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
47
src/CalculatorUITestFramework/UnitConverterResults.cs
Normal file
47
src/CalculatorUITestFramework/UnitConverterResults.cs
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class UnitConverterResults
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
private WindowsElement CalculationResult1 => this.session.TryFindElementByAccessibilityId("Value1");
|
||||
|
||||
private WindowsElement CalculationResult2 => this.session.TryFindElementByAccessibilityId("Value2");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the Value1 control and removes the narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetCalculationResult1Text()
|
||||
{
|
||||
return Regex.Replace(this.CalculationResult1.Text.Trim(), "[^0-9.]", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that CalculationResult1 and CalculationResult2 are not null
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public void IsResultsDisplayPresent()
|
||||
{
|
||||
Assert.IsNotNull(this.CalculationResult1);
|
||||
Assert.IsNotNull(this.CalculationResult2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the Value2 control and removes the narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetCalculationResult2Text()
|
||||
{
|
||||
return Regex.Replace(this.CalculationResult2.Text.Trim(), "[^0-9.]", "");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
134
src/CalculatorUITests/CurrencyConverterFunctionalTests.cs
Normal file
134
src/CalculatorUITests/CurrencyConverterFunctionalTests.cs
Normal file
@ -0,0 +1,134 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using CalculatorUITestFramework;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using System;
|
||||
|
||||
namespace CalculatorUITests
|
||||
{
|
||||
[TestClass]
|
||||
public class CurrencyConverterFunctionalTests
|
||||
{
|
||||
private static UnitConverterPage page = new UnitConverterPage();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the WinAppDriver web driver session.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
// Create session to launch a Calculator window
|
||||
WinAppDriver.Instance.SetupCalculatorSession(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the app and WinAppDriver web driver session.
|
||||
/// </summary>
|
||||
[ClassCleanup]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
// Tear down Calculator session.
|
||||
WinAppDriver.Instance.TearDownCalculatorSession();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the calculator is in a cleared state
|
||||
/// </summary>
|
||||
[TestInitialize]
|
||||
public void TestInit()
|
||||
{
|
||||
CalculatorApp.EnsureCalculatorHasFocus();
|
||||
page.EnsureCalculatorIsCurrencyMode();
|
||||
page.EnsureCalculatorResultTextIsZero();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
page.ClearAll();
|
||||
}
|
||||
|
||||
#region Basic UI Functionality via Mouse Input Tests
|
||||
/// <summary>
|
||||
/// These automated tests verify clicking each of the buttons in the Calculator UI and getting an expected result
|
||||
/// Via mouse input, all basic UI functionality is checked
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[Priority(0)]
|
||||
public void MouseInput_EnterInputAndCheckTheResult()
|
||||
{
|
||||
//Verifies the 2 is entered and clear is functional
|
||||
page.UnitConverterOperators.NumberPad.Num2Button.Click();
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 2 button
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 2 button
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These automated tests verify clicking each of the buttons in the Calculator UI and getting an expected result
|
||||
/// Via mouse input, all basic UI functionality is checked
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[Priority(1)]
|
||||
public void MouseInput_EnterInputWithFullDecimalAndClear()
|
||||
{
|
||||
//Verifies the 20.42 is entered and clear is functional
|
||||
page.UnitConverterOperators.NumberPad.Num2Button.Click();
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 2 button
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 2 button
|
||||
page.UnitConverterOperators.NumberPad.Num0Button.Click();
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 2 button
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 2 button
|
||||
page.UnitConverterOperators.NumberPad.DecimalButton.Click();
|
||||
Assert.AreEqual("20.00", page.UnitConverterResults.GetCalculationResult1Text()); //verifies decimal button
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult2Text()); //verifies decimal button
|
||||
page.UnitConverterOperators.NumberPad.Num4Button.Click();
|
||||
Assert.AreEqual("20.40", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 4 button
|
||||
Assert.AreEqual("20.40", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 4 button
|
||||
page.UnitConverterOperators.NumberPad.Num3Button.Click();
|
||||
Assert.AreEqual("20.43", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 3 button
|
||||
Assert.AreEqual("20.43", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 3 button
|
||||
page.UnitConverterOperators.NumberPad.Num3Button.Click();
|
||||
page.UnitConverterOperators.ClearButton.Click();
|
||||
Assert.AreEqual("0", page.UnitConverterResults.GetCalculationResult1Text()); //verifies Clear button
|
||||
Assert.AreEqual("0", page.UnitConverterResults.GetCalculationResult2Text()); //verifies Clear button
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These automated tests verify clicking each of the buttons in the Calculator UI and getting an expected result
|
||||
/// Via mouse input, all basic UI functionality is checked
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[Priority(1)]
|
||||
public void MouseInput_EnterInputWithFullDecimalAndClearWithBackspace()
|
||||
{
|
||||
//Verifies the 20.42 is entered and clear is functional
|
||||
page.UnitConverterOperators.NumberPad.Num2Button.Click();
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 2 button
|
||||
Assert.AreEqual("2", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 2 button
|
||||
page.UnitConverterOperators.NumberPad.Num0Button.Click();
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 2 button
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 2 button
|
||||
page.UnitConverterOperators.NumberPad.DecimalButton.Click();
|
||||
Assert.AreEqual("20.00", page.UnitConverterResults.GetCalculationResult1Text()); //verifies decimal button
|
||||
Assert.AreEqual("20", page.UnitConverterResults.GetCalculationResult2Text()); //verifies decimal button
|
||||
page.UnitConverterOperators.NumberPad.Num4Button.Click();
|
||||
Assert.AreEqual("20.40", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 4 button
|
||||
Assert.AreEqual("20.40", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 4 button
|
||||
page.UnitConverterOperators.NumberPad.Num3Button.Click();
|
||||
Assert.AreEqual("20.43", page.UnitConverterResults.GetCalculationResult1Text()); //verifies 3 button
|
||||
Assert.AreEqual("20.43", page.UnitConverterResults.GetCalculationResult2Text()); //verifies 3 button
|
||||
page.UnitConverterOperators.NumberPad.Num3Button.Click();
|
||||
page.UnitConverterOperators.BackSpaceButton.Click();
|
||||
page.UnitConverterOperators.BackSpaceButton.Click();
|
||||
page.UnitConverterOperators.BackSpaceButton.Click();
|
||||
page.UnitConverterOperators.BackSpaceButton.Click();
|
||||
page.UnitConverterOperators.BackSpaceButton.Click();
|
||||
Assert.AreEqual("0", page.UnitConverterResults.GetCalculationResult1Text()); //verifies Backspace button clicks
|
||||
Assert.AreEqual("0", page.UnitConverterResults.GetCalculationResult2Text()); //verifies Backspace button clicks
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -202,6 +202,8 @@ namespace UnitConverterUnitTests
|
||||
TEST_METHOD(UnitConverterTestQuote);
|
||||
TEST_METHOD(UnitConverterTestUnquote);
|
||||
TEST_METHOD(UnitConverterTestBackspace);
|
||||
TEST_METHOD(UnitConverterTestBackspaceBasic);
|
||||
TEST_METHOD(UnitConverterTestClear);
|
||||
TEST_METHOD(UnitConverterTestScientificInputs);
|
||||
TEST_METHOD(UnitConverterTestSupplementaryResultRounding);
|
||||
TEST_METHOD(UnitConverterTestMaxDigitsReached);
|
||||
@ -291,6 +293,41 @@ namespace UnitConverterUnitTests
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector<tuple<wstring, Unit>>(begin(test2), end(test2))));
|
||||
}
|
||||
|
||||
|
||||
// Verify a basic copy paste steam. '20.43' with backspace button pressed
|
||||
void UnitConverterTest::UnitConverterTestBackspaceBasic()
|
||||
{
|
||||
s_unitConverter->SendCommand(Command::Two);
|
||||
s_unitConverter->SendCommand(Command::Zero);
|
||||
s_unitConverter->SendCommand(Command::Decimal);
|
||||
s_unitConverter->SendCommand(Command::Four);
|
||||
s_unitConverter->SendCommand(Command::Three);
|
||||
s_unitConverter->SendCommand(Command::Backspace);
|
||||
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"20.4"), wstring(L"20.4")));
|
||||
s_unitConverter->SendCommand(Command::Backspace);
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"20."), wstring(L"20")));
|
||||
s_unitConverter->SendCommand(Command::Backspace);
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"20"), wstring(L"20")));
|
||||
s_unitConverter->SendCommand(Command::Backspace);
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"2"), wstring(L"2")));
|
||||
s_unitConverter->SendCommand(Command::Backspace);
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"0"), wstring(L"0")));
|
||||
}
|
||||
|
||||
// Verify a basic copy paste steam. '20.43' with backspace button pressed
|
||||
void UnitConverterTest::UnitConverterTestClear()
|
||||
{
|
||||
s_unitConverter->SendCommand(Command::Two);
|
||||
s_unitConverter->SendCommand(Command::Zero);
|
||||
s_unitConverter->SendCommand(Command::Decimal);
|
||||
s_unitConverter->SendCommand(Command::Four);
|
||||
s_unitConverter->SendCommand(Command::Three);
|
||||
s_unitConverter->SendCommand(Command::Clear);
|
||||
|
||||
VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"0"), wstring(L"0")));
|
||||
}
|
||||
|
||||
// Check the getter functions
|
||||
void UnitConverterTest::UnitConverterTestGetters()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user