Skip to content

Commit

Permalink
wip test ordering of popular
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Dec 8, 2024
1 parent 3f07748 commit 0b2637c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class EmojiStoreImpl with EmojiStore {
List<EmojiCandidate> _generateAllCandidates() {
final results = <EmojiCandidate>[];

// Include the "popular" emoji in their canonical order
// Include the "popular" emoji, in their canonical order
// relative to each other.
results.addAll(zulipPopularEmojis);

Expand Down
73 changes: 73 additions & 0 deletions test/model/emoji_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,40 @@ void main() {
return store;
}

test('popular emoji appear even when no server emoji data', () {
final store = prepare(unicodeEmoji: null);
check(store.allEmojiCandidates()).deepEquals([
...arePopularCandidates,
isZulipCandidate(),
]);
});

test('popular emoji appear in their canonical order', () {
// In the server's emoji data, have the popular emoji in a permuted order,
// and interspersed with other emoji.
final store = prepare(unicodeEmoji: {
'1f603': ['smiley'],
for (final candidate in zulipPopularEmojis.skip(3))
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
'1f34a': ['orange', 'tangerine', 'mandarin'],
for (final candidate in zulipPopularEmojis.take(3))
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
'1f516': ['bookmark'],
});
// In the allEmojiCandidates result, the popular emoji come first
// and are in their canonical order, even though the other Unicode emoji
// are in the same order they were given in.
check(store.allEmojiCandidates()).deepEquals([
for (final candidate in zulipPopularEmojis)
isUnicodeCandidate(candidate.emojiCode,
[candidate.emojiName, ...candidate.aliases]),
isUnicodeCandidate('1f603', ['smiley']),
isUnicodeCandidate('1f34a', ['orange', 'tangerine', 'mandarin']),
isUnicodeCandidate('1f516', ['bookmark']),
isZulipCandidate(),
]);
});

test('realm emoji overrides Unicode emoji', () {
final store = prepare(realmEmoji: {
'1': eg.realmEmojiItem(emojiCode: '1', emojiName: 'smiley'),
Expand Down Expand Up @@ -301,6 +335,45 @@ void main() {
return view.results;
}

test('results preserve order of popular emoji within each rank', () async {
// In other words, the sorting by rank is a stable sort.

// Full results list matches allEmojiCandidates.
check(prepare().allEmojiCandidates())
.deepEquals([...arePopularCandidates, isZulipCandidate()]);
check(await resultsOf(''))
.deepEquals([...arePopularResults, isZulipResult()]);

// Same list written out explicitly, for comparison with the cases below.
check(await resultsOf('')).deepEquals([
isUnicodeResult(names: ['+1', 'thumbs_up', 'like']),
isUnicodeResult(names: ['tada']),
isUnicodeResult(names: ['smile']),
isUnicodeResult(names: ['heart', 'love', 'love_you']),
isUnicodeResult(names: ['working_on_it', 'hammer_and_wrench', 'tools']),
isUnicodeResult(names: ['octopus']),
isZulipResult(),
]);

check(await resultsOf('t')).deepEquals([
// prefix
isUnicodeResult(names: ['+1', 'thumbs_up', 'like']),
isUnicodeResult(names: ['tada']),
isUnicodeResult(names: ['working_on_it', 'hammer_and_wrench', 'tools']),
// other
isUnicodeResult(names: ['heart', 'love', 'love_you']),
isUnicodeResult(names: ['octopus']),
]);

check(await resultsOf('h')).deepEquals([
// prefix
isUnicodeResult(names: ['heart', 'love', 'love_you']),
isUnicodeResult(names: ['working_on_it', 'hammer_and_wrench', 'tools']),
// other
isUnicodeResult(names: ['+1', 'thumbs_up', 'like']),
]);
});

test('results end-to-end', () async {
// (See more detailed rank tests below, on EmojiAutocompleteQuery.)

Expand Down

0 comments on commit 0b2637c

Please sign in to comment.