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' ;
7
+ import 'package:url_launcher/url_launcher.dart' ;
5
8
import 'package:zulip/widgets/dialog.dart' ;
6
9
7
- /// In a widget test, check that showErrorDialog was called with the right text.
10
+ import '../model/binding.dart' ;
11
+
12
+ /// In a widget test, check that [showErrorDialog] was called with the right text.
8
13
///
9
14
/// Checks for an error dialog matching an expected title
10
15
/// and, optionally, matching an expected message. Fails if none is found.
@@ -14,27 +19,55 @@ import 'package:zulip/widgets/dialog.dart';
14
19
Widget checkErrorDialog (WidgetTester tester, {
15
20
required String expectedTitle,
16
21
String ? expectedMessage,
22
+ Uri ? expectedLearnMoreButtonUrl,
17
23
}) {
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
- }
24
+ switch (defaultTargetPlatform) {
25
+ case TargetPlatform .android:
26
+ case TargetPlatform .fuchsia:
27
+ case TargetPlatform .linux:
28
+ case TargetPlatform .windows:
29
+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
30
+ tester.widget (find.descendant (matchRoot: true ,
31
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
32
+ if (expectedMessage != null ) {
33
+ tester.widget (find.descendant (matchRoot: true ,
34
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
35
+ }
36
+ if (expectedLearnMoreButtonUrl != null ) {
37
+ check (testBinding.takeLaunchUrlCalls ()).single.equals ((
38
+ url: expectedLearnMoreButtonUrl,
39
+ mode: LaunchMode .inAppBrowserView));
40
+ }
41
+
42
+ return tester.widget (find.descendant (of: find.byWidget (dialog),
43
+ matching: find.widgetWithText (TextButton , 'OK' )));
25
44
26
- // TODO check "Learn more" button?
45
+ case TargetPlatform .iOS:
46
+ case TargetPlatform .macOS:
47
+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
48
+ tester.widget (find.descendant (matchRoot: true ,
49
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
50
+ if (expectedMessage != null ) {
51
+ tester.widget (find.descendant (matchRoot: true ,
52
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
53
+ }
54
+ if (expectedLearnMoreButtonUrl != null ) {
55
+ check (testBinding.takeLaunchUrlCalls ()).single.equals ((
56
+ url: expectedLearnMoreButtonUrl,
57
+ mode: LaunchMode .externalApplication));
58
+ }
27
59
28
- return tester.widget (
29
- find. descendant (of : find.byWidget (dialog),
30
- matching : find. widgetWithText ( TextButton , 'OK' )));
60
+ return tester.widget (find. descendant (of : find. byWidget (dialog),
61
+ matching : find.widgetWithText ( CupertinoDialogAction , 'OK' )));
62
+ }
31
63
}
32
64
33
- // TODO(#996) update this to check for per-platform flavors of alert dialog
34
65
/// Checks that there is no dialog.
35
66
/// Fails if one is found.
36
67
void checkNoDialog (WidgetTester tester) {
37
- check (find.byType (AlertDialog )).findsNothing ();
68
+ check (find.byType (Dialog )).findsNothing ();
69
+ check (find.bySubtype <AlertDialog >()).findsNothing ();
70
+ check (find.byType (CupertinoAlertDialog )).findsNothing ();
38
71
}
39
72
40
73
/// In a widget test, check that [showSuggestedActionDialog] was called
@@ -51,19 +84,35 @@ void checkNoDialog(WidgetTester tester) {
51
84
required String expectedMessage,
52
85
String ? expectedActionButtonText,
53
86
}) {
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)));
87
+ switch (defaultTargetPlatform) {
88
+ case TargetPlatform .android:
89
+ case TargetPlatform .fuchsia:
90
+ case TargetPlatform .linux:
91
+ case TargetPlatform .windows:
92
+ final dialog = tester.widget <AlertDialog >(find.bySubtype <AlertDialog >());
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)));
59
97
60
- final actionButton = tester.widget (
61
- find.descendant (of: find.byWidget (dialog),
62
- matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
98
+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
99
+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
100
+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
101
+ matching: find.widgetWithText (TextButton , 'Cancel' )));
102
+ return (actionButton, cancelButton);
63
103
64
- final cancelButton = tester.widget (
65
- find.descendant (of: find.byWidget (dialog),
66
- matching: find.widgetWithText (TextButton , 'Cancel' )));
104
+ case TargetPlatform .iOS:
105
+ case TargetPlatform .macOS:
106
+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
107
+ tester.widget (find.descendant (matchRoot: true ,
108
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
109
+ tester.widget (find.descendant (matchRoot: true ,
110
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
67
111
68
- return (actionButton, cancelButton);
112
+ final actionButton = tester.widget (find.descendant (of: find.byWidget (dialog),
113
+ matching: find.widgetWithText (CupertinoDialogAction , expectedActionButtonText ?? 'Continue' )));
114
+ final cancelButton = tester.widget (find.descendant (of: find.byWidget (dialog),
115
+ matching: find.widgetWithText (CupertinoDialogAction , 'Cancel' )));
116
+ return (actionButton, cancelButton);
117
+ }
69
118
}
0 commit comments