Skip to content

Commit 9d6a859

Browse files
committed
widget tests: Add checkSuggestedActionDialog
Like we added `checkErrorDialog` in 02fd562.
1 parent b0307db commit 9d6a859

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/widgets/dialog_checks.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:zulip/widgets/dialog.dart';
34

45
/// In a widget test, check that showErrorDialog was called with the right text.
56
///
@@ -24,3 +25,34 @@ Widget checkErrorDialog(WidgetTester tester, {
2425
find.descendant(of: find.byWidget(dialog),
2526
matching: find.widgetWithText(TextButton, 'OK')));
2627
}
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

Comments
 (0)