1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_test/flutter_test.dart' ;
3
+ import 'package:zulip/widgets/dialog.dart' ;
3
4
4
5
/// In a widget test, check that showErrorDialog was called with the right text.
5
6
///
@@ -24,3 +25,34 @@ Widget checkErrorDialog(WidgetTester tester, {
24
25
find.descendant (of: find.byWidget (dialog),
25
26
matching: find.widgetWithText (TextButton , 'OK' )));
26
27
}
28
+
29
+ /// In a widget test, check that [showSuggestedActionDialog] was called
30
+ /// with the right text.
31
+ ///
32
+ /// Checks for a suggested-action dialog matching an expected title and message.
33
+ /// Fails if none is found.
34
+ ///
35
+ /// On success, returns a Record with the widget's action button first
36
+ /// and its cancel button second.
37
+ /// Tap the action button by calling `tester.tap(find.byWidget(actionButton))` .
38
+ (Widget , Widget ) checkSuggestedActionDialog (WidgetTester tester, {
39
+ required String expectedTitle,
40
+ required String expectedMessage,
41
+ String ? expectedActionButtonText,
42
+ }) {
43
+ final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
44
+ tester.widget (find.descendant (matchRoot: true ,
45
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
46
+ tester.widget (find.descendant (matchRoot: true ,
47
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
48
+
49
+ final actionButton = tester.widget (
50
+ find.descendant (of: find.byWidget (dialog),
51
+ matching: find.widgetWithText (TextButton , expectedActionButtonText ?? 'Continue' )));
52
+
53
+ final cancelButton = tester.widget (
54
+ find.descendant (of: find.byWidget (dialog),
55
+ matching: find.widgetWithText (TextButton , 'Cancel' )));
56
+
57
+ return (actionButton, cancelButton);
58
+ }
0 commit comments