From e844e4804d1d0d2bced455f3ef56e996f61d852c Mon Sep 17 00:00:00 2001 From: vjrj <vjrj@comunes.org> Date: Sat, 16 Sep 2023 23:37:40 +0200 Subject: [PATCH] Remove warnings with moch in tests --- lib/ui/widgets/first_screen/g1_textfield.dart | 3 +- test/ui_test.dart | 40 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/ui/widgets/first_screen/g1_textfield.dart b/lib/ui/widgets/first_screen/g1_textfield.dart index a42f8fa0..307a4fd6 100644 --- a/lib/ui/widgets/first_screen/g1_textfield.dart +++ b/lib/ui/widgets/first_screen/g1_textfield.dart @@ -148,6 +148,7 @@ class _G1PayAmountFieldState extends State<G1PayAmountField> { TextPosition(offset: _controller.text.length)); value = _controller.text; } - return validateDecimal(sep: sep, locale: locale, amount: value); + return validateDecimal( + sep: sep, locale: locale, amount: value, tr: (String s) => tr(s)); } } diff --git a/test/ui_test.dart b/test/ui_test.dart index 58959347..044ac17c 100644 --- a/test/ui_test.dart +++ b/test/ui_test.dart @@ -10,6 +10,15 @@ void main() { expect(parsedDouble, equals(1234.56)); }); + test( + 'localizedParseToDouble parses a localized double zero ended string correctly', + () { + const String doubleString = '1.234,50'; + final double parsedDouble = + parseToDoubleLocalized(locale: 'es', number: doubleString); + expect(parsedDouble, equals(1234.5)); + }); + test('valid and invalid comments', () { const List<String> invalidText = <String>['á', '`e', 'ç', 'ñ', ',']; const List<String> validText = <String>[ @@ -29,59 +38,72 @@ void main() { reason: 'Failed $text'); } }); + String tr(String s) => s; test('Valid decimal number - en_US', () { final String? result = - validateDecimal(sep: '.', locale: 'en_US', amount: '123.45'); + validateDecimal(sep: '.', locale: 'en_US', amount: '123.45', tr: tr); expect(result, null); }); test('Valid decimal number - es_ES', () { final String? result = - validateDecimal(sep: ',', locale: 'es_ES', amount: '123,45'); + validateDecimal(sep: ',', locale: 'es_ES', amount: '123,45', tr: tr); expect(result, null); }); test('Empty amount - en_US', () { final String? result = - validateDecimal(sep: '.', locale: 'en_US', amount: ''); + validateDecimal(sep: '.', locale: 'en_US', amount: '', tr: tr); + expect(result, null); + }); + + test('Amount starts with separator - es_ES', () { + final String? result = + validateDecimal(sep: ',', locale: 'es_ES', amount: ',45', tr: tr); expect(result, null); }); test('Amount starts with separator - es_ES', () { final String? result = - validateDecimal(sep: ',', locale: 'es_ES', amount: ',45'); + validateDecimal(sep: ',', locale: 'es_ES', amount: ',45', tr: tr); + expect(result, null); + }); + + test('Amount decimal ends with zero - es_ES', () { + final String? result = + validateDecimal(sep: ',', locale: 'es_ES', amount: '2,40', tr: tr); expect(result, null); }); test('Negative number - en_US', () { final String? result = - validateDecimal(sep: '.', locale: 'en_US', amount: '-123.45'); + validateDecimal(sep: '.', locale: 'en_US', amount: '-123.45', tr: tr); expect(result, 'enter_a_positive_number'); }); test('Invalid number - es_ES', () { final String? result = - validateDecimal(sep: ',', locale: 'es_ES', amount: '12a,45'); + validateDecimal(sep: ',', locale: 'es_ES', amount: '12a,45', tr: tr); expect(result, 'enter_a_valid_number'); }); test('Invalid number - es_ES', () { final String? result = - validateDecimal(sep: ',', locale: 'es_ES', amount: '0.45'); + validateDecimal(sep: ',', locale: 'es_ES', amount: '0.45', tr: tr); expect(result, 'enter_a_valid_number'); }); test('Invalid number - en', () { final String? result = - validateDecimal(sep: '.', locale: 'en', amount: '0,45'); + validateDecimal(sep: '.', locale: 'en', amount: '0,45', tr: tr); expect(result, 'enter_a_valid_number'); }); group('humanizeContact', () { test('Should return "your_wallet" if pubKey matches publicAddress', () { const String publicAddress = 'your_public_address'; const Contact contact = Contact(pubKey: 'your_public_address'); - final String result = humanizeContact(publicAddress, contact); + final String result = humanizeContact(publicAddress, contact, false, tr); expect(result, 'your_wallet'); }); -- GitLab