Skip to content

Commit 1a36a44

Browse files
committed
More tests
1 parent c7274d4 commit 1a36a44

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

test/form_builder_validators_test.dart

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ void main() {
516516
// Fail
517517
expect(validator('13/23'), isNotNull);
518518

519-
final validatorNoExpiredCheck = FormBuilderValidators.creditCardExpirationDate(checkForExpiration: false);
519+
final validatorNoExpiredCheck =
520+
FormBuilderValidators.creditCardExpirationDate(
521+
checkForExpiration: false);
520522
// Pass
521523
expect(validatorNoExpiredCheck('12/23'), isNull);
522524
// Fail
@@ -717,6 +719,59 @@ void main() {
717719
expect(validator('hellohello1@'), isNotNull);
718720
expect(validator('Hellohello1'), isNotNull);
719721
expect(validator('Hellohello@'), isNotNull);
722+
723+
// Fail - only lowercase
724+
expect(validator('lowercasepassword'), isNotNull);
725+
726+
// Fail - only uppercase
727+
expect(validator('UPPERCASEPASSWORD'), isNotNull);
728+
729+
// Fail - only numbers
730+
expect(validator('1234567890'), isNotNull);
731+
732+
// Fail - only special chars
733+
expect(validator('~!@#%^&*'), isNotNull);
734+
735+
// Fail - weak password
736+
expect(validator('password123'), isNotNull);
737+
738+
// Fail - empty password
739+
expect(validator(''), isNotNull);
740+
741+
// Fail - whitespace only
742+
expect(validator(' '), isNotNull);
743+
744+
// Fail - similar characters
745+
expect(validator('aaaaaa1111'), isNotNull);
746+
747+
final customValidator = FormBuilderValidators.password(
748+
minLength: 4,
749+
maxLength: 16,
750+
uppercase: 3,
751+
lowercase: 3,
752+
number: 3,
753+
specialChar: 3,
754+
);
755+
// Pass - meets all requirements
756+
expect(customValidator('PASsw0rd@123!!'), isNull);
757+
758+
// Fail - less than min length
759+
expect(customValidator('Pass@12'), isNotNull);
760+
761+
// Fail - more than max length
762+
expect(customValidator('ThisIsAP@ssw0rd1234'), isNotNull);
763+
764+
// Fail - missing uppercase chars
765+
expect(customValidator('password@123'), isNotNull);
766+
767+
// Fail - missing lowercase chars
768+
expect(customValidator('PASSWORD@123'), isNotNull);
769+
770+
// Fail - missing number
771+
expect(customValidator('Password@abc'), isNotNull);
772+
773+
// Fail - missing special char
774+
expect(customValidator('Password123abc'), isNotNull);
720775
}),
721776
);
722777
}

0 commit comments

Comments
 (0)