Skip to content

Commit a14ea8b

Browse files
committed
autocomplete test: Highlight one end-to-end test, cut the others
It's good to have an end-to-end test here that the actual autocomplete results reflect the sorting that's tested by all the unit tests in the rest of this file: a test that makes a MentionAutocompleteView, then gives it a query, and inspects the results. The several such test cases that were here, though, don't exercise any distinct scenarios when it comes to that end-to-end logic; they differ from each other only in ways that are exercised by the unit tests above, plus the tests for RecentSenders and RecentDmConversations that check those data structures' handling of events. So pick just one of these test cases and cut the rest.
1 parent 3823ec4 commit a14ea8b

File tree

1 file changed

+24
-59
lines changed

1 file changed

+24
-59
lines changed

test/model/autocomplete_test.dart

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,13 @@ void main() {
574574
});
575575
});
576576

577-
group('autocomplete suggests relevant users in the intended order', () {
577+
test('final results end-to-end', () async {
578578
// The order should be:
579579
// 1. Users most recent in the current topic/stream.
580580
// 2. Users most recent in the DM conversations.
581581

582582
final stream = eg.stream();
583583
const topic = 'topic';
584-
final streamNarrow = StreamNarrow(stream.streamId);
585584
final topicNarrow = TopicNarrow(stream.streamId, topic);
586585

587586
final users = List.generate(5, (i) => eg.user(userId: i));
@@ -618,65 +617,31 @@ void main() {
618617
check(results).deepEquals(expected);
619618
}
620619

621-
group('StreamNarrow & TopicNarrow', () {
622-
late FakeApiConnection connection;
623-
late MessageListView messageList;
624-
625-
Future<void> fetchInitialMessagesIn(Narrow narrow) async {
626-
connection = store.connection as FakeApiConnection;
627-
connection.prepare(json: newestResult(
628-
foundOldest: false,
629-
messages: narrow is StreamNarrow
630-
? messages
631-
: messages.where((m) => m.topic == topic).toList(),
632-
).toJson());
633-
messageList = MessageListView.init(store: store, narrow: narrow);
634-
await messageList.fetchInitial();
635-
}
636-
637-
Future<void> checkInitialResultsIn(Narrow narrow,
638-
{required List<int> expected, bool includeStream = false}) async {
639-
assert(narrow is! StreamNarrow || !includeStream);
640-
await prepareStore(includeMessageHistory: includeStream);
641-
await fetchInitialMessagesIn(narrow);
642-
await checkResultsIn(narrow, expected: expected);
643-
}
644-
645-
test('StreamNarrow', () async {
646-
await checkInitialResultsIn(streamNarrow, expected: [4, 0, 3, 1, 2]);
647-
});
648-
649-
test('StreamNarrow, new message arrives', () async {
650-
await checkInitialResultsIn(streamNarrow, expected: [4, 0, 3, 1, 2]);
651-
652-
// Until now, latest message id in [stream] is 60.
653-
await store.addMessage(streamMessage(id: 70, senderId: 2));
654-
655-
await checkResultsIn(streamNarrow, expected: [2, 4, 0, 3, 1]);
656-
});
657-
658-
test('StreamNarrow, a batch of older messages arrives', () async {
659-
await checkInitialResultsIn(streamNarrow, expected: [4, 0, 3, 1, 2]);
660-
661-
// Until now, oldest message id in [stream] is 50.
662-
final oldMessages = [
663-
streamMessage(id: 30, senderId: 1),
664-
streamMessage(id: 40, senderId: 2),
665-
];
666-
connection.prepare(json: olderResult(
667-
anchor: 50, foundOldest: false,
668-
messages: oldMessages,
669-
).toJson());
670-
await messageList.fetchOlder();
620+
late FakeApiConnection connection;
621+
late MessageListView messageList;
622+
623+
Future<void> fetchInitialMessagesIn(Narrow narrow) async {
624+
connection = store.connection as FakeApiConnection;
625+
connection.prepare(json: newestResult(
626+
foundOldest: false,
627+
messages: narrow is StreamNarrow
628+
? messages
629+
: messages.where((m) => m.topic == topic).toList(),
630+
).toJson());
631+
messageList = MessageListView.init(store: store, narrow: narrow);
632+
await messageList.fetchInitial();
633+
}
671634

672-
await checkResultsIn(streamNarrow, expected: [4, 0, 2, 1, 3]);
673-
});
635+
Future<void> checkInitialResultsIn(Narrow narrow,
636+
{required List<int> expected, bool includeStream = false}) async {
637+
assert(narrow is! StreamNarrow || !includeStream);
638+
await prepareStore(includeMessageHistory: includeStream);
639+
await fetchInitialMessagesIn(narrow);
640+
await checkResultsIn(narrow, expected: expected);
641+
}
674642

675-
test('TopicNarrow, other messages are in stream', () async {
676-
await checkInitialResultsIn(topicNarrow, expected: [0, 4, 3, 1, 2],
677-
includeStream: true);
678-
});
679-
});
643+
await checkInitialResultsIn(topicNarrow, expected: [0, 4, 3, 1, 2],
644+
includeStream: true);
680645
});
681646
});
682647
}

0 commit comments

Comments
 (0)