Skip to content

Commit b436fb5

Browse files
committed
autocomplete test [nfc]: Bring details next to details in end-to-end test
This way it's possible to look at the expected results at the end of this test and compare them with the test data that leads to those results, without scanning past a lot of other code that isn't related to why these particular results are the right answers.
1 parent 0288ee4 commit b436fb5

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

test/model/autocomplete_test.dart

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -575,46 +575,11 @@ void main() {
575575
});
576576

577577
test('final results end-to-end', () async {
578-
// The order should be:
579-
// 1. Users most recent in the current topic/stream.
580-
// 2. Users most recent in the DM conversations.
581-
582-
final stream = eg.stream();
583-
const topic = 'topic';
584-
final topicNarrow = TopicNarrow(stream.streamId, topic);
585-
586-
final users = [
587-
eg.user(userId: 1, fullName: 'User One'),
588-
eg.user(userId: 2, fullName: 'User Two'),
589-
eg.user(userId: 3, fullName: 'User Three'),
590-
eg.user(userId: 4, fullName: 'User Four'),
591-
eg.user(userId: 5, fullName: 'User Five'),
592-
];
593-
594-
final dmConversations = [
595-
RecentDmConversation(userIds: [4], maxMessageId: 300),
596-
RecentDmConversation(userIds: [1], maxMessageId: 200),
597-
RecentDmConversation(userIds: [1, 2], maxMessageId: 100),
598-
];
599-
600-
StreamMessage streamMessage({required int id, required int senderId, String? topic}) =>
601-
eg.streamMessage(id: id, sender: users[senderId-1], topic: topic, stream: stream);
602-
603-
final messages = [
604-
streamMessage(id: 50, senderId: 1, topic: topic),
605-
streamMessage(id: 60, senderId: 5),
606-
];
607-
608-
Future<void> prepareStore() async {
609-
await prepare(users: users, dmConversations: dmConversations,
610-
messages: messages);
611-
}
612-
613-
Future<void> fetchInitialMessagesIn(Narrow narrow) async {
578+
Future<void> fetchInitialMessagesIn(Narrow narrow, List<Message> messages) async {
614579
final connection = store.connection as FakeApiConnection;
615580
connection.prepare(json: newestResult(
616581
foundOldest: false,
617-
messages: messages.where((m) => m.topic == topic).toList(),
582+
messages: messages,
618583
).toJson());
619584
final messageList = MessageListView.init(store: store, narrow: narrow);
620585
await messageList.fetchInitial();
@@ -634,11 +599,38 @@ void main() {
634599
return results;
635600
}
636601

637-
await prepareStore();
638-
await fetchInitialMessagesIn(topicNarrow);
602+
final stream = eg.stream();
603+
const topic = 'topic';
604+
final topicNarrow = TopicNarrow(stream.streamId, topic);
605+
606+
final users = [
607+
eg.user(userId: 1, fullName: 'User One'),
608+
eg.user(userId: 2, fullName: 'User Two'),
609+
eg.user(userId: 3, fullName: 'User Three'),
610+
eg.user(userId: 4, fullName: 'User Four'),
611+
eg.user(userId: 5, fullName: 'User Five'),
612+
];
613+
614+
final messages = [
615+
eg.streamMessage(id: 50, sender: users[1-1], stream: stream, topic: topic),
616+
eg.streamMessage(id: 60, sender: users[5-1], stream: stream),
617+
];
618+
619+
await prepare(users: users, messages: messages, dmConversations: [
620+
RecentDmConversation(userIds: [4], maxMessageId: 300),
621+
RecentDmConversation(userIds: [1], maxMessageId: 200),
622+
RecentDmConversation(userIds: [1, 2], maxMessageId: 100),
623+
]);
624+
await fetchInitialMessagesIn(topicNarrow,
625+
messages.where((m) => m.topic == topic).toList());
626+
639627
// Check the ranking of the full list of users.
628+
// The order should be:
629+
// 1. Users most recent in the current topic/stream.
630+
// 2. Users most recent in the DM conversations.
640631
check(await getResults(topicNarrow, MentionAutocompleteQuery('')))
641632
.deepEquals([1, 5, 4, 2, 3]);
633+
642634
// Check the ranking applies also to results filtered by a query.
643635
check(await getResults(topicNarrow, MentionAutocompleteQuery('t')))
644636
.deepEquals([2, 3]);

0 commit comments

Comments
 (0)