11import 'package:checks/checks.dart' ;
2+ import 'package:flutter/cupertino.dart' ;
3+ import 'package:flutter/foundation.dart' ;
24import 'package:flutter/material.dart' ;
35import 'package:flutter_checks/flutter_checks.dart' ;
46import 'package:flutter_test/flutter_test.dart' ;
57import 'package:zulip/widgets/dialog.dart' ;
68
7- /// In a widget test, check that showErrorDialog was called with the right text.
9+ /// In a widget test, check that [ showErrorDialog] was called with the right text.
810///
911/// Checks for an error dialog matching an expected title
1012/// and, optionally, matching an expected message. Fails if none is found.
@@ -15,26 +17,41 @@ Widget checkErrorDialog(WidgetTester tester, {
1517 required String expectedTitle,
1618 String ? expectedMessage,
1719}) {
18- final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
19- tester.widget (find.descendant (matchRoot: true ,
20- of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
21- if (expectedMessage != null ) {
22- tester.widget (find.descendant (matchRoot: true ,
23- of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
24- }
25-
26- // TODO check "Learn more" button?
20+ switch (defaultTargetPlatform) {
21+ case TargetPlatform .android:
22+ case TargetPlatform .fuchsia:
23+ case TargetPlatform .linux:
24+ case TargetPlatform .windows:
25+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
26+ tester.widget (find.descendant (matchRoot: true ,
27+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
28+ if (expectedMessage != null ) {
29+ tester.widget (find.descendant (matchRoot: true ,
30+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
31+ }
32+ return tester.widget (find.descendant (of: find.byWidget (dialog),
33+ matching: find.widgetWithText (TextButton , 'OK' )));
2734
28- return tester.widget (
29- find.descendant (of: find.byWidget (dialog),
30- matching: find.widgetWithText (TextButton , 'OK' )));
35+ case TargetPlatform .iOS:
36+ case TargetPlatform .macOS:
37+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
38+ tester.widget (find.descendant (matchRoot: true ,
39+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
40+ if (expectedMessage != null ) {
41+ tester.widget (find.descendant (matchRoot: true ,
42+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
43+ }
44+ return tester.widget (find.descendant (of: find.byWidget (dialog),
45+ matching: find.widgetWithText (CupertinoDialogAction , 'OK' )));
46+ }
3147}
3248
33- // TODO(#996) update this to check for per-platform flavors of alert dialog
3449/// Checks that there is no dialog.
3550/// Fails if one is found.
3651void checkNoDialog (WidgetTester tester) {
37- check (find.byType (AlertDialog )).findsNothing ();
52+ check (find.byType (Dialog )).findsNothing ();
53+ check (find.bySubtype <AlertDialog >()).findsNothing ();
54+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
3855}
3956
4057/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -51,19 +68,35 @@ void checkNoDialog(WidgetTester tester) {
5168 required String expectedMessage,
5269 String ? expectedActionButtonText,
5370}) {
54- final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
55- tester.widget (find.descendant (matchRoot: true ,
56- of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
57- tester.widget (find.descendant (matchRoot: true ,
58- of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
71+ switch (defaultTargetPlatform) {
72+ case TargetPlatform .android:
73+ case TargetPlatform .fuchsia:
74+ case TargetPlatform .linux:
75+ case TargetPlatform .windows:
76+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
77+ tester.widget (find.descendant (matchRoot: true ,
78+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
79+ tester.widget (find.descendant (matchRoot: true ,
80+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
5981
60- final actionButton = tester.widget (
61- find.descendant (of: find.byWidget (dialog),
62- matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
82+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
83+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
84+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
85+ matching: find.widgetWithText (TextButton , 'Cancel' )));
86+ return (actionButton, cancelButton);
6387
64- final cancelButton = tester.widget (
65- find.descendant (of: find.byWidget (dialog),
66- matching: find.widgetWithText (TextButton , 'Cancel' )));
88+ case TargetPlatform .iOS:
89+ case TargetPlatform .macOS:
90+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
91+ tester.widget (find.descendant (matchRoot: true ,
92+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
93+ tester.widget (find.descendant (matchRoot: true ,
94+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
6795
68- return (actionButton, cancelButton);
96+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
97+ matching: find.widgetWithText (CupertinoDialogAction , expectedActionButtonText ?? 'Continue' )));
98+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
99+ matching: find.widgetWithText (CupertinoDialogAction , 'Cancel' )));
100+ return (actionButton, cancelButton);
101+ }
69102}
0 commit comments