Skip to content

Commit 0b4c289

Browse files
committed
Tests
1 parent 6038944 commit 0b4c289

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed
Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,79 @@
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 numeric chars -', () {
9+
test('should return null when the value has at least 1 numeric character',
10+
() {
11+
// Arrange
12+
final HasNumericCharsValidator validator = HasNumericCharsValidator();
13+
const String value = 'abc123';
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 numeric characters',
23+
() {
24+
// Arrange
25+
final HasNumericCharsValidator validator =
26+
HasNumericCharsValidator(atLeast: 3);
27+
const String value = 'a1b2c3';
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 numeric characters',
38+
() {
39+
// Arrange
40+
final HasNumericCharsValidator validator =
41+
HasNumericCharsValidator(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 numeric characters',
53+
() {
54+
// Arrange
55+
final HasNumericCharsValidator validator =
56+
HasNumericCharsValidator(atLeast: 3, errorText: customErrorMessage);
57+
const String value = 'a1b';
58+
59+
// Act
60+
final String? result = validator.validate(value);
61+
62+
// Assert
63+
expect(result, equals(customErrorMessage));
64+
});
65+
66+
test('should return the error message when the value is empty', () {
67+
// Arrange
68+
final HasNumericCharsValidator validator =
69+
HasNumericCharsValidator(errorText: customErrorMessage);
70+
const String value = '';
71+
72+
// Act
73+
final String? result = validator.validate(value);
74+
75+
// Assert
76+
expect(result, equals(customErrorMessage));
77+
});
78+
});
879
}

0 commit comments

Comments
 (0)