Skip to content

Commit 22fa9d1

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 96a328c commit 22fa9d1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
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

0 commit comments

Comments
 (0)