-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33707b6
commit 02fd562
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
/// In a widget test, check that showErrorDialog was called with the right text. | ||
/// | ||
/// Checks for an error dialog matching an expected title | ||
/// and, optionally, matching an expected message. Fails if none is found. | ||
/// | ||
/// On success, returns the widget's "OK" button. | ||
/// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))`. | ||
Widget checkErrorDialog(WidgetTester tester, { | ||
required String expectedTitle, | ||
String? expectedMessage, | ||
}) { | ||
final dialog = tester.widget<AlertDialog>(find.byType(AlertDialog)); | ||
tester.widget(find.descendant(matchRoot: true, | ||
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle))); | ||
if (expectedMessage != null) { | ||
tester.widget(find.descendant(matchRoot: true, | ||
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage))); | ||
} | ||
|
||
return tester.widget( | ||
find.descendant(of: find.byWidget(dialog), | ||
matching: find.widgetWithText(TextButton, 'OK'))); | ||
} |