Skip to content

Commit 4065209

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Make addStream async
This is the next step toward making handleEvent async.
1 parent 9a9db2c commit 4065209

File tree

7 files changed

+50
-36
lines changed

7 files changed

+50
-36
lines changed

test/model/compose_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ hello
237237
required String name,
238238
String? topic,
239239
int? nearMessageId,
240-
}) {
240+
}) async {
241241
assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment');
242242
final store = eg.store();
243-
store.addStream(eg.stream(streamId: streamId, name: name));
243+
await store.addStream(eg.stream(streamId: streamId, name: name));
244244
final narrow = topic == null
245245
? StreamNarrow(streamId)
246246
: TopicNarrow(streamId, topic);
@@ -340,7 +340,7 @@ hello
340340
final stream = eg.stream(streamId: 1, name: 'test here');
341341
final message = eg.streamMessage(sender: sender, stream: stream, topic: 'some topic');
342342
final store = eg.store();
343-
store.addStream(stream);
343+
await store.addStream(stream);
344344
await store.addUser(sender);
345345

346346
check(quoteAndReplyPlaceholder(store, message: message)).equals('''

test/model/message_list_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ void main() async {
3939
Future<void> prepare({Narrow narrow = const AllMessagesNarrow()}) async {
4040
final stream = eg.stream();
4141
subscription = eg.subscription(stream);
42-
store = eg.store()
43-
..addStream(stream)..addSubscription(subscription);
42+
store = eg.store();
43+
await store.addStream(stream);
44+
store.addSubscription(subscription);
4445
connection = store.connection as FakeApiConnection;
4546
notifiedCount = 0;
4647
model = MessageListView.init(store: store, narrow: narrow)
@@ -615,7 +616,7 @@ void main() async {
615616
test('in StreamNarrow', () async {
616617
final stream = eg.stream(streamId: 1, name: 'stream 1');
617618
await prepare(narrow: StreamNarrow(stream.streamId));
618-
store.addStream(stream);
619+
await store.addStream(stream);
619620
store.addSubscription(eg.subscription(stream, isMuted: true));
620621
store.addUserTopic(stream, 'A', UserTopicVisibilityPolicy.unmuted);
621622
store.addUserTopic(stream, 'C', UserTopicVisibilityPolicy.muted);
@@ -659,7 +660,7 @@ void main() async {
659660
test('in TopicNarrow', () async {
660661
final stream = eg.stream(streamId: 1, name: 'stream 1');
661662
await prepare(narrow: TopicNarrow(stream.streamId, 'A'));
662-
store.addStream(stream);
663+
await store.addStream(stream);
663664
store.addSubscription(eg.subscription(stream, isMuted: true));
664665
store.addUserTopic(stream, 'A', UserTopicVisibilityPolicy.muted);
665666

test/model/stream_test.dart

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ void main() {
4242
)));
4343
});
4444

45-
test('added by events', () {
45+
test('added by events', () async {
4646
final stream1 = eg.stream(streamId: 1, name: 'stream 1');
4747
final stream2 = eg.stream(streamId: 2, name: 'stream 2');
4848
final store = eg.store();
4949
checkUnified(store);
50-
checkUnified(store..addStream(stream1));
51-
checkUnified(store..addStream(stream2));
52-
checkUnified(store..addSubscription(eg.subscription(stream1)));
50+
51+
await store.addStream(stream1);
52+
checkUnified(store);
53+
54+
await store.addStream(stream2);
55+
checkUnified(store);
56+
57+
store.addSubscription(eg.subscription(stream1));
58+
checkUnified(store);
5359
});
5460
});
5561

@@ -132,46 +138,52 @@ void main() {
132138
});
133139

134140
group('isTopicVisible/InStream', () {
135-
test('with policy none, stream not muted', () {
136-
final store = eg.store()..addStream(stream1)
137-
..addSubscription(eg.subscription(stream1));
141+
test('with policy none, stream not muted', () async {
142+
final store = eg.store();
143+
await store.addStream(stream1);
144+
store.addSubscription(eg.subscription(stream1));
138145
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
139146
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
140147
});
141148

142-
test('with policy none, stream muted', () {
143-
final store = eg.store()..addStream(stream1)
144-
..addSubscription(eg.subscription(stream1, isMuted: true));
149+
test('with policy none, stream muted', () async {
150+
final store = eg.store();
151+
await store.addStream(stream1);
152+
store.addSubscription(eg.subscription(stream1, isMuted: true));
145153
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
146154
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
147155
});
148156

149-
test('with policy none, stream unsubscribed', () {
150-
final store = eg.store()..addStream(stream1);
157+
test('with policy none, stream unsubscribed', () async {
158+
final store = eg.store();
159+
await store.addStream(stream1);
151160
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
152161
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
153162
});
154163

155-
test('with policy muted', () {
156-
final store = eg.store()..addStream(stream1)
157-
..addSubscription(eg.subscription(stream1))
158-
..addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.muted);
164+
test('with policy muted', () async {
165+
final store = eg.store();
166+
await store.addStream(stream1);
167+
store.addSubscription(eg.subscription(stream1));
168+
store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.muted);
159169
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isFalse();
160170
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
161171
});
162172

163-
test('with policy unmuted', () {
164-
final store = eg.store()..addStream(stream1)
165-
..addSubscription(eg.subscription(stream1, isMuted: true))
166-
..addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.unmuted);
173+
test('with policy unmuted', () async {
174+
final store = eg.store();
175+
await store.addStream(stream1);
176+
store.addSubscription(eg.subscription(stream1, isMuted: true));
177+
store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.unmuted);
167178
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
168179
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
169180
});
170181

171-
test('with policy followed', () {
172-
final store = eg.store()..addStream(stream1)
173-
..addSubscription(eg.subscription(stream1, isMuted: true))
174-
..addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.followed);
182+
test('with policy followed', () async {
183+
final store = eg.store();
184+
await store.addStream(stream1);
185+
store.addSubscription(eg.subscription(stream1, isMuted: true));
186+
store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.followed);
175187
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
176188
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
177189
});

test/model/test_store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ extension PerAccountStoreTestExtension on PerAccountStore {
124124
}
125125
}
126126

127-
void addStream(ZulipStream stream) {
127+
Future<void> addStream(ZulipStream stream) async {
128128
addStreams([stream]);
129129
}
130130

test/model/unreads_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ void main() {
174174
check(model.countInAllMessagesNarrow()).equals(5);
175175
});
176176

177-
test('countInStream/Narrow', () {
177+
test('countInStream/Narrow', () async {
178178
final stream = eg.stream();
179179
prepare();
180-
streamStore.addStream(stream);
180+
await streamStore.addStream(stream);
181181
streamStore.addSubscription(eg.subscription(stream));
182182
streamStore.addUserTopic(stream, 'a', UserTopicVisibilityPolicy.unmuted);
183183
streamStore.addUserTopic(stream, 'c', UserTopicVisibilityPolicy.muted);

test/widgets/action_sheet_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
4242
await store.addUser(eg.user(userId: message.senderId));
4343
if (message is StreamMessage) {
4444
final stream = eg.stream(streamId: message.streamId);
45-
store..addStream(stream)..addSubscription(eg.subscription(stream));
45+
await store.addStream(stream);
46+
store.addSubscription(eg.subscription(stream));
4647
}
4748
final connection = store.connection as FakeApiConnection;
4849

test/widgets/content_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ void main() {
627627
pushedRoutes.removeLast();
628628

629629
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
630-
store.addStream(eg.stream(name: 'stream'));
630+
await store.addStream(eg.stream(name: 'stream'));
631631
return pushedRoutes;
632632
}
633633

0 commit comments

Comments
 (0)