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