Skip to content

Commit 093eaba

Browse files
committed
autocomplete test: Fix up cross-signal tests; add comments to clarify
The way these tests were meant to work wasn't particularly explicit; and the recent changes adding more signals didn't take that intended structure into account, so that it became hard to see if the tests checked what they're intended to check. Bring them back to that structure, and add comments explaining it.
1 parent b48e54b commit 093eaba

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

test/model/autocomplete_test.dart

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,20 @@ void main() {
558558
}
559559
}
560560

561-
test('TopicNarrow: topic recency > stream recency > DM recency '
562-
'> human vs. bot user > alphabetical order', () async {
561+
test('TopicNarrow: topic recency > stream recency > DM recency > human/bot > name', () async {
562+
// The user with the greatest topic recency ranks last on each of the
563+
// other criteria, but comes out first in the end, showing that
564+
// topic recency comes first. Then among the remaining users, the one
565+
// with the greatest stream recency ranks last on each of the remaining
566+
// criteria, but comes out second in the end; and so on.
563567
final users = [
564-
eg.user(fullName: 'Z'),
565-
eg.user(),
566-
eg.user(isBot: true),
567-
eg.user(),
568-
eg.user(),
569-
eg.user(),
570-
eg.user(isBot: true),
571-
eg.user(fullName: 'ab'),
572-
eg.user(fullName: 'bc'),
568+
eg.user(fullName: 'Z', isBot: true), // wins by topic recency
569+
eg.user(fullName: 'Y', isBot: true), // runner-up, by stream recency
570+
eg.user(fullName: 'X', isBot: true), // runner-up, by DM recency
571+
eg.user(fullName: 'W', isBot: false), // runner-up, by human-vs-bot
572+
eg.user(fullName: 'A', isBot: true), // runner-up, by name
573+
eg.user(fullName: 'B', isBot: true), // tied because no remaining criteria
574+
eg.user(fullName: 'b', isBot: true),
573575
];
574576
final stream = eg.stream();
575577
final narrow = TopicNarrow(stream.streamId, 'this');
@@ -578,64 +580,71 @@ void main() {
578580
eg.streamMessage(sender: users[0], stream: stream, topic: 'this'),
579581
eg.streamMessage(sender: users[2], stream: stream, topic: 'other'),
580582
eg.streamMessage(sender: users[1], stream: stream, topic: 'other'),
581-
eg.dmMessage(from: users[3], to: [users[4], eg.selfUser]),
583+
eg.dmMessage(from: users[3], to: [...users.skip(4), eg.selfUser]),
582584
eg.dmMessage(from: users[2], to: [eg.selfUser]),
583585
]);
584586
checkPrecedes(narrow, users[0], users.skip(1));
585587
checkPrecedes(narrow, users[1], users.skip(2));
586588
checkPrecedes(narrow, users[2], users.skip(3));
587-
checkRankEqual(narrow, [users[3], users[4]]);
588-
checkPrecedes(narrow, users[5], users.skip(6));
589-
checkPrecedes(narrow, users[7], users.skip(8));
589+
checkPrecedes(narrow, users[3], users.skip(4));
590+
checkPrecedes(narrow, users[4], users.skip(5));
591+
checkRankEqual(narrow, [users[5], users[6]]);
590592
});
591593

592-
test('ChannelNarrow: stream recency > DM recency > human vs. bot user '
593-
'> alphabetical order', () async {
594+
test('ChannelNarrow: stream recency > DM recency > human/bot > name', () async {
595+
// Same principle as for TopicNarrow; see that test case above.
594596
final users = [
595-
eg.user(isBot: true, fullName: 'Z'),
596-
eg.user(),
597-
eg.user(),
598-
eg.user(),
599-
eg.user(),
600-
eg.user(isBot: true),
601-
eg.user(fullName: 'ab', isBot: true),
602-
eg.user(fullName: 'bc', isBot: true),
597+
eg.user(fullName: 'Z', isBot: true), // wins by stream recency
598+
eg.user(fullName: 'Y', isBot: true), // runner-up, by DM recency
599+
eg.user(fullName: 'X', isBot: false), // runner-up, by human-vs-bot
600+
eg.user(fullName: 'A', isBot: true), // runner-up, by name
601+
eg.user(fullName: 'B', isBot: true), // tied because no remaining criteria
602+
eg.user(fullName: 'b', isBot: true),
603603
];
604604
final stream = eg.stream();
605605
final narrow = ChannelNarrow(stream.streamId);
606606
await prepare(users: users, messages: [
607607
eg.streamMessage(sender: users[1], stream: stream),
608608
eg.streamMessage(sender: users[0], stream: stream),
609-
eg.dmMessage(from: users[2], to: [users[3], eg.selfUser]),
609+
eg.dmMessage(from: users[2], to: [...users.skip(3), eg.selfUser]),
610610
eg.dmMessage(from: users[1], to: [eg.selfUser]),
611-
eg.dmMessage(from: users[4], to: [users[5], eg.selfUser]),
612611
]);
613612
checkPrecedes(narrow, users[0], users.skip(1));
614613
checkPrecedes(narrow, users[1], users.skip(2));
615-
checkRankEqual(narrow, [users[2], users[3]]);
616-
checkPrecedes(narrow, users[4], users.skip(5));
617-
checkPrecedes(narrow, users[6], users.skip(7));
614+
checkPrecedes(narrow, users[2], users.skip(3));
615+
checkPrecedes(narrow, users[3], users.skip(4));
616+
checkRankEqual(narrow, [users[4], users[5]]);
618617
});
619618

620-
test('DmNarrow: DM recency > this-conversation recency or stream recency '
621-
'or human vs. bot user or alphabetical order', () async {
619+
test('DmNarrow: DM recency > human/bot > name, ignore this-conversation recency and stream recency', () async {
620+
// Same principle as for TopicNarrow; see that test case above.
622621
final users = [
623-
eg.user(isBot: true, fullName: 'Z'),
624-
eg.user(),
625-
eg.user(),
626-
eg.user(),
627-
eg.user(),
628-
eg.user(isBot: true),
629-
eg.user(fullName: 'ab'),
630-
eg.user(fullName: 'bc'),
622+
// First user wins by DM recency.
623+
eg.user(fullName: 'Z', isBot: true),
624+
// Next two are runners-up by DM recency, and have a two-way tie
625+
// despite different this-conversation recency (because that doesn't count).
626+
eg.user(fullName: 'Y', isBot: true),
627+
eg.user(fullName: 'y', isBot: true),
628+
// Next user is the runner-up due to DM recency, and comes after the
629+
// above users even when it has greater this-conversation recency
630+
// (because that doesn't count).
631+
eg.user(fullName: 'X', isBot: true),
632+
// Remainder have no DM recency and so come later.
633+
// Next user is the runner-up due to human-vs-bot.
634+
eg.user(fullName: 'W', isBot: false),
635+
// Next user is the runner-up due to name.
636+
eg.user(fullName: 'A', isBot: true),
637+
// Remaining users are tied, even though they differ in stream recency
638+
// (because that doesn't count).
639+
eg.user(fullName: 'B', isBot: true),
640+
eg.user(fullName: 'b', isBot: true),
631641
];
632642
await prepare(users: users, messages: [
633643
eg.dmMessage(from: users[3], to: [eg.selfUser]),
634644
eg.dmMessage(from: users[1], to: [users[2], eg.selfUser]),
635645
eg.dmMessage(from: users[0], to: [eg.selfUser]),
636-
eg.streamMessage(sender: users[1]),
637-
eg.streamMessage(sender: users[2]),
638-
eg.streamMessage(sender: users[3]),
646+
for (final user in users.skip(1))
647+
eg.streamMessage(sender: user),
639648
]);
640649
for (final narrow in [
641650
DmNarrow.withUser(users[3].userId, selfUserId: eg.selfUser.userId),
@@ -647,8 +656,10 @@ void main() {
647656
checkRankEqual(narrow, [users[1], users[2]]);
648657
checkPrecedes(narrow, users[1], users.skip(3));
649658
checkPrecedes(narrow, users[2], users.skip(3));
659+
checkPrecedes(narrow, users[3], users.skip(4));
650660
checkPrecedes(narrow, users[4], users.skip(5));
651-
checkPrecedes(narrow, users[6], users.skip(7));
661+
checkPrecedes(narrow, users[5], users.skip(6));
662+
checkRankEqual(narrow, [users[6], users[7]]);
652663
}
653664
});
654665

0 commit comments

Comments
 (0)