File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_test/flutter_test.dart' ;
3
+ import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4
+ import 'form_builder_tester.dart' ;
5
+
6
+ void main () {
7
+ testWidgets ('FormBuilderSwitch -- Off/On/Off' , (WidgetTester tester) async {
8
+ const switchName = 'switch1' ;
9
+ final testWidget = FormBuilderSwitch (
10
+ name: switchName,
11
+ title: const Text ('Switch 1' ),
12
+ initialValue: false ,
13
+ );
14
+ final widgetFinder = find.byWidget (testWidget);
15
+
16
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
17
+
18
+ expect (formSave (), isTrue);
19
+ expect (formValue (switchName), isFalse);
20
+ await tester.tap (widgetFinder);
21
+ await tester.pumpAndSettle ();
22
+ expect (formSave (), isTrue);
23
+ expect (formValue (switchName), isTrue);
24
+ await tester.tap (widgetFinder);
25
+ await tester.pumpAndSettle ();
26
+ expect (formSave (), isTrue);
27
+ expect (formValue (switchName), isFalse);
28
+ });
29
+ }
Original file line number Diff line number Diff line change
1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_form_builder/flutter_form_builder.dart' ;
3
+
4
+ final _formKey = GlobalKey <FormBuilderState >();
5
+
6
+ Widget buildTestableFieldWidget (Widget widget) {
7
+ return MaterialApp (
8
+ home: Scaffold (
9
+ body: FormBuilder (
10
+ key: _formKey,
11
+ child: widget,
12
+ ),
13
+ ),
14
+ );
15
+ }
16
+
17
+ bool formSave () => _formKey.currentState.saveAndValidate ();
18
+ dynamic formValue (String name) => _formKey.currentState.value[name];
Original file line number Diff line number Diff line change
1
+ import 'package:flutter_test/flutter_test.dart' ;
2
+ import 'package:flutter_form_builder/flutter_form_builder.dart' ;
3
+
4
+ import 'form_builder_tester.dart' ;
5
+
6
+ void main () {
7
+ testWidgets ('FormBuilderTextField -- Hello Planet' ,
8
+ (WidgetTester tester) async {
9
+ const newTextValue = 'Hello 🪐' ;
10
+ const textFieldName = 'text1' ;
11
+ final testWidget = FormBuilderTextField (
12
+ name: textFieldName,
13
+ );
14
+ final widgetFinder = find.byWidget (testWidget);
15
+
16
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
17
+ expect (formSave (), isTrue);
18
+ // TODO Confirm that this should not be isEmpty
19
+ expect (formValue (textFieldName), isNull);
20
+ await tester.enterText (widgetFinder, newTextValue);
21
+ expect (formSave (), isTrue);
22
+ expect (formValue (textFieldName), equals (newTextValue));
23
+ await tester.enterText (widgetFinder, '' );
24
+ expect (formSave (), isTrue);
25
+ expect (formValue (textFieldName), isEmpty);
26
+ });
27
+ }
You can’t perform that action at this time.
0 commit comments