Skip to content

Commit

Permalink
widget tests: Add checkSuggestedActionDialog
Browse files Browse the repository at this point in the history
Like we added `checkErrorDialog` in 02fd562.
  • Loading branch information
chrisbobbe authored and gnprice committed Nov 14, 2024
1 parent 7aff885 commit 38213a8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/widgets/dialog_checks.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/widgets/dialog.dart';

/// In a widget test, check that showErrorDialog was called with the right text.
///
Expand All @@ -24,3 +25,34 @@ Widget checkErrorDialog(WidgetTester tester, {
find.descendant(of: find.byWidget(dialog),
matching: find.widgetWithText(TextButton, 'OK')));
}

/// In a widget test, check that [showSuggestedActionDialog] was called
/// with the right text.
///
/// Checks for a suggested-action dialog matching an expected title and message.
/// Fails if none is found.
///
/// On success, returns a Record with the widget's action button first
/// and its cancel button second.
/// Tap the action button by calling `tester.tap(find.byWidget(actionButton))`.
(Widget, Widget) checkSuggestedActionDialog(WidgetTester tester, {
required String expectedTitle,
required String expectedMessage,
String? expectedActionButtonText,
}) {
final dialog = tester.widget<AlertDialog>(find.byType(AlertDialog));
tester.widget(find.descendant(matchRoot: true,
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle)));
tester.widget(find.descendant(matchRoot: true,
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));

final actionButton = tester.widget(
find.descendant(of: find.byWidget(dialog),
matching: find.widgetWithText(TextButton, expectedActionButtonText ?? 'Continue')));

final cancelButton = tester.widget(
find.descendant(of: find.byWidget(dialog),
matching: find.widgetWithText(TextButton, 'Cancel')));

return (actionButton, cancelButton);
}

0 comments on commit 38213a8

Please sign in to comment.