Skip to content

actions test: Await all responses; cut pumpAndSettle #993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions test/widgets/actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ void main() {

await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: const Scaffold(body: Placeholder())));
// global store, per-account store get loaded
await tester.pumpAndSettle();
await tester.pump();
context = tester.element(find.byType(Placeholder));
}

Expand All @@ -52,8 +51,9 @@ void main() {
processedCount: 11, updatedCount: 3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more call-site of pumpAndSettle from prepare that can be cut too.

firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: true).toJson());
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIs(IsOperand.unread));
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
Expand All @@ -76,8 +76,9 @@ void main() {
processedCount: 11, updatedCount: 3,
firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: true).toJson());
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags/narrow')
Expand All @@ -101,9 +102,9 @@ void main() {
processedCount: 11, updatedCount: 3,
firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: true).toJson());
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await tester.pumpAndSettle();
await future;
check(store.unreads.oldUnreadsMissing).isFalse();
});

Expand All @@ -115,8 +116,9 @@ void main() {

connection.zulipFeatureLevel = 154;
connection.prepare(json: {});
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/mark_all_as_read')
Expand All @@ -133,8 +135,9 @@ void main() {
await prepare(tester);
connection.zulipFeatureLevel = 154;
connection.prepare(json: {});
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/mark_stream_as_read')
Expand All @@ -148,8 +151,9 @@ void main() {
await prepare(tester);
connection.zulipFeatureLevel = 154;
connection.prepare(json: {});
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/mark_topic_as_read')
Expand All @@ -170,8 +174,9 @@ void main() {
connection.zulipFeatureLevel = 154;
connection.prepare(json:
UpdateMessageFlagsResult(messages: [message.id]).toJson());
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags')
Expand All @@ -190,8 +195,9 @@ void main() {
connection.zulipFeatureLevel = 154;
connection.prepare(json:
UpdateMessageFlagsResult(messages: [message.id]).toJson());
markNarrowAsRead(context, narrow);
final future = markNarrowAsRead(context, narrow);
await tester.pump(Duration.zero);
await future;
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags')
Expand Down Expand Up @@ -272,7 +278,7 @@ void main() {
processedCount: 20, updatedCount: 10,
firstProcessedId: 2000, lastProcessedId: 2023,
foundOldest: false, foundNewest: true).toJson());
await tester.pumpAndSettle();
await tester.pump(Duration.zero);
check(find.bySubtype<SnackBar>().evaluate()).length.equals(1);
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
Expand Down Expand Up @@ -310,8 +316,6 @@ void main() {
'op': 'add',
'flag': 'read',
});

await tester.pumpAndSettle();
checkErrorDialog(tester,
expectedTitle: onFailedTitle,
expectedMessage: zulipLocalizations.errorInvalidResponse);
Expand All @@ -323,7 +327,6 @@ void main() {
connection.prepare(exception: http.ClientException('Oops'));
final didPass = invokeUpdateMessageFlagsStartingFromAnchor();
await tester.pump(Duration.zero);
await tester.pumpAndSettle();
checkErrorDialog(tester,
expectedTitle: onFailedTitle,
expectedMessage: 'NetworkException: Oops (ClientException: Oops)');
Expand Down