Skip to content

Commit 81d3b0d

Browse files
gnpricechrisbobbe
andcommitted
autocomplete test [nfc]: Apply ranking in debugCompareUsers
This makes this function better match the end-to-end behavior of our autocomplete ordering, now that that involves this ranking notion. Co-authored-by: Chris Bobbe <[email protected]>
1 parent 096ab74 commit 81d3b0d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/model/autocomplete.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,23 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
455455
}
456456

457457
/// Compare the users the same way they would be sorted as
458-
/// autocomplete candidates.
458+
/// autocomplete candidates, given [query].
459+
///
460+
/// The users must both match the query.
459461
///
460462
/// This behaves the same as the comparator used for sorting in
461-
/// [_usersByRelevance], but calling this for each comparison would be a bit
462-
/// less efficient because some of the logic is independent of the users and
463-
/// can be precomputed.
463+
/// [_usersByRelevance], combined with the ranking applied at the end
464+
/// of [computeResults].
464465
///
465466
/// This is useful for tests in order to distinguish "A comes before B"
466467
/// from "A ranks equal to B, and the sort happened to put A before B",
467468
/// particularly because [List.sort] makes no guarantees about the order
468469
/// of items that compare equal.
469470
int debugCompareUsers(User userA, User userB) {
471+
final rankA = query.testUser(userA, store)!.rank;
472+
final rankB = query.testUser(userB, store)!.rank;
473+
if (rankA != rankB) return rankA.compareTo(rankB);
474+
470475
return _comparator(store: store, narrow: narrow)(userA, userB);
471476
}
472477

test/model/autocomplete_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,10 @@ void main() {
845845
eg.dmMessage(from: users[4-1], to: [eg.selfUser]),
846846
]);
847847

848-
// Check the ranking of the full list of mentions.
849-
// The order should be:
848+
// Check the order of a full list of mentions, focusing on relevance.
849+
// The bucket-sort-by-rank step has its own tests;
850+
// see "MentionAutocompleteQuery ranking.
851+
// For this list, the order should be:
850852
// 1. Wildcards before individual users.
851853
// 2. Users most recent in the current topic/stream.
852854
// 3. Users most recent in the DM conversations.

0 commit comments

Comments
 (0)