1
1
import 'package:checks/checks.dart' ;
2
+ import 'package:flutter/cupertino.dart' ;
3
+ import 'package:flutter/foundation.dart' ;
2
4
import 'package:flutter/material.dart' ;
3
5
import 'package:flutter_checks/flutter_checks.dart' ;
4
6
import 'package:flutter_test/flutter_test.dart' ;
5
7
import 'package:zulip/widgets/dialog.dart' ;
6
8
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.
8
10
///
9
11
/// Checks for an error dialog matching an expected title
10
12
/// and, optionally, matching an expected message. Fails if none is found.
@@ -15,22 +17,44 @@ Widget checkErrorDialog(WidgetTester tester, {
15
17
required String expectedTitle,
16
18
String ? expectedMessage,
17
19
}) {
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
+ }
25
45
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
+ }
29
49
}
30
50
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.
32
53
void checkNoErrorDialog (WidgetTester tester) {
54
+ check (find.byType (Dialog )).findsNothing ();
33
55
check (find.byType (AlertDialog )).findsNothing ();
56
+ check (find.bySubtype <AlertDialog >()).findsNothing ();
57
+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
34
58
}
35
59
36
60
/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -47,19 +71,35 @@ void checkNoErrorDialog(WidgetTester tester) {
47
71
required String expectedMessage,
48
72
String ? expectedActionButtonText,
49
73
}) {
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)));
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)));
55
84
56
- final actionButton = tester.widget (
57
- find.descendant (of: find.byWidget (dialog),
58
- 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);
59
90
60
- final cancelButton = tester.widget (
61
- find.descendant (of: find.byWidget (dialog),
62
- 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)));
63
98
64
- 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
+ }
65
105
}
0 commit comments