mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
Add TestCurrencyFormattingLogic in UnitConverterViewModelUnitTests
This commit is contained in:
parent
ac04706d48
commit
3ad95ff7ea
3 changed files with 47 additions and 9 deletions
|
@ -227,9 +227,10 @@ void UnitConverterViewModel::OnUnitChanged(Object ^ parameter)
|
|||
return;
|
||||
}
|
||||
|
||||
m_model->SetCurrentUnitTypes(UnitFrom->GetModelUnit(), UnitTo->GetModelUnit());
|
||||
|
||||
UpdateCurrencyFormatter();
|
||||
|
||||
m_model->SetCurrentUnitTypes(UnitFrom->GetModelUnit(), UnitTo->GetModelUnit());
|
||||
if (m_supplementaryResultsTimer != nullptr)
|
||||
{
|
||||
// End timer to show results immediately
|
||||
|
|
|
@ -140,6 +140,7 @@ vector<UCM::Category> UnitConverterMock::GetCategories()
|
|||
cats.push_back(CAT1);
|
||||
cats.push_back(CAT2);
|
||||
cats.push_back(CAT3);
|
||||
cats.push_back(CAT_CURRENCY);
|
||||
|
||||
m_curCategory = CAT2;
|
||||
|
||||
|
@ -174,6 +175,10 @@ UCM::CategorySelectionInitializer UnitConverterMock::SetCurrentCategory(const UC
|
|||
units.push_back(UNIT9);
|
||||
break;
|
||||
}
|
||||
case CURRENCY_ID:
|
||||
units.push_back(UNITJPY);
|
||||
units.push_back(UNITJOD);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
|
@ -341,7 +346,7 @@ TEST_METHOD(TestUnitConverterLoadSetsUpCategories)
|
|||
VM::UnitConverterViewModel vm(mock);
|
||||
IObservableVector<VM::Category ^> ^ cats = vm.Categories;
|
||||
VERIFY_ARE_EQUAL((UINT)1, mock->m_getCategoriesCallCount);
|
||||
VERIFY_ARE_EQUAL((UINT)3, cats->Size);
|
||||
VERIFY_ARE_EQUAL((UINT)4, cats->Size);
|
||||
// Verify that we match current category
|
||||
VERIFY_IS_TRUE(CAT2 == vm.CurrentCategory->GetModelCategory());
|
||||
}
|
||||
|
@ -935,6 +940,33 @@ TEST_METHOD(TestDecimalFormattingLogic)
|
|||
VERIFY_IS_TRUE(vm.Value1 == L"3");
|
||||
VERIFY_IS_TRUE(vm.Value2 == L"2.50");
|
||||
}
|
||||
|
||||
TEST_METHOD(TestCurrencyFormattingLogic)
|
||||
{
|
||||
// verify that currency fraction digits is formatted per currency type
|
||||
|
||||
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();
|
||||
VM::UnitConverterViewModel vm(mock);
|
||||
|
||||
// Establish base condition
|
||||
vm.CurrentCategory = vm.Categories->GetAt(3); // Currency
|
||||
vm.Unit1 = vm.Units->GetAt(0); // JPY
|
||||
vm.Unit2 = vm.Units->GetAt(1); // JOD
|
||||
vm.UnitChanged->Execute(nullptr);
|
||||
|
||||
const WCHAR *vFrom = L"1.2340", *vTo = L"0.0070";
|
||||
vm.UpdateDisplay(vFrom, vTo);
|
||||
|
||||
VERIFY_IS_TRUE(vm.Value1 == L"1.");
|
||||
VERIFY_IS_TRUE(vm.Value2 == L"0.007");
|
||||
vm.SwitchActive->Execute(nullptr);
|
||||
VERIFY_IS_TRUE(vm.Value1 == L"1"); // dangling decimal now removed
|
||||
VERIFY_IS_TRUE(vm.Value2 == L"0.007");
|
||||
vm.SwitchActive->Execute(nullptr);
|
||||
VERIFY_IS_TRUE(vm.Value1 == L"1");
|
||||
VERIFY_IS_TRUE(vm.Value2 == L"0.007");
|
||||
}
|
||||
|
||||
// Tests that when we switch the active field and get display
|
||||
// updates, the correct automation names are are being updated.
|
||||
TEST_METHOD(TestValue1AndValue2AutomationNameChanges)
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace UCM = UnitConversionManager;
|
|||
|
||||
namespace CalculatorUnitTests
|
||||
{
|
||||
static constexpr int CURRENCY_ID = 16;
|
||||
|
||||
static UCM::Unit UNIT1 = { 1, L"UNIT1", L"U1", true, false, false };
|
||||
static UCM::Unit UNIT2 = { 2, L"UNIT2", L"U2", false, true, false };
|
||||
static UCM::Unit UNIT3 = { 3, L"UNIT3", L"U3", false, false, false };
|
||||
|
@ -19,10 +21,13 @@ namespace CalculatorUnitTests
|
|||
static UCM::Unit UNIT8 = { 8, L"UNIT8", L"U8", false, false, false };
|
||||
static UCM::Unit UNIT9 = { 9, L"UNIT9", L"U9", true, false, false };
|
||||
static UCM::Unit UNITWHIMSY = { 10, L"Whimsy", L"UW", true, false, true };
|
||||
static UCM::Unit UNITJPY = { 11, L"Japan - Yen", L"JPY", true, true, false };
|
||||
static UCM::Unit UNITJOD = { 12, L"Jordan - Dinar", L"JOD", true, true, false };
|
||||
|
||||
static UCM::Category CAT1 = { 1, L"CAT1", false }; // contains Unit1 - Unit3
|
||||
static UCM::Category CAT2 = { 2, L"CAT2", false }; // contains Unit4 - Unit6
|
||||
static UCM::Category CAT3 = { 3, L"CAT3", false }; // contains Unit7 - Unit9
|
||||
static UCM::Category CAT_CURRENCY = { CURRENCY_ID, L"Currency", false }; // contains UnitJPY and UnitJOD
|
||||
|
||||
class UnitConverterMock : public UnitConversionManager::IUnitConverter
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue