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+ import '../model/binding.dart' ;
10+
11+ /// In a widget test, check that [showErrorDialog] was called with the right text.
812///
913/// Checks for an error dialog matching an expected title
1014/// and, optionally, matching an expected message. Fails if none is found.
@@ -15,26 +19,41 @@ Widget checkErrorDialog(WidgetTester tester, {
1519 required String expectedTitle,
1620 String ? expectedMessage,
1721}) {
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?
22+ switch (defaultTargetPlatform) {
23+ case TargetPlatform .android:
24+ case TargetPlatform .fuchsia:
25+ case TargetPlatform .linux:
26+ case TargetPlatform .windows:
27+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
28+ tester.widget (find.descendant (matchRoot: true ,
29+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
30+ if (expectedMessage != null ) {
31+ tester.widget (find.descendant (matchRoot: true ,
32+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
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+ return tester.widget (find.descendant (of: find.byWidget (dialog),
47+ matching: find.widgetWithText (CupertinoDialogAction , 'OK' )));
48+ }
3149}
3250
33- // TODO(#996) update this to check for per-platform flavors of alert dialog
3451/// Checks that there is no dialog.
3552/// Fails if one is found.
3653void checkNoDialog (WidgetTester tester) {
37- check (find.byType (AlertDialog )).findsNothing ();
54+ check (find.byType (Dialog )).findsNothing ();
55+ check (find.bySubtype <AlertDialog >()).findsNothing ();
56+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
3857}
3958
4059/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -51,19 +70,35 @@ void checkNoDialog(WidgetTester tester) {
5170 required String expectedMessage,
5271 String ? expectedActionButtonText,
5372}) {
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)));
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)));
5983
60- final actionButton = tester.widget (
61- find.descendant (of: find.byWidget (dialog),
62- 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);
6389
64- final cancelButton = tester.widget (
65- find.descendant (of: find.byWidget (dialog),
66- 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)));
6797
68- 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+ }
69104}
0 commit comments