@@ -1001,4 +1001,111 @@ void main() {
1001
1001
expect (validator ('123 hello' ), isNotNull);
1002
1002
}),
1003
1003
);
1004
+
1005
+ testWidgets (
1006
+ 'FormBuilderValidators.aggregate' ,
1007
+ (WidgetTester tester) => testValidations (tester, (context) {
1008
+ final validator = FormBuilderValidators .aggregate <String >([
1009
+ FormBuilderValidators .required (),
1010
+ FormBuilderValidators .minLength (5 ),
1011
+ FormBuilderValidators .maxLength (10 ),
1012
+ ]);
1013
+ // Pass
1014
+ expect (validator ('hello' ), isNull);
1015
+ // Fail
1016
+ expect (validator (null ), isNotNull);
1017
+ expect (validator ('' ), isNotNull);
1018
+ expect (validator ('test' ), isNotNull);
1019
+ expect (validator ('this string is too long' ), isNotNull);
1020
+ }),
1021
+ );
1022
+
1023
+ testWidgets (
1024
+ 'FormBuilderValidators.debounce' ,
1025
+ (WidgetTester tester) async {
1026
+ String ? validationResult;
1027
+ final validator = FormBuilderValidators .debounce <String >(
1028
+ duration: const Duration (milliseconds: 500 ),
1029
+ validator: (value) => FormBuilderValidators .required ()(value),
1030
+ );
1031
+
1032
+ // Set initial result to null
1033
+ validationResult = validator ('valid' );
1034
+ // Initial pass check
1035
+ expect (validationResult, isNull);
1036
+
1037
+ // Set result to not null but should still be null initially due to debounce
1038
+ validationResult = validator ('' );
1039
+ expect (validationResult, isNull);
1040
+
1041
+ // Advance time by 500 milliseconds to trigger debounce
1042
+ await tester.pump (const Duration (milliseconds: 500 ));
1043
+
1044
+ // Validate again to see the actual result after debounce
1045
+ validationResult = validator ('' );
1046
+ expect (validationResult, isNotNull);
1047
+ },
1048
+ );
1049
+
1050
+ testWidgets (
1051
+ 'FormBuilderValidators.retry' ,
1052
+ (WidgetTester tester) async {
1053
+ int attempts = 0 ;
1054
+ final validator = FormBuilderValidators .retry <String >(
1055
+ times: 3 ,
1056
+ duration: const Duration (milliseconds: 10 ),
1057
+ validator: (value) {
1058
+ attempts++ ;
1059
+ return value != 'pass' && attempts < 3 ? 'fail' : null ;
1060
+ },
1061
+ );
1062
+ // Pass on retry
1063
+ expect (validator ('pass' ), isNull);
1064
+ // Fail after retries
1065
+ expect (validator ('fail' ), isNotNull);
1066
+ await Future .delayed (const Duration (milliseconds: 200 ));
1067
+ expect (attempts, 3 );
1068
+ },
1069
+ );
1070
+
1071
+ testWidgets (
1072
+ 'FormBuilderValidators.transform' ,
1073
+ (WidgetTester tester) => testValidations (tester, (context) {
1074
+ final validator = FormBuilderValidators .transform <String >(
1075
+ FormBuilderValidators .required (),
1076
+ (value) => value? .trim () ?? '' ,
1077
+ );
1078
+ // Pass
1079
+ expect (validator (' trimmed ' ), isNull);
1080
+ // Fail
1081
+ expect (validator (' ' ), isNotNull);
1082
+ }),
1083
+ );
1084
+
1085
+ testWidgets (
1086
+ 'FormBuilderValidators.skipWhen' ,
1087
+ (WidgetTester tester) => testValidations (tester, (context) {
1088
+ final validator = FormBuilderValidators .skipWhen <String >(
1089
+ (value) => value == 'skip' ,
1090
+ FormBuilderValidators .required (),
1091
+ );
1092
+ // Pass
1093
+ expect (validator ('skip' ), isNull);
1094
+ // Fail
1095
+ expect (validator ('' ), isNotNull);
1096
+ }),
1097
+ );
1098
+
1099
+ testWidgets (
1100
+ 'FormBuilderValidators.log' ,
1101
+ (WidgetTester tester) => testValidations (tester, (context) {
1102
+ final validator = FormBuilderValidators .log <String >(
1103
+ log: (value) => 'Logging: $value ' ,
1104
+ );
1105
+ // Pass
1106
+ expect (validator ('test' ), isNull);
1107
+ // Fail
1108
+ expect (validator (null ), isNull); // Log message will be displayed
1109
+ }),
1110
+ );
1004
1111
}
0 commit comments