Skip to content

Commit

Permalink
test [nfc]: Factor out checkNoErrorDialog helper
Browse files Browse the repository at this point in the history
With zulip#996, these tests will have to start checking for separate
per-platform flavors of alert dialog. Best if they all do so through
this one codepath.
  • Loading branch information
chrisbobbe authored and gnprice committed Jan 23, 2025
1 parent cb1eb7d commit c0b9a5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions test/widgets/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ void main() {
check(ZulipApp.ready).value.isFalse();
await tester.pump();
check(findSnackBarByText(message).evaluate()).isEmpty();
check(find.byType(AlertDialog).evaluate()).isEmpty();
checkNoErrorDialog(tester);

check(ZulipApp.ready).value.isTrue();
// After app startup, reportErrorToUserBriefly displays a SnackBar.
reportErrorToUserBriefly(message, details: details);
await tester.pumpAndSettle();
check(findSnackBarByText(message).evaluate()).single;
check(find.byType(AlertDialog).evaluate()).isEmpty();
checkNoErrorDialog(tester);

// Open the error details dialog.
await tester.tap(find.text('Details'));
Expand Down
9 changes: 3 additions & 6 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ void main() {
await setupAndTapSend(tester, prepareResponse: (int messageId) {
connection.prepare(json: SendMessageResult(id: messageId).toJson());
});
final errorDialogs = tester.widgetList(find.byType(AlertDialog));
check(errorDialogs).isEmpty();
checkNoErrorDialog(tester);
});

testWidgets('ZulipApiException', (tester) async {
Expand Down Expand Up @@ -506,8 +505,7 @@ void main() {
check(call.allowMultiple).equals(true);
check(call.type).equals(FileType.media);

final errorDialogs = tester.widgetList(find.byType(AlertDialog));
check(errorDialogs).isEmpty();
checkNoErrorDialog(tester);

check(controller!.content.text)
.equals('see image: [Uploading image.jpg…]()\n\n');
Expand Down Expand Up @@ -566,8 +564,7 @@ void main() {
check(call.source).equals(ImageSource.camera);
check(call.requestFullMetadata).equals(false);

final errorDialogs = tester.widgetList(find.byType(AlertDialog));
check(errorDialogs).isEmpty();
checkNoErrorDialog(tester);

check(controller!.content.text)
.equals('see image: [Uploading image.jpg…]()\n\n');
Expand Down
7 changes: 7 additions & 0 deletions test/widgets/dialog_checks.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
import 'package:flutter_checks/flutter_checks.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/widgets/dialog.dart';

Expand Down Expand Up @@ -26,6 +28,11 @@ Widget checkErrorDialog(WidgetTester tester, {
matching: find.widgetWithText(TextButton, 'OK')));
}

// TODO(#996) update this to check for per-platform flavors of alert dialog
void checkNoErrorDialog(WidgetTester tester) {
check(find.byType(AlertDialog)).findsNothing();
}

/// In a widget test, check that [showSuggestedActionDialog] was called
/// with the right text.
///
Expand Down

0 comments on commit c0b9a5d

Please sign in to comment.