Skip to content

Commit c500bc7

Browse files
committed
Tests
1 parent 95991b3 commit c500bc7

File tree

73 files changed

+2182
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2182
-73
lines changed
Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Has special chars -', () {
9+
test('should return null when the value has at least 1 special character',
10+
() {
11+
// Arrange
12+
final HasSpecialCharsValidator validator = HasSpecialCharsValidator();
13+
const String value = 'abc!@#';
14+
15+
// Act
16+
final String? result = validator.validate(value);
17+
18+
// Assert
19+
expect(result, isNull);
20+
});
21+
22+
test('should return null when the value has at least 3 special characters',
23+
() {
24+
// Arrange
25+
final HasSpecialCharsValidator validator =
26+
HasSpecialCharsValidator(atLeast: 3);
27+
const String value = 'a!b@c#';
28+
29+
// Act
30+
final String? result = validator.validate(value);
31+
32+
// Assert
33+
expect(result, isNull);
34+
});
35+
36+
test(
37+
'should return the error message when the value has no special characters',
38+
() {
39+
// Arrange
40+
final HasSpecialCharsValidator validator =
41+
HasSpecialCharsValidator(errorText: customErrorMessage);
42+
const String value = 'abc';
43+
44+
// Act
45+
final String? result = validator.validate(value);
46+
47+
// Assert
48+
expect(result, equals(customErrorMessage));
49+
});
50+
51+
test(
52+
'should return the error message when the value has less than 3 special characters',
53+
() {
54+
// Arrange
55+
final HasSpecialCharsValidator validator =
56+
HasSpecialCharsValidator(atLeast: 3, errorText: customErrorMessage);
57+
const String value = 'a!b';
58+
59+
// Act
60+
final String? result = validator.validate(value);
61+
62+
// Assert
63+
expect(result, equals(customErrorMessage));
64+
});
65+
});
866
}
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Has uppercase chars -', () {
9+
test('should return null when the value has at least 1 uppercase character',
10+
() {
11+
// Arrange
12+
final HasUppercaseCharsValidator validator = HasUppercaseCharsValidator();
13+
const String value = 'abcA';
14+
15+
// Act
16+
final String? result = validator.validate(value);
17+
18+
// Assert
19+
expect(result, isNull);
20+
});
21+
22+
test(
23+
'should return null when the value has at least 3 uppercase characters',
24+
() {
25+
// Arrange
26+
final HasUppercaseCharsValidator validator =
27+
HasUppercaseCharsValidator(atLeast: 3);
28+
const String value = 'aAbBcC';
29+
30+
// Act
31+
final String? result = validator.validate(value);
32+
33+
// Assert
34+
expect(result, isNull);
35+
});
36+
37+
test(
38+
'should return the error message when the value has no uppercase characters',
39+
() {
40+
// Arrange
41+
final HasUppercaseCharsValidator validator =
42+
HasUppercaseCharsValidator(errorText: customErrorMessage);
43+
const String value = 'abc';
44+
45+
// Act
46+
final String? result = validator.validate(value);
47+
48+
// Assert
49+
expect(result, equals(customErrorMessage));
50+
});
51+
52+
test(
53+
'should return the error message when the value has less than 3 uppercase characters',
54+
() {
55+
// Arrange
56+
final HasUppercaseCharsValidator validator =
57+
HasUppercaseCharsValidator(atLeast: 3, errorText: customErrorMessage);
58+
const String value = 'aA';
59+
60+
// Act
61+
final String? result = validator.validate(value);
62+
63+
// Assert
64+
expect(result, equals(customErrorMessage));
65+
});
66+
});
867
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Is false -', () {
9+
test('should return null when the value is false', () {
10+
// Arrange
11+
const IsFalseValidator validator = IsFalseValidator();
12+
const bool value = false;
13+
14+
// Act
15+
final String? result = validator.validate(value);
16+
17+
// Assert
18+
expect(result, isNull);
19+
});
20+
21+
test('should return the error message when the value is true', () {
22+
// Arrange
23+
final IsFalseValidator validator =
24+
IsFalseValidator(errorText: customErrorMessage);
25+
const bool value = true;
26+
27+
// Act
28+
final String? result = validator.validate(value);
29+
30+
// Assert
31+
expect(result, equals(customErrorMessage));
32+
});
33+
});
834
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Is true -', () {
9+
test('should return null when the value is true', () {
10+
// Arrange
11+
const IsTrueValidator validator = IsTrueValidator();
12+
const bool value = true;
13+
14+
// Act
15+
final String? result = validator.validate(value);
16+
17+
// Assert
18+
expect(result, isNull);
19+
});
20+
21+
test('should return the error message when the value is false', () {
22+
// Arrange
23+
final IsTrueValidator validator =
24+
IsTrueValidator(errorText: customErrorMessage);
25+
const bool value = false;
26+
27+
// Act
28+
final String? result = validator.validate(value);
29+
30+
// Assert
31+
expect(result, equals(customErrorMessage));
32+
});
33+
});
834
}
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Contains element -', () {
9+
test('should return null when the value contains the element', () {
10+
// Arrange
11+
const ContainsElementValidator validator =
12+
ContainsElementValidator(element: 'a');
13+
const List<String> value = <String>['a', 'b', 'c'];
14+
15+
// Act
16+
final String? result = validator.validate(value);
17+
18+
// Assert
19+
expect(result, isNull);
20+
});
21+
22+
test(
23+
'should return the error message when the value does not contain the element',
24+
() {
25+
// Arrange
26+
final ContainsElementValidator validator =
27+
ContainsElementValidator(element: 'a', errorText: customErrorMessage);
28+
const List<String> value = <String>['b', 'c'];
29+
30+
// Act
31+
final String? result = validator.validate(value);
32+
33+
// Assert
34+
expect(result, equals(customErrorMessage));
35+
});
36+
});
837
}
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Equal length -', () {
9+
test('should return null when the value has the same length as the target',
10+
() {
11+
// Arrange
12+
const EqualLengthValidator validator = EqualLengthValidator(length: 3);
13+
const String value = 'abc';
14+
15+
// Act
16+
final String? result = validator.validate(value);
17+
18+
// Assert
19+
expect(result, isNull);
20+
});
21+
22+
test(
23+
'should return the error message when the value has a different length',
24+
() {
25+
// Arrange
26+
final EqualLengthValidator validator =
27+
EqualLengthValidator(length: 3, errorText: customErrorMessage);
28+
const String value = 'abcd';
29+
30+
// Act
31+
final String? result = validator.validate(value);
32+
33+
// Assert
34+
expect(result, equals(customErrorMessage));
35+
});
36+
});
837
}
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Max length -', () {
9+
test('should return null when the value has the same length as the target',
10+
() {
11+
// Arrange
12+
const MaxLengthValidator validator = MaxLengthValidator(maxLength: 3);
13+
const String value = 'abc';
14+
15+
// Act
16+
final String? result = validator.validate(value);
17+
18+
// Assert
19+
expect(result, isNull);
20+
});
21+
22+
test(
23+
'should return null when the value has a smaller length than the target',
24+
() {
25+
// Arrange
26+
const MaxLengthValidator validator = MaxLengthValidator(maxLength: 3);
27+
const String value = 'ab';
28+
29+
// Act
30+
final String? result = validator.validate(value);
31+
32+
// Assert
33+
expect(result, isNull);
34+
});
35+
36+
test('should return the error message when the value has a greater length',
37+
() {
38+
// Arrange
39+
final MaxLengthValidator validator =
40+
MaxLengthValidator(maxLength: 3, errorText: customErrorMessage);
41+
const String value = 'abcd';
42+
43+
// Act
44+
final String? result = validator.validate(value);
45+
46+
// Assert
47+
expect(result, equals(customErrorMessage));
48+
});
49+
});
850
}
Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
11
import 'package:faker_dart/faker_dart.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:form_builder_validators/form_builder_validators.dart';
34

