Skip to content

Commit 31c85e9

Browse files
committed
msglist test [nfc]: Have prepare-outbox helpers take channel ID not channel
1 parent fe60009 commit 31c85e9

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

test/model/message_list_test.dart

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ void main() {
127127

128128
Future<void> prepareOutboxMessages({
129129
required int count,
130-
required ZulipStream stream,
130+
required int channelId,
131131
String topic = 'some topic',
132132
}) async {
133133
for (int i = 0; i < count; i++) {
134134
connection.prepare(json: SendMessageResult(id: 123).toJson());
135135
await store.sendMessage(
136-
destination: StreamDestination(stream.streamId, eg.t(topic)),
136+
destination: StreamDestination(channelId, eg.t(topic)),
137137
content: 'content');
138138
}
139139
}
@@ -288,7 +288,8 @@ void main() {
288288
await prepare(
289289
narrow: eg.topicNarrow(stream.streamId, 'topic'), stream: stream);
290290

291-
await prepareOutboxMessages(count: 1, stream: stream, topic: 'topic');
291+
await prepareOutboxMessages(count: 1,
292+
channelId: stream.streamId, topic: 'topic');
292293
async.elapse(kLocalEchoDebounceDuration);
293294
checkNotNotified();
294295
check(model)
@@ -309,7 +310,8 @@ void main() {
309310
await prepare(
310311
narrow: eg.topicNarrow(stream.streamId, 'topic'), stream: stream);
311312

312-
await prepareOutboxMessages(count: 1, stream: stream, topic: 'topic');
313+
await prepareOutboxMessages(count: 1,
314+
channelId: stream.streamId, topic: 'topic');
313315
async.elapse(kLocalEchoDebounceDuration);
314316
checkNotNotified();
315317
check(model)
@@ -332,7 +334,8 @@ void main() {
332334
anchor: AnchorCode.firstUnread,
333335
stream: stream);
334336

335-
await prepareOutboxMessages(count: 1, stream: stream, topic: 'topic');
337+
await prepareOutboxMessages(count: 1,
338+
channelId: stream.streamId, topic: 'topic');
336339
async.elapse(kLocalEchoDebounceDuration);
337340
checkNotNotified();
338341
check(model)..fetched.isFalse()..outboxMessages.isEmpty();
@@ -781,7 +784,7 @@ void main() {
781784
await prepareMessages(foundOldest: true, messages:
782785
List.generate(30, (i) => eg.streamMessage(stream: stream)));
783786

784-
await prepareOutboxMessages(count: 5, stream: stream);
787+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
785788
async.elapse(kLocalEchoDebounceDuration);
786789
checkNotified(count: 5);
787790
check(model)
@@ -824,7 +827,7 @@ void main() {
824827
await prepareMessages(foundOldest: true, messages:
825828
List.generate(30, (i) => eg.streamMessage(stream: stream)));
826829

827-
await prepareOutboxMessages(count: 5, stream: stream);
830+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
828831
async.elapse(kLocalEchoDebounceDuration);
829832
checkNotified(count: 5);
830833
final localMessageId = store.outboxMessages.keys.first;
@@ -850,7 +853,7 @@ void main() {
850853
await prepareMessages(foundOldest: true, messages:
851854
List.generate(30, (i) => eg.streamMessage(stream: stream, topic: 'topic')));
852855

853-
await prepareOutboxMessages(count: 5, stream: stream, topic: 'other');
856+
await prepareOutboxMessages(count: 5, channelId: stream.streamId, topic: 'other');
854857
final localMessageId = store.outboxMessages.keys.first;
855858
check(model)
856859
..messages.length.equals(30)
@@ -876,7 +879,7 @@ void main() {
876879
await prepare(narrow: ChannelNarrow(stream.streamId), stream: stream);
877880
await prepareMessages(foundOldest: true, messages:
878881
List.generate(30, (i) => eg.streamMessage(stream: stream)));
879-
await prepareOutboxMessages(count: 5, stream: stream);
882+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
880883
check(model).outboxMessages.isEmpty();
881884

882885
async.elapse(kLocalEchoDebounceDuration);
@@ -888,7 +891,8 @@ void main() {
888891
await prepare(narrow: eg.topicNarrow(stream.streamId, 'topic'), stream: stream);
889892
await prepareMessages(foundOldest: true, messages:
890893
List.generate(30, (i) => eg.streamMessage(stream: stream, topic: 'topic')));
891-
await prepareOutboxMessages(count: 5, stream: stream, topic: 'other topic');
894+
await prepareOutboxMessages(count: 5,
895+
channelId: stream.streamId, topic: 'other topic');
892896
check(model).outboxMessages.isEmpty();
893897

894898
async.elapse(kLocalEchoDebounceDuration);
@@ -898,7 +902,7 @@ void main() {
898902

899903
test('before fetch', () => awaitFakeAsync((async) async {
900904
await prepare(narrow: ChannelNarrow(stream.streamId), stream: stream);
901-
await prepareOutboxMessages(count: 5, stream: stream);
905+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
902906
check(model)
903907
..fetched.isFalse()
904908
..outboxMessages.isEmpty();
@@ -916,13 +920,13 @@ void main() {
916920

917921
Future<void> prepareFailedOutboxMessages(FakeAsync async, {
918922
required int count,
919-
required ZulipStream stream,
923+
required int channelId,
920924
String topic = 'some topic',
921925
}) async {
922926
for (int i = 0; i < count; i++) {
923927
connection.prepare(httpException: SocketException('failed'));
924928
await check(store.sendMessage(
925-
destination: StreamDestination(stream.streamId, eg.t(topic)),
929+
destination: StreamDestination(channelId, eg.t(topic)),
926930
content: 'content')).throws();
927931
}
928932
}
@@ -932,7 +936,7 @@ void main() {
932936
await prepareMessages(foundOldest: true, messages:
933937
List.generate(30, (i) => eg.streamMessage(stream: stream, topic: 'topic')));
934938
await prepareFailedOutboxMessages(async,
935-
count: 5, stream: stream);
939+
count: 5, channelId: stream.streamId);
936940
check(model).outboxMessages.length.equals(5);
937941
checkNotified(count: 5);
938942

@@ -946,7 +950,7 @@ void main() {
946950
await prepareMessages(foundOldest: true, messages:
947951
List.generate(30, (i) => eg.streamMessage(stream: stream, topic: 'topic')));
948952
await prepareFailedOutboxMessages(async,
949-
count: 5, stream: stream, topic: 'other topic');
953+
count: 5, channelId: stream.streamId, topic: 'other topic');
950954
check(model).outboxMessages.isEmpty();
951955
checkNotNotified();
952956

@@ -959,7 +963,7 @@ void main() {
959963
await prepare(narrow: ChannelNarrow(stream.streamId), stream: stream);
960964
await prepareMessages(foundOldest: true, messages: []);
961965
await prepareFailedOutboxMessages(async,
962-
count: 1, stream: stream);
966+
count: 1, channelId: stream.streamId);
963967
check(model).outboxMessages.single;
964968
checkNotified(count: 1);
965969

@@ -1461,7 +1465,7 @@ void main() {
14611465
test('message present', () => awaitFakeAsync((async) async {
14621466
await prepare(narrow: const CombinedFeedNarrow(), stream: stream);
14631467
await prepareMessages(foundOldest: true, messages: []);
1464-
await prepareOutboxMessages(count: 5, stream: stream);
1468+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
14651469

14661470
async.elapse(kLocalEchoDebounceDuration);
14671471
checkNotified(count: 5);
@@ -1476,7 +1480,7 @@ void main() {
14761480
narrow: eg.topicNarrow(stream.streamId, 'some topic'), stream: stream);
14771481
await prepareMessages(foundOldest: true, messages: []);
14781482
await prepareOutboxMessages(count: 5,
1479-
stream: stream, topic: 'other topic');
1483+
channelId: stream.streamId, topic: 'other topic');
14801484

14811485
async.elapse(kLocalEchoDebounceDuration);
14821486
checkNotNotified();
@@ -1620,7 +1624,7 @@ void main() {
16201624
final narrow = ChannelNarrow(stream.streamId);
16211625
await prepareNarrow(narrow, initialMessages + movedMessages);
16221626
connection.prepare(json: SendMessageResult(id: 1).toJson());
1623-
await prepareOutboxMessages(count: 5, stream: stream);
1627+
await prepareOutboxMessages(count: 5, channelId: stream.streamId);
16241628

16251629
async.elapse(kLocalEchoDebounceDuration);
16261630
checkNotified(count: 5);
@@ -2765,7 +2769,8 @@ void main() {
27652769
// `findItemWithMessageId` uses binary search. Set up just enough
27662770
// outbox message items, so that a [MessageListDateSeparatorItem] for
27672771
// the outbox messages is right in the middle.
2768-
await prepareOutboxMessages(count: 2, stream: stream, topic: 'topic');
2772+
await prepareOutboxMessages(count: 2,
2773+
channelId: stream.streamId, topic: 'topic');
27692774
async.elapse(kLocalEchoDebounceDuration);
27702775
checkNotified(count: 2);
27712776
check(model.items).deepEquals(<Condition<Object?>>[
@@ -2788,7 +2793,8 @@ void main() {
27882793
// `findItemWithMessageId` uses binary search. Set up just enough
27892794
// outbox message items, so that a [MessageListOutboxMessageItem]
27902795
// is right in the middle.
2791-
await prepareOutboxMessages(count: 3, stream: stream, topic: 'topic');
2796+
await prepareOutboxMessages(count: 3,
2797+
channelId: stream.streamId, topic: 'topic');
27922798
async.elapse(kLocalEchoDebounceDuration);
27932799
checkNotified(count: 3);
27942800
check(model.items).deepEquals(<Condition<Object?>>[

0 commit comments

Comments
 (0)