1+ import 'package:flutter/cupertino.dart' ;
2+ import 'package:flutter/foundation.dart' ;
13import 'package:checks/checks.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,22 +17,50 @@ 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' )));
2535
26- return tester.widget (
27- find.descendant (of: find.byWidget (dialog),
28- matching: find.widgetWithText (TextButton , 'OK' )));
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+ }
45+
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
51+ /// Checks that there is no error dialog.
52+ /// Fails if one is found.
3253void checkNoErrorDialog (WidgetTester tester) {
33- check (find.byType (AlertDialog )).findsNothing ();
54+ switch (defaultTargetPlatform) {
55+ case TargetPlatform .android:
56+ case TargetPlatform .fuchsia:
57+ case TargetPlatform .linux:
58+ case TargetPlatform .windows:
59+ check (find.bySubtype <AlertDialog >()).findsNothing ();
60+ case TargetPlatform .iOS:
61+ case TargetPlatform .macOS:
62+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
63+ }
3464}
3565
3666/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -47,19 +77,39 @@ void checkNoErrorDialog(WidgetTester tester) {
4777 required String expectedMessage,
4878 String ? expectedActionButtonText,
4979}) {
50- final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
51- tester.widget (find.descendant (matchRoot: true ,
52- of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
53- tester.widget (find.descendant (matchRoot: true ,
54- of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
80+ switch (defaultTargetPlatform) {
81+ case TargetPlatform .android:
82+ case TargetPlatform .fuchsia:
83+ case TargetPlatform .linux:
84+ case TargetPlatform .windows:
85+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
86+ tester.widget (find.descendant (matchRoot: true ,
87+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
88+ tester.widget (find.descendant (matchRoot: true ,
89+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
5590
56- final actionButton = tester.widget (
57- find.descendant (of: find.byWidget (dialog),
58- matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
91+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
92+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
5993
60- final cancelButton = tester.widget (
61- find.descendant (of: find.byWidget (dialog),
62- matching: find.widgetWithText (TextButton , 'Cancel' )));
94+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
95+ matching: find.widgetWithText (TextButton , 'Cancel' )));
6396
64- return (actionButton, cancelButton);
65- }
97+ return (actionButton, cancelButton);
98+
99+ case TargetPlatform .iOS:
100+ case TargetPlatform .macOS:
101+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
102+ tester.widget (find.descendant (matchRoot: true ,
103+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
104+ tester.widget (find.descendant (matchRoot: true ,
105+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
106+
107+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
108+ matching: find.widgetWithText (CupertinoDialogAction , expectedActionButtonText ?? 'Continue' )));
109+
110+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
111+ matching: find.widgetWithText (CupertinoDialogAction , 'Cancel' )));
112+
113+ return (actionButton, cancelButton);
114+ }
115+ }
0 commit comments