@@ -6,28 +6,84 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
6
6
import 'form_builder_tester.dart' ;
7
7
8
8
void main () {
9
- testWidgets ('FormBuilderChoiceChip -- 1,3' , (WidgetTester tester) async {
10
- const widgetName = 'cc1' ;
11
- final testWidget = FormBuilderChoiceChip <int >(
12
- shouldRequestFocus: false ,
13
- name: widgetName,
14
- options: const [
15
- FormBuilderChipOption (key: ValueKey ('1' ), value: 1 ),
16
- FormBuilderChipOption (key: ValueKey ('2' ), value: 2 ),
17
- FormBuilderChipOption (key: ValueKey ('3' ), value: 3 ),
18
- ],
19
- );
20
- await tester.pumpWidget (buildTestableFieldWidget (testWidget));
21
-
22
- expect (formSave (), isTrue);
23
- expect (formValue (widgetName), isNull);
24
- await tester.tap (find.byKey (const ValueKey ('1' )));
25
- await tester.pumpAndSettle ();
26
- expect (formSave (), isTrue);
27
- expect (formValue (widgetName), equals (1 ));
28
- await tester.tap (find.byKey (const ValueKey ('3' )));
29
- await tester.pumpAndSettle ();
30
- expect (formSave (), isTrue);
31
- expect (formValue (widgetName), equals (3 ));
9
+ group ('FormBuilderChoiceChip --' , () {
10
+ testWidgets ('basic' , (WidgetTester tester) async {
11
+ const widgetName = 'cc1' ;
12
+
13
+ final testWidget = FormBuilderChoiceChip <int >(
14
+ shouldRequestFocus: false ,
15
+ name: widgetName,
16
+ options: const [
17
+ FormBuilderChipOption (key: ValueKey ('1' ), value: 1 ),
18
+ FormBuilderChipOption (key: ValueKey ('2' ), value: 2 ),
19
+ FormBuilderChipOption (key: ValueKey ('3' ), value: 3 ),
20
+ ],
21
+ );
22
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
23
+
24
+ expect (formSave (), isTrue);
25
+ expect (formValue <int ?>(widgetName), isNull);
26
+ await tester.tap (find.byKey (const ValueKey ('1' )));
27
+ await tester.pumpAndSettle ();
28
+ expect (formSave (), isTrue);
29
+ expect (formValue <int ?>(widgetName), equals (1 ));
30
+ await tester.tap (find.byKey (const ValueKey ('3' )));
31
+ await tester.pumpAndSettle ();
32
+ expect (formSave (), isTrue);
33
+ expect (formValue <int ?>(widgetName), equals (3 ));
34
+ });
35
+ });
36
+ group ('initial value -' , () {
37
+ testWidgets ('to FormBuilder' , (WidgetTester tester) async {
38
+ const widgetName = 'cc2' ;
39
+
40
+ final testWidget = FormBuilderChoiceChip <int >(
41
+ shouldRequestFocus: false ,
42
+ name: widgetName,
43
+ options: const [
44
+ FormBuilderChipOption (key: ValueKey ('1' ), value: 1 ),
45
+ FormBuilderChipOption (key: ValueKey ('2' ), value: 2 ),
46
+ FormBuilderChipOption (key: ValueKey ('3' ), value: 3 ),
47
+ ],
48
+ );
49
+ await tester.pumpWidget (buildTestableFieldWidget (
50
+ testWidget,
51
+ initialValue: {widgetName: 1 },
52
+ ));
53
+
54
+ await tester.ensureVisible (find.byKey (const ValueKey ('1' )));
55
+ expect (formInstantValue (widgetName), equals (1 ));
56
+ expect (formSave (), isTrue);
57
+ expect (formValue <int ?>(widgetName), equals (1 ));
58
+ await tester.tap (find.byKey (const ValueKey ('3' )));
59
+ await tester.pumpAndSettle ();
60
+ expect (formSave (), isTrue);
61
+ expect (formValue <int ?>(widgetName), equals (3 ));
62
+ });
63
+ testWidgets ('to Widget' , (WidgetTester tester) async {
64
+ const widgetName = 'cc3' ;
65
+
66
+ final testWidget = FormBuilderChoiceChip <int >(
67
+ shouldRequestFocus: false ,
68
+ name: widgetName,
69
+ initialValue: 1 ,
70
+ options: const [
71
+ FormBuilderChipOption (key: ValueKey ('1' ), value: 1 ),
72
+ FormBuilderChipOption (key: ValueKey ('2' ), value: 2 ),
73
+ FormBuilderChipOption (key: ValueKey ('3' ), value: 3 ),
74
+ ],
75
+ );
76
+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
77
+ await tester.pumpAndSettle ();
78
+
79
+ await tester.ensureVisible (find.byKey (const ValueKey ('1' )));
80
+ expect (formInstantValue (widgetName), equals (1 ));
81
+ expect (formSave (), isTrue);
82
+ expect (formValue <int ?>(widgetName), equals (1 ));
83
+ await tester.tap (find.byKey (const ValueKey ('3' )));
84
+ await tester.pumpAndSettle ();
85
+ expect (formSave (), isTrue);
86
+ expect (formValue <int ?>(widgetName), equals (3 ));
87
+ });
32
88
});
33
89
}
0 commit comments