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,24 +17,43 @@ 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- }
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+
33+ return tester.widget (find.descendant (of: find.byWidget (dialog),
34+ matching: find.widgetWithText (TextButton , 'OK' )));
35+
36+ case TargetPlatform .iOS:
37+ case TargetPlatform .macOS:
38+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
39+ tester.widget (find.descendant (matchRoot: true ,
40+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
41+ if (expectedMessage != null ) {
42+ tester.widget (find.descendant (matchRoot: true ,
43+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
44+ }
2545
26- return tester.widget (
27- find. descendant (of : find.byWidget (dialog),
28- matching : find. widgetWithText ( TextButton , 'OK' )));
46+ return tester.widget (find. descendant (of : find. byWidget (dialog),
47+ matching : find.widgetWithText ( CupertinoDialogAction , 'OK' )));
48+ }
2949}
3050
31- // TODO(#996) update this to check for per-platform flavors of alert dialog
3251/// Checks that there is no dialog.
3352/// Fails if one is found.
3453void checkNoDialog (WidgetTester tester) {
35- check (find.byType (AlertDialog )).findsNothing ();
54+ check (find.byType (Dialog )).findsNothing ();
55+ check (find.bySubtype <AlertDialog >()).findsNothing ();
56+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
3657}
3758
3859/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -49,19 +70,35 @@ void checkNoDialog(WidgetTester tester) {
4970 required String expectedMessage,
5071 String ? expectedActionButtonText,
5172}) {
52- final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
53- tester.widget (find.descendant (matchRoot: true ,
54- of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
55- tester.widget (find.descendant (matchRoot: true ,
56- of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
73+ switch (defaultTargetPlatform) {
74+ case TargetPlatform .android:
75+ case TargetPlatform .fuchsia:
76+ case TargetPlatform .linux:
77+ case TargetPlatform .windows:
78+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
79+ tester.widget (find.descendant (matchRoot: true ,
80+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
81+ tester.widget (find.descendant (matchRoot: true ,
82+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
5783
58- final actionButton = tester.widget (
59- find.descendant (of: find.byWidget (dialog),
60- matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
84+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
85+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
86+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
87+ matching: find.widgetWithText (TextButton , 'Cancel' )));
88+ return (actionButton, cancelButton);
6189
62- final cancelButton = tester.widget (
63- find.descendant (of: find.byWidget (dialog),
64- matching: find.widgetWithText (TextButton , 'Cancel' )));
90+ case TargetPlatform .iOS:
91+ case TargetPlatform .macOS:
92+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
93+ tester.widget (find.descendant (matchRoot: true ,
94+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
95+ tester.widget (find.descendant (matchRoot: true ,
96+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
6597
66- return (actionButton, cancelButton);
98+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
99+ matching: find.widgetWithText (CupertinoDialogAction , expectedActionButtonText ?? 'Continue' )));
100+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
101+ matching: find.widgetWithText (CupertinoDialogAction , 'Cancel' )));
102+ return (actionButton, cancelButton);
103+ }
67104}
0 commit comments