@@ -154,16 +154,19 @@ void main() {
154
154
expect (widthInput, findsOneWidget);
155
155
expect (heightInput, findsOneWidget);
156
156
157
- // Verify the labels are expected.
158
- expect (_labelForInput (titleInput, matching: 'set' ), findsNothing);
159
- expect (_labelForInput (titleInput, matching: 'default' ), findsNothing);
160
- expect (_labelForInput (widthInput, matching: 'set' ), findsNothing);
161
- expect (_labelForInput (widthInput, matching: 'default' ), findsNothing);
162
- expect (_labelForInput (heightInput, matching: 'set' ), findsNothing);
163
- expect (_labelForInput (heightInput, matching: 'default' ), findsOneWidget);
164
-
165
- // Verify required comments exist.
166
- expect (_requiredTextForInput (titleInput), findsOneWidget);
157
+ // Verify the labels and required are expected.
158
+ _labelsAndRequiredTextAreExpected (
159
+ titleInput,
160
+ inputExpectations: titleInputExpectations,
161
+ );
162
+ _labelsAndRequiredTextAreExpected (
163
+ widthInput,
164
+ inputExpectations: widthInputExpectations,
165
+ );
166
+ _labelsAndRequiredTextAreExpected (
167
+ heightInput,
168
+ inputExpectations: heightInputExpectations,
169
+ );
167
170
});
168
171
169
172
testWidgets ('inputs are expected for second group of editable arguments' , (
@@ -184,14 +187,15 @@ void main() {
184
187
expect (softWrapInput, findsOneWidget);
185
188
expect (alignInput, findsOneWidget);
186
189
187
- // Verify the labels are expected.
188
- expect (_labelForInput (softWrapInput, matching: 'set' ), findsNothing);
189
- expect (
190
- _labelForInput (softWrapInput, matching: 'default' ),
191
- findsOneWidget,
190
+ // Verify the labels and required are expected.
191
+ _labelsAndRequiredTextAreExpected (
192
+ softWrapInput,
193
+ inputExpectations: softWrapInputExpectations,
194
+ );
195
+ _labelsAndRequiredTextAreExpected (
196
+ alignInput,
197
+ inputExpectations: alignInputExpectations,
192
198
);
193
- expect (_labelForInput (alignInput, matching: 'set' ), findsOneWidget);
194
- expect (_labelForInput (alignInput, matching: 'default' ), findsNothing);
195
199
});
196
200
197
201
testWidgets ('softWrap input has expected options' , (tester) async {
@@ -537,6 +541,34 @@ Finder _labelForInput(Finder inputFinder, {required String matching}) {
537
541
Finder _requiredTextForInput (Finder inputFinder) =>
538
542
_helperTextForInput (inputFinder, matching: '*required' );
539
543
544
+ void _labelsAndRequiredTextAreExpected (
545
+ Finder inputFinder, {
546
+ required Map <String , bool > inputExpectations,
547
+ }) {
548
+ // Check for the existence/non-existence of the "set" badge.
549
+ final shouldBeSet = inputExpectations['isSet' ] == true ;
550
+ expect (
551
+ _labelForInput (inputFinder, matching: 'set' ),
552
+ shouldBeSet ? findsOneWidget : findsNothing,
553
+ reason: 'Expected to find ${shouldBeSet ? 'a' : 'no' } "set" badge.' ,
554
+ );
555
+ // Check for the existence/non-existence of the "default" badge.
556
+ final shouldBeDefault = inputExpectations['isDefault' ] == true ;
557
+ expect (
558
+ _labelForInput (inputFinder, matching: 'default' ),
559
+ shouldBeDefault ? findsOneWidget : findsNothing,
560
+ reason: 'Expected to find ${shouldBeDefault ? 'a' : 'no' } "default" badge.' ,
561
+ );
562
+ // Check for the existence/non-existence of the required text ('*').
563
+ final shouldBeRequired = inputExpectations['isRequired' ] == true ;
564
+ expect (
565
+ _requiredTextForInput (inputFinder),
566
+ shouldBeRequired ? findsOneWidget : findsNothing,
567
+ reason:
568
+ 'Expected to find ${shouldBeRequired ? 'the' : 'no' } "required" indicator.' ,
569
+ );
570
+ }
571
+
540
572
Finder _helperTextForInput (Finder inputFinder, {required String matching}) {
541
573
final rowFinder = find.ancestor (of: inputFinder, matching: find.byType (Row ));
542
574
return find.descendant (of: rowFinder, matching: find.richText (matching));
@@ -653,63 +685,79 @@ final activeLocationChangedEvent2 = ActiveLocationChangedEvent(
653
685
);
654
686
655
687
// Result 1
656
- final titleProperty = EditableArgument (
657
- name: 'title' ,
658
- value: 'Hello world!' ,
659
- type: 'string' ,
660
- isDefault: false ,
661
- isEditable: true ,
662
- isNullable: true ,
663
- isRequired: true ,
664
- hasArgument: false ,
665
- );
666
- final widthProperty = EditableArgument (
667
- name: 'width' ,
668
- displayValue: '100.0' ,
669
- type: 'double' ,
670
- isEditable: false ,
671
- isDefault: false ,
672
- errorText: 'Some reason for why this can\' t be edited.' ,
673
- isNullable: false ,
674
- value: 20.0 ,
675
- isRequired: false ,
676
- hasArgument: false ,
677
- );
678
- final heightProperty = EditableArgument (
679
- name: 'height' ,
680
- type: 'double' ,
681
- hasArgument: false ,
682
- isEditable: true ,
683
- isNullable: true ,
684
- value: 20.0 ,
685
- isDefault: true ,
686
- isRequired: false ,
687
- );
688
+ final titleProperty = EditableArgument .fromJson ({
689
+ 'name' : 'title' ,
690
+ 'value' : 'Hello world!' ,
691
+ 'type' : 'string' ,
692
+ 'isEditable' : true ,
693
+ 'isNullable' : true ,
694
+ 'isRequired' : true ,
695
+ 'hasArgument' : true ,
696
+ });
697
+ final titleInputExpectations = {
698
+ 'isSet' : true ,
699
+ 'isRequired' : true ,
700
+ 'isDefault' : false ,
701
+ };
702
+
703
+ final widthProperty = EditableArgument .fromJson ({
704
+ 'name' : 'width' ,
705
+ 'displayValue' : 'myWidth' ,
706
+ 'type' : 'double' ,
707
+ 'errorText' : 'Some reason why this can\' t be edited.' ,
708
+ 'isNullable' : false ,
709
+ 'isRequired' : false ,
710
+ 'hasArgument' : true ,
711
+ });
712
+ final widthInputExpectations = {
713
+ 'isSet' : true ,
714
+ 'isRequired' : false ,
715
+ 'isDefault' : false ,
716
+ };
717
+
718
+ final heightProperty = EditableArgument .fromJson ({
719
+ 'name' : 'height' ,
720
+ 'type' : 'double' ,
721
+ 'hasArgument' : false ,
722
+ 'isEditable' : true ,
723
+ 'isNullable' : true ,
724
+ 'defaultValue' : 20.0 ,
725
+ 'isRequired' : false ,
726
+ });
727
+ final heightInputExpectations = {
728
+ 'isSet' : false ,
729
+ 'isRequired' : false ,
730
+ 'isDefault' : true ,
731
+ };
688
732
final result1 = EditableArgumentsResult (
689
733
args: [titleProperty, widthProperty, heightProperty],
690
734
);
691
735
692
736
// Result 2
693
- final softWrapProperty = EditableArgument (
694
- name: 'softWrap' ,
695
- type: 'bool' ,
696
- isNullable: false ,
697
- value: true ,
698
- isDefault: true ,
699
- hasArgument: false ,
700
- isEditable: true ,
701
- isRequired: false ,
702
- );
703
- final alignProperty = EditableArgument (
704
- name: 'align' ,
705
- type: 'enum' ,
706
- isNullable: true ,
707
- hasArgument: true ,
708
- isDefault: false ,
709
- isRequired: false ,
710
- isEditable: true ,
711
- value: 'Alignment.center' ,
712
- options: [
737
+ final softWrapProperty = EditableArgument .fromJson ({
738
+ 'name' : 'softWrap' ,
739
+ 'type' : 'bool' ,
740
+ 'isNullable' : false ,
741
+ 'defaultValue' : true ,
742
+ 'hasArgument' : false ,
743
+ 'isEditable' : true ,
744
+ 'isRequired' : false ,
745
+ });
746
+ final softWrapInputExpectations = {
747
+ 'isSet' : false ,
748
+ 'isRequired' : false ,
749
+ 'isDefault' : true ,
750
+ };
751
+ final alignProperty = EditableArgument .fromJson ({
752
+ 'name' : 'align' ,
753
+ 'type' : 'enum' ,
754
+ 'isNullable' : true ,
755
+ 'hasArgument' : true ,
756
+ 'defaultValue' : 'Alignment.bottomLeft' ,
757
+ 'isRequired' : false ,
758
+ 'isEditable' : true ,
759
+ 'value' : 'Alignment.center' ,
760
+ 'options' : [
713
761
'Alignment.bottomCenter' ,
714
762
'Alignment.bottomLeft' ,
715
763
'Alignment.bottomRight' ,
@@ -720,7 +768,12 @@ final alignProperty = EditableArgument(
720
768
'Alignment.topLeft' ,
721
769
'Alignment.topRight' ,
722
770
],
723
- );
771
+ });
772
+ final alignInputExpectations = {
773
+ 'isSet' : true ,
774
+ 'isRequired' : false ,
775
+ 'isDefault' : false ,
776
+ };
724
777
final result2 = EditableArgumentsResult (
725
778
args: [softWrapProperty, alignProperty],
726
779
);
0 commit comments