Skip to content

Commit 4239515

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 e2df7a9 commit 4239515

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

test/widgets/actions_test.dart

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ void main() {
3939

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

@@ -52,8 +51,9 @@ void main() {
5251
processedCount: 11, updatedCount: 3,
5352
firstProcessedId: null, lastProcessedId: null,
5453
foundOldest: true, foundNewest: true).toJson());
55-
markNarrowAsRead(context, narrow);
54+
final future = markNarrowAsRead(context, narrow);
5655
await tester.pump(Duration.zero);
56+
await future;
5757
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIs(IsOperand.unread));
5858
check(connection.lastRequest).isA<http.Request>()
5959
..method.equals('POST')
@@ -76,8 +76,9 @@ void main() {
7676
processedCount: 11, updatedCount: 3,
7777
firstProcessedId: null, lastProcessedId: null,
7878
foundOldest: true, foundNewest: true).toJson());
79-
markNarrowAsRead(context, narrow);
79+
final future = markNarrowAsRead(context, narrow);
8080
await tester.pump(Duration.zero);
81+
await future;
8182
check(connection.lastRequest).isA<http.Request>()
8283
..method.equals('POST')
8384
..url.path.equals('/api/v1/messages/flags/narrow')
@@ -101,9 +102,9 @@ void main() {
101102
processedCount: 11, updatedCount: 3,
102103
firstProcessedId: null, lastProcessedId: null,
103104
foundOldest: true, foundNewest: true).toJson());
104-
markNarrowAsRead(context, narrow);
105+
final future = markNarrowAsRead(context, narrow);
105106
await tester.pump(Duration.zero);
106-
await tester.pumpAndSettle();
107+
await future;
107108
check(store.unreads.oldUnreadsMissing).isFalse();
108109
});
109110

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

116117
connection.zulipFeatureLevel = 154;
117118
connection.prepare(json: {});
118-
markNarrowAsRead(context, narrow);
119+
final future = markNarrowAsRead(context, narrow);
119120
await tester.pump(Duration.zero);
121+
await future;
120122
check(connection.lastRequest).isA<http.Request>()
121123
..method.equals('POST')
122124
..url.path.equals('/api/v1/mark_all_as_read')
@@ -133,8 +135,9 @@ void main() {
133135
await prepare(tester);
134136
connection.zulipFeatureLevel = 154;
135137
connection.prepare(json: {});
136-
markNarrowAsRead(context, narrow);
138+
final future = markNarrowAsRead(context, narrow);
137139
await tester.pump(Duration.zero);
140+
await future;
138141
check(connection.lastRequest).isA<http.Request>()
139142
..method.equals('POST')
140143
..url.path.equals('/api/v1/mark_stream_as_read')
@@ -148,8 +151,9 @@ void main() {
148151
await prepare(tester);
149152
connection.zulipFeatureLevel = 154;
150153
connection.prepare(json: {});
151-
markNarrowAsRead(context, narrow);
154+
final future = markNarrowAsRead(context, narrow);
152155
await tester.pump(Duration.zero);
156+
await future;
153157
check(connection.lastRequest).isA<http.Request>()
154158
..method.equals('POST')
155159
..url.path.equals('/api/v1/mark_topic_as_read')
@@ -170,8 +174,9 @@ void main() {
170174
connection.zulipFeatureLevel = 154;
171175
connection.prepare(json:
172176
UpdateMessageFlagsResult(messages: [message.id]).toJson());
173-
markNarrowAsRead(context, narrow);
177+
final future = markNarrowAsRead(context, narrow);
174178
await tester.pump(Duration.zero);
179+
await future;
175180
check(connection.lastRequest).isA<http.Request>()
176181
..method.equals('POST')
177182
..url.path.equals('/api/v1/messages/flags')
@@ -190,8 +195,9 @@ void main() {
190195
connection.zulipFeatureLevel = 154;
191196
connection.prepare(json:
192197
UpdateMessageFlagsResult(messages: [message.id]).toJson());
193-
markNarrowAsRead(context, narrow);
198+
final future = markNarrowAsRead(context, narrow);
194199
await tester.pump(Duration.zero);
200+
await future;
195201
check(connection.lastRequest).isA<http.Request>()
196202
..method.equals('POST')
197203
..url.path.equals('/api/v1/messages/flags')
@@ -272,7 +278,7 @@ void main() {
272278
processedCount: 20, updatedCount: 10,
273279
firstProcessedId: 2000, lastProcessedId: 2023,
274280
foundOldest: false, foundNewest: true).toJson());
275-
await tester.pumpAndSettle();
281+
await tester.pump(Duration.zero);
276282
check(find.bySubtype<SnackBar>().evaluate()).length.equals(1);
277283
check(connection.lastRequest).isA<http.Request>()
278284
..method.equals('POST')
@@ -310,8 +316,6 @@ void main() {
310316
'op': 'add',
311317
'flag': 'read',
312318
});
313-
314-
await tester.pumpAndSettle();
315319
checkErrorDialog(tester,
316320
expectedTitle: onFailedTitle,
317321
expectedMessage: zulipLocalizations.errorInvalidResponse);
@@ -323,7 +327,6 @@ void main() {
323327
connection.prepare(exception: http.ClientException('Oops'));
324328
final didPass = invokeUpdateMessageFlagsStartingFromAnchor();
325329
await tester.pump(Duration.zero);
326-
await tester.pumpAndSettle();
327330
checkErrorDialog(tester,
328331
expectedTitle: onFailedTitle,
329332
expectedMessage: 'NetworkException: Oops (ClientException: Oops)');

0 commit comments

Comments
 (0)