@@ -7,7 +7,8 @@ import '../form_builder_tester.dart';
7
7
void main () {
8
8
group ('FormBuilderField -' , () {
9
9
group ('custom error -' , () {
10
- testWidgets ('Should show custom error when invalidate field' , (tester) async {
10
+ testWidgets ('Should show custom error when invalidate field' ,
11
+ (tester) async {
11
12
final textFieldKey = GlobalKey <FormBuilderFieldState >();
12
13
const textFieldName = 'text2' ;
13
14
const errorTextField = 'error text field' ;
@@ -41,15 +42,18 @@ void main() {
41
42
42
43
expect (textFieldKey.currentState? .isValid, isFalse);
43
44
});
44
- testWidgets ('Should valid when no has error and autovalidateMode is always' , (tester) async {
45
+ testWidgets (
46
+ 'Should valid when no has error and autovalidateMode is always' ,
47
+ (tester) async {
45
48
final textFieldKey = GlobalKey <FormBuilderFieldState >();
46
49
const textFieldName = 'text' ;
47
50
const errorTextField = 'error text field' ;
48
51
final testWidget = FormBuilderTextField (
49
52
name: textFieldName,
50
53
key: textFieldKey,
51
54
autovalidateMode: AutovalidateMode .always,
52
- validator: (value) => value == null || value.isEmpty ? errorTextField : null ,
55
+ validator: (value) =>
56
+ value == null || value.isEmpty ? errorTextField : null ,
53
57
);
54
58
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
55
59
@@ -61,15 +65,18 @@ void main() {
61
65
62
66
expect (textFieldKey.currentState? .isValid, isTrue);
63
67
});
64
- testWidgets ('Should invalid when has error and autovalidateMode is always' , (tester) async {
68
+ testWidgets (
69
+ 'Should invalid when has error and autovalidateMode is always' ,
70
+ (tester) async {
65
71
final textFieldKey = GlobalKey <FormBuilderFieldState >();
66
72
const textFieldName = 'text' ;
67
73
const errorTextField = 'error text field' ;
68
74
final testWidget = FormBuilderTextField (
69
75
name: textFieldName,
70
76
key: textFieldKey,
71
77
autovalidateMode: AutovalidateMode .always,
72
- validator: (value) => value == null || value.length < 10 ? errorTextField : null ,
78
+ validator: (value) =>
79
+ value == null || value.length < 10 ? errorTextField : null ,
73
80
);
74
81
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
75
82
@@ -100,7 +107,8 @@ void main() {
100
107
101
108
expect (textFieldKey.currentState? .hasError, isTrue);
102
109
});
103
- testWidgets ('Should no has errors when is empty and no has validators' , (tester) async {
110
+ testWidgets ('Should no has errors when is empty and no has validators' ,
111
+ (tester) async {
104
112
final textFieldKey = GlobalKey <FormBuilderFieldState >();
105
113
const textFieldName = 'text' ;
106
114
final testWidget = FormBuilderTextField (
@@ -118,7 +126,9 @@ void main() {
118
126
});
119
127
120
128
group ('valueIsValid -' , () {
121
- testWidgets ('Should value is valid when validator passes, despite set custom error' , (tester) async {
129
+ testWidgets (
130
+ 'Should value is valid when validator passes, despite set custom error' ,
131
+ (tester) async {
122
132
final textFieldKey = GlobalKey <FormBuilderFieldState >();
123
133
const textFieldName = 'text' ;
124
134
const errorTextField = 'error text field' ;
@@ -137,7 +147,8 @@ void main() {
137
147
});
138
148
139
149
group ('valueHasError -' , () {
140
- testWidgets ('Should value is invalid when validator passes' , (tester) async {
150
+ testWidgets ('Should value is invalid when validator passes' ,
151
+ (tester) async {
141
152
final textFieldKey = GlobalKey <FormBuilderFieldState >();
142
153
const textFieldName = 'text' ;
143
154
const invalidValue = 'invalid' ;
@@ -155,20 +166,25 @@ void main() {
155
166
});
156
167
157
168
group ('autovalidateMode -' , () {
158
- testWidgets ('Should show error when init form and AutovalidateMode is always' , (tester) async {
169
+ testWidgets (
170
+ 'Should show error when init form and AutovalidateMode is always' ,
171
+ (tester) async {
159
172
const textFieldName = 'text4' ;
160
173
const errorTextField = 'error text field' ;
161
174
final testWidget = FormBuilderTextField (
162
175
name: textFieldName,
163
- validator: (value) => value == null || value.isEmpty ? errorTextField : null ,
176
+ validator: (value) =>
177
+ value == null || value.isEmpty ? errorTextField : null ,
164
178
autovalidateMode: AutovalidateMode .always,
165
179
);
166
180
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
167
181
await tester.pumpAndSettle ();
168
182
169
183
expect (find.text (errorTextField), findsOneWidget);
170
184
});
171
- testWidgets ('Should show error when AutovalidateMode is onUserInteraction and change field' , (tester) async {
185
+ testWidgets (
186
+ 'Should show error when AutovalidateMode is onUserInteraction and change field' ,
187
+ (tester) async {
172
188
const textFieldName = 'text4' ;
173
189
const errorTextField = 'error text field' ;
174
190
final testWidget = FormBuilderTextField (
@@ -190,34 +206,40 @@ void main() {
190
206
testWidgets ('Should not dirty by default' , (tester) async {
191
207
const textFieldName = 'text' ;
192
208
final textFieldKey = GlobalKey <FormBuilderFieldState >();
193
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
209
+ final testWidget =
210
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
194
211
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
195
212
196
213
expect (textFieldKey.currentState? .isDirty, false );
197
214
});
198
- testWidgets ('Should dirty when update field value by user' , (tester) async {
215
+ testWidgets ('Should dirty when update field value by user' ,
216
+ (tester) async {
199
217
const textFieldName = 'text' ;
200
218
final textFieldKey = GlobalKey <FormBuilderFieldState >();
201
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
219
+ final testWidget =
220
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
202
221
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
203
222
204
223
final widgetFinder = find.byWidget (testWidget);
205
224
await tester.enterText (widgetFinder, 'test' );
206
225
207
226
expect (textFieldKey.currentState? .isDirty, true );
208
227
});
209
- testWidgets ('Should dirty when update field value by method' , (tester) async {
228
+ testWidgets ('Should dirty when update field value by method' ,
229
+ (tester) async {
210
230
const textFieldName = 'text' ;
211
231
final textFieldKey = GlobalKey <FormBuilderFieldState >();
212
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
232
+ final testWidget =
233
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
213
234
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
214
235
215
236
textFieldKey.currentState? .setValue ('test' );
216
237
await tester.pumpAndSettle ();
217
238
218
239
expect (textFieldKey.currentState? .isDirty, true );
219
240
});
220
- testWidgets ('Should dirty when update field with initial value by user' , (tester) async {
241
+ testWidgets ('Should dirty when update field with initial value by user' ,
242
+ (tester) async {
221
243
const textFieldName = 'text' ;
222
244
final textFieldKey = GlobalKey <FormBuilderFieldState >();
223
245
final testWidget = FormBuilderTextField (
@@ -232,7 +254,8 @@ void main() {
232
254
233
255
expect (textFieldKey.currentState? .isDirty, true );
234
256
});
235
- testWidgets ('Should dirty when update field with initial value by method' , (tester) async {
257
+ testWidgets ('Should dirty when update field with initial value by method' ,
258
+ (tester) async {
236
259
const textFieldName = 'text' ;
237
260
final textFieldKey = GlobalKey <FormBuilderFieldState >();
238
261
final testWidget = FormBuilderTextField (
@@ -250,7 +273,8 @@ void main() {
250
273
testWidgets ('Should not dirty when reset field value' , (tester) async {
251
274
const textFieldName = 'text' ;
252
275
final textFieldKey = GlobalKey <FormBuilderFieldState >();
253
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
276
+ final testWidget =
277
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
254
278
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
255
279
256
280
textFieldKey.currentState? .setValue ('test' );
@@ -259,7 +283,8 @@ void main() {
259
283
260
284
expect (textFieldKey.currentState? .isDirty, false );
261
285
});
262
- testWidgets ('Should not dirty when reset field with initial value' , (tester) async {
286
+ testWidgets ('Should not dirty when reset field with initial value' ,
287
+ (tester) async {
263
288
const textFieldName = 'text' ;
264
289
final textFieldKey = GlobalKey <FormBuilderFieldState >();
265
290
final testWidget = FormBuilderTextField (
@@ -281,15 +306,17 @@ void main() {
281
306
testWidgets ('Should not touched by default' , (tester) async {
282
307
const textFieldName = 'text' ;
283
308
final textFieldKey = GlobalKey <FormBuilderFieldState >();
284
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
309
+ final testWidget =
310
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
285
311
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
286
312
287
313
expect (textFieldKey.currentState? .isTouched, false );
288
314
});
289
315
testWidgets ('Should touched when focus input' , (tester) async {
290
316
const textFieldName = 'text' ;
291
317
final textFieldKey = GlobalKey <FormBuilderFieldState >();
292
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
318
+ final testWidget =
319
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
293
320
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
294
321
295
322
final widgetFinder = find.byWidget (testWidget);
@@ -303,7 +330,8 @@ void main() {
303
330
testWidgets ('Should reset to null when call reset' , (tester) async {
304
331
const textFieldName = 'text' ;
305
332
final textFieldKey = GlobalKey <FormBuilderFieldState >();
306
- final testWidget = FormBuilderTextField (name: textFieldName, key: textFieldKey);
333
+ final testWidget =
334
+ FormBuilderTextField (name: textFieldName, key: textFieldKey);
307
335
await tester.pumpWidget (buildTestableFieldWidget (testWidget));
308
336
309
337
textFieldKey.currentState? .setValue ('test' );
@@ -329,7 +357,9 @@ void main() {
329
357
330
358
expect (textFieldKey.currentState? .value, equals (initialValue));
331
359
});
332
- testWidgets ('Should reset custom error when invalidate field and then reset' , (tester) async {
360
+ testWidgets (
361
+ 'Should reset custom error when invalidate field and then reset' ,
362
+ (tester) async {
333
363
final textFieldKey = GlobalKey <FormBuilderFieldState >();
334
364
const textFieldName = 'text' ;
335
365
const errorTextField = 'error text field' ;
0 commit comments