Skip to content

Commit 9ef8628

Browse files
committed
actions test: Await all responses; cut pumpAndSettle
This ensures that if one of these markNarrowAsRead calls were to change behavior so that it no longer completed within the test (and then possibly threw an error, or failed to ever complete at all), the test would catch that.
1 parent a1b5579 commit 9ef8628

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

test/widgets/actions_test.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ void main() {
5252
processedCount: 11, updatedCount: 3,
5353
firstProcessedId: null, lastProcessedId: null,
5454
foundOldest: true, foundNewest: true).toJson());
55-
markNarrowAsRead(context, narrow);
55+
final future = markNarrowAsRead(context, narrow);
5656
await tester.pump(Duration.zero);
57+
await future;
5758
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIs(IsOperand.unread));
5859
check(connection.lastRequest).isA<http.Request>()
5960
..method.equals('POST')
@@ -76,8 +77,9 @@ void main() {
7677
processedCount: 11, updatedCount: 3,
7778
firstProcessedId: null, lastProcessedId: null,
7879
foundOldest: true, foundNewest: true).toJson());
79-
markNarrowAsRead(context, narrow);
80+
final future = markNarrowAsRead(context, narrow);
8081
await tester.pump(Duration.zero);
82+
await future;
8183
check(connection.lastRequest).isA<http.Request>()
8284
..method.equals('POST')
8385
..url.path.equals('/api/v1/messages/flags/narrow')
@@ -101,9 +103,9 @@ void main() {
101103
processedCount: 11, updatedCount: 3,
102104
firstProcessedId: null, lastProcessedId: null,
103105
foundOldest: true, foundNewest: true).toJson());
104-
markNarrowAsRead(context, narrow);
106+
final future = markNarrowAsRead(context, narrow);
105107
await tester.pump(Duration.zero);
106-
await tester.pumpAndSettle();
108+
await future;
107109
check(store.unreads.oldUnreadsMissing).isFalse();
108110
});
109111

@@ -115,8 +117,9 @@ void main() {
115117

116118
connection.zulipFeatureLevel = 154;
117119
connection.prepare(json: {});
118-
markNarrowAsRead(context, narrow);
120+
final future = markNarrowAsRead(context, narrow);
119121
await tester.pump(Duration.zero);
122+
await future;
120123
check(connection.lastRequest).isA<http.Request>()
121124
..method.equals('POST')
122125
..url.path.equals('/api/v1/mark_all_as_read')
@@ -133,8 +136,9 @@ void main() {
133136
await prepare(tester);
134137
connection.zulipFeatureLevel = 154;
135138
connection.prepare(json: {});
136-
markNarrowAsRead(context, narrow);
139+
final future = markNarrowAsRead(context, narrow);
137140
await tester.pump(Duration.zero);
141+
await future;
138142
check(connection.lastRequest).isA<http.Request>()
139143
..method.equals('POST')
140144
..url.path.equals('/api/v1/mark_stream_as_read')
@@ -148,8 +152,9 @@ void main() {
148152
await prepare(tester);
149153
connection.zulipFeatureLevel = 154;
150154
connection.prepare(json: {});
151-
markNarrowAsRead(context, narrow);
155+
final future = markNarrowAsRead(context, narrow);
152156
await tester.pump(Duration.zero);
157+
await future;
153158
check(connection.lastRequest).isA<http.Request>()
154159
..method.equals('POST')
155160
..url.path.equals('/api/v1/mark_topic_as_read')
@@ -170,8 +175,9 @@ void main() {
170175
connection.zulipFeatureLevel = 154;
171176
connection.prepare(json:
172177
UpdateMessageFlagsResult(messages: [message.id]).toJson());
173-
markNarrowAsRead(context, narrow);
178+
final future = markNarrowAsRead(context, narrow);
174179
await tester.pump(Duration.zero);
180+
await future;
175181
check(connection.lastRequest).isA<http.Request>()
176182
..method.equals('POST')
177183
..url.path.equals('/api/v1/messages/flags')
@@ -190,8 +196,9 @@ void main() {
190196
connection.zulipFeatureLevel = 154;
191197
connection.prepare(json:
192198
UpdateMessageFlagsResult(messages: [message.id]).toJson());
193-
markNarrowAsRead(context, narrow);
199+
final future = markNarrowAsRead(context, narrow);
194200
await tester.pump(Duration.zero);
201+
await future;
195202
check(connection.lastRequest).isA<http.Request>()
196203
..method.equals('POST')
197204
..url.path.equals('/api/v1/messages/flags')
@@ -272,7 +279,7 @@ void main() {
272279
processedCount: 20, updatedCount: 10,
273280
firstProcessedId: 2000, lastProcessedId: 2023,
274281
foundOldest: false, foundNewest: true).toJson());
275-
await tester.pumpAndSettle();
282+
await tester.pump(Duration.zero);
276283
check(find.bySubtype<SnackBar>().evaluate()).length.equals(1);
277284
check(connection.lastRequest).isA<http.Request>()
278285
..method.equals('POST')
@@ -310,8 +317,6 @@ void main() {
310317
'op': 'add',
311318
'flag': 'read',
312319
});
313-
314-
await tester.pumpAndSettle();
315320
checkErrorDialog(tester,
316321
expectedTitle: onFailedTitle,
317322
expectedMessage: zulipLocalizations.errorInvalidResponse);
@@ -323,7 +328,6 @@ void main() {
323328
connection.prepare(exception: http.ClientException('Oops'));
324329
final didPass = invokeUpdateMessageFlagsStartingFromAnchor();
325330
await tester.pump(Duration.zero);
326-
await tester.pumpAndSettle();
327331
checkErrorDialog(tester,
328332
expectedTitle: onFailedTitle,
329333
expectedMessage: 'NetworkException: Oops (ClientException: Oops)');

0 commit comments

Comments
 (0)