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,44 @@ 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-
2620 // TODO check "Learn more" button?
21+ switch (defaultTargetPlatform) {
22+ case TargetPlatform .android:
23+ case TargetPlatform .fuchsia:
24+ case TargetPlatform .linux:
25+ case TargetPlatform .windows:
26+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
27+ tester.widget (find.descendant (matchRoot: true ,
28+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
29+ if (expectedMessage != null ) {
30+ tester.widget (find.descendant (matchRoot: true ,
31+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
32+ }
33+
34+ return tester.widget (find.descendant (of: find.byWidget (dialog),
35+ matching: find.widgetWithText (TextButton , 'OK' )));
2736
28- return tester.widget (
29- find.descendant (of: find.byWidget (dialog),
30- matching: find.widgetWithText (TextButton , 'OK' )));
37+ case TargetPlatform .iOS:
38+ case TargetPlatform .macOS:
39+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
40+ tester.widget (find.descendant (matchRoot: true ,
41+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
42+ if (expectedMessage != null ) {
43+ tester.widget (find.descendant (matchRoot: true ,
44+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
45+ }
46+
47+ return tester.widget (find.descendant (of: find.byWidget (dialog),
48+ matching: find.widgetWithText (CupertinoDialogAction , 'OK' )));
49+ }
3150}
3251
33- // TODO(#996) update this to check for per-platform flavors of alert dialog
3452/// Checks that there is no dialog.
3553/// Fails if one is found.
3654void checkNoDialog (WidgetTester tester) {
37- check (find.byType (AlertDialog )).findsNothing ();
55+ check (find.byType (Dialog )).findsNothing ();
56+ check (find.bySubtype <AlertDialog >()).findsNothing ();
57+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
3858}
3959
4060/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -51,19 +71,35 @@ void checkNoDialog(WidgetTester tester) {
5171 required String expectedMessage,
5272 String ? expectedActionButtonText,
5373}) {
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)));
74+ switch (defaultTargetPlatform) {
75+ case TargetPlatform .android:
76+ case TargetPlatform .fuchsia:
77+ case TargetPlatform .linux:
78+ case TargetPlatform .windows:
79+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
80+ tester.widget (find.descendant (matchRoot: true ,
81+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
82+ tester.widget (find.descendant (matchRoot: true ,
83+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
5984
60- final actionButton = tester.widget (
61- find.descendant (of: find.byWidget (dialog),
62- matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
85+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
86+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
87+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
88+ matching: find.widgetWithText (TextButton , 'Cancel' )));
89+ return (actionButton, cancelButton);
6390
64- final cancelButton = tester.widget (
65- find.descendant (of: find.byWidget (dialog),
66- matching: find.widgetWithText (TextButton , 'Cancel' )));
91+ case TargetPlatform .iOS:
92+ case TargetPlatform .macOS:
93+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
94+ tester.widget (find.descendant (matchRoot: true ,
95+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
96+ tester.widget (find.descendant (matchRoot: true ,
97+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
6798
68- return (actionButton, cancelButton);
99+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
100+ matching: find.widgetWithText (CupertinoDialogAction , expectedActionButtonText ?? 'Continue' )));
101+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
102+ matching: find.widgetWithText (CupertinoDialogAction , 'Cancel' )));
103+ return (actionButton, cancelButton);
104+ }
69105}
0 commit comments