Skip to content

Commit

Permalink
feat(test): add test for amount input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Aug 16, 2023
1 parent efcf5df commit 4d2e8cd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/widgets/validations/vtt_amount_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ enum AmountInputError {
invalid,
zero,
decimals,
tooBig,
invalidNumber
}

Expand All @@ -20,7 +19,6 @@ Map<AmountInputError, String> errorMap = {
AmountInputError.zero: 'Amount cannot be zero',
AmountInputError.invalid: 'Invalid amount',
AmountInputError.decimals: 'Only 9 decimal digits supported',
AmountInputError.tooBig: 'Amount too big',
};

// Extend FormzInput and provide the input type and error type.
Expand Down
50 changes: 50 additions & 0 deletions test/validations/vtt_amount_input_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:my_wit_wallet/widgets/validations/vtt_amount_input.dart';
import 'package:test/test.dart';

void main() async {
test('Decimal number has more than 9 digits', () async {
String amount = '0.00000000001';
VttAmountInput _amount = VttAmountInput.dirty(
value: amount, availableNanoWit: 1000, allowValidation: true);

expect(_amount.validator(amount, avoidWeightedAmountCheck: true),
errorMap[AmountInputError.decimals]);
});
test('Not enough Funds', () async {
String amount = '0.000000001';
VttAmountInput _amount = VttAmountInput.dirty(
value: amount, availableNanoWit: 0, allowValidation: true);

expect(_amount.validator(amount, avoidWeightedAmountCheck: true),
errorMap[AmountInputError.notEnough]);
});
test('Amount cannot be zero', () async {
String amount = '0';
VttAmountInput _amount = VttAmountInput.dirty(
value: amount, availableNanoWit: 0, allowValidation: true);

expect(_amount.validator(amount, avoidWeightedAmountCheck: true),
errorMap[AmountInputError.zero]);
});
test('Amount can be zero', () async {
String amount = '0';
VttAmountInput _amount = VttAmountInput.dirty(
value: amount,
availableNanoWit: 0,
allowValidation: true,
allowZero: true);

expect(_amount.validator(amount, avoidWeightedAmountCheck: true), null);
});
test('Invalid amount', () async {
String amount = '0.';
VttAmountInput _amount = VttAmountInput.dirty(
value: amount,
availableNanoWit: 0,
allowValidation: true,
allowZero: true);

expect(_amount.validator(amount, avoidWeightedAmountCheck: true),
errorMap[AmountInputError.invalid]);
});
}

0 comments on commit 4d2e8cd

Please sign in to comment.