45
void main() {
56
final Faker faker = Faker.instance;
67
final String customErrorMessage = faker.lorem.sentence();
7-
group('Email -', () {});
8+
group('Max words count -', () {
9+
test(
10+
'should return null when the value has the same number of words as the target',
11+
() {
12+
// Arrange
13+
const MaxWordsCountValidator validator =
14+
MaxWordsCountValidator(maxWordsCount: 3);
15+
const String value = 'abc def ghi';
16+
17+
// Act
18+
final String? result = validator.validate(value);
19+
20+
// Assert
21+
expect(result, isNull);
22+
});
23+
24+
test(
25+
'should return null when the value has a smaller number of words than the target',
26+
() {
27+
// Arrange
28+
const MaxWordsCountValidator validator =
29+
MaxWordsCountValidator(maxWordsCount: 3);
30+
const String value = 'ab cd';
31+
32+
// Act
33+
final String? result = validator.validate(value);
34+
35+
// Assert
36+
expect(result, isNull);
37+
});
38+
39+
test(
40+
'should return the error message when the value has a greater number of words',
41+
() {
42+
// Arrange
43+
final MaxWordsCountValidator validator = MaxWordsCountValidator(
44+
maxWordsCount: 3, errorText: customErrorMessage,);
45+
const String value = 'abcd efgh ijkl';
46+
47+
// Act
48+
final String? result = validator.validate(value);
49+
50+
// Assert
51+
expect(result, equals(customErrorMessage));
52+
});
53+
});
854
}

0 commit comments

Comments
 (0)