Skip to content

Commit e2f24d9

Browse files
test: add missing tests on extensions
1 parent 30aa93e commit e2f24d9

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/widgets.dart';
2+
import 'package:flutter_form_builder/src/extensions/autovalidatemode_extension.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
void main() {
6+
group('AutoValidateModeExtension', () {
7+
test('when mode is always then return true', () {
8+
final mode = AutovalidateMode.always;
9+
final result = mode.isAlways;
10+
expect(result, isTrue);
11+
});
12+
test('when mode is onUserInteraction then return true', () {
13+
final mode = AutovalidateMode.onUserInteraction;
14+
final result = mode.isOnUserInteraction;
15+
expect(result, isTrue);
16+
});
17+
test('when mode is disabled then return false', () {
18+
final mode = AutovalidateMode.disabled;
19+
final result = mode.isEnable;
20+
expect(result, isFalse);
21+
});
22+
test('when mode is always then isEnable should return true', () {
23+
final mode = AutovalidateMode.always;
24+
final result = mode.isEnable;
25+
expect(result, isTrue);
26+
});
27+
test('when mode is onUserInteraction then isEnable should return true', () {
28+
final mode = AutovalidateMode.onUserInteraction;
29+
final result = mode.isEnable;
30+
expect(result, isTrue);
31+
});
32+
});
33+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'package:flutter_form_builder/src/extensions/generic_validator.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('GenericValidator -', () {
6+
test('when type is String and value is empty then return true', () {
7+
final String value = '';
8+
final result = value.emptyValidator();
9+
expect(result, isTrue);
10+
});
11+
test('when type is String and value is not empty then return false', () {
12+
final String value = 'not empty';
13+
final result = value.emptyValidator();
14+
expect(result, isFalse);
15+
});
16+
test('when type is List and value is empty then return true', () {
17+
final List<int> value = [];
18+
final result = value.emptyValidator();
19+
expect(result, isTrue);
20+
});
21+
test('when type is List and value is not empty then return false', () {
22+
final List<int> value = [1, 2, 3];
23+
final result = value.emptyValidator();
24+
expect(result, isFalse);
25+
});
26+
test('when type is Map and value is empty then return true', () {
27+
final Map<String, int> value = {};
28+
final result = value.emptyValidator();
29+
expect(result, isTrue);
30+
});
31+
test('when type is Map and value is not empty then return false', () {
32+
final Map<String, int> value = {'key': 1};
33+
final result = value.emptyValidator();
34+
expect(result, isFalse);
35+
});
36+
test('when type is Set and value is empty then return true', () {
37+
final Set<int> value = {};
38+
final result = value.emptyValidator();
39+
expect(result, isTrue);
40+
});
41+
test('when type is Set and value is not empty then return false', () {
42+
final Set<int> value = {1, 2, 3};
43+
final result = value.emptyValidator();
44+
expect(result, isFalse);
45+
});
46+
test('when type is Iterable and value is empty then return true', () {
47+
final Iterable<int> value = [];
48+
final result = value.emptyValidator();
49+
expect(result, isTrue);
50+
});
51+
test('when type is Iterable and value is not empty then return false', () {
52+
final Iterable<int> value = [1, 2, 3];
53+
final result = value.emptyValidator();
54+
expect(result, isFalse);
55+
});
56+
test('when type is not and empty possible then return false', () {
57+
final int value = 1;
58+
final result = value.emptyValidator();
59+
expect(result, isFalse);
60+
});
61+
test('when value is null then return true', () {
62+
final String? value = null;
63+
final result = value.emptyValidator();
64+
expect(result, isTrue);
65+
});
66+
});
67+
}

0 commit comments

Comments
 (0)