Skip to content

Commit 5097fce

Browse files
chrisbobbegnprice
authored andcommitted
msglist test: Add smoke test for renarrowAndFetch
We're about to use this more; seems a good time to write a test.
1 parent 673ff5b commit 5097fce

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test/model/message_list_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:io';
34

@@ -427,6 +428,58 @@ void main() {
427428
});
428429
});
429430

431+
group('renarrowAndFetch', () {
432+
test('smoke', () => awaitFakeAsync((async) async {
433+
final channel = eg.stream();
434+
435+
const narrow = CombinedFeedNarrow();
436+
await prepare(narrow: narrow, stream: channel);
437+
final messages = List.generate(100,
438+
(i) => eg.streamMessage(id: 1000 + i, stream: channel));
439+
await prepareMessages(foundOldest: false, messages: messages);
440+
441+
// Start a fetchOlder, so we can check that renarrowAndFetch causes its
442+
// result to be discarded.
443+
connection.prepare(
444+
json: olderResult(
445+
anchor: 1000, foundOldest: false,
446+
messages: List.generate(100,
447+
(i) => eg.streamMessage(id: 900 + i, stream: channel)),
448+
).toJson(),
449+
delay: Duration(milliseconds: 500),
450+
);
451+
unawaited(model.fetchOlder());
452+
checkNotifiedOnce();
453+
454+
// Start the renarrowAndFetch.
455+
final newNarrow = ChannelNarrow(channel.streamId);
456+
final result = eg.getMessagesResult(
457+
anchor: model.anchor, foundOldest: false, messages: messages);
458+
connection.prepare(json: result.toJson(), delay: Duration(seconds: 1));
459+
model.renarrowAndFetch(newNarrow);
460+
checkNotifiedOnce();
461+
check(model)
462+
..fetched.isFalse()
463+
..narrow.equals(newNarrow)
464+
..messages.isEmpty();
465+
466+
// Elapse until the fetchOlder is done but renarrowAndFetch is still
467+
// pending; check that the list is still empty despite the fetchOlder.
468+
async.elapse(Duration(milliseconds: 750));
469+
check(model)
470+
..fetched.isFalse()
471+
..narrow.equals(newNarrow)
472+
..messages.isEmpty();
473+
474+
// Elapse until the renarrowAndFetch completes.
475+
async.elapse(Duration(seconds: 250));
476+
check(model)
477+
..fetched.isTrue()
478+
..narrow.equals(newNarrow)
479+
..messages.length.equals(100);
480+
}));
481+
});
482+
430483
group('fetching more', () {
431484
test('fetchOlder smoke', () async {
432485
const narrow = CombinedFeedNarrow();

0 commit comments

Comments
 (0)