From 0b2637c2213479ad1e28eeb5f14239483504a924 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 7 Dec 2024 22:38:32 -0800 Subject: [PATCH] wip test ordering of popular --- lib/model/emoji.dart | 2 +- test/model/emoji_test.dart | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/lib/model/emoji.dart b/lib/model/emoji.dart index c215c4f094..eede09b1d1 100644 --- a/lib/model/emoji.dart +++ b/lib/model/emoji.dart @@ -283,7 +283,7 @@ class EmojiStoreImpl with EmojiStore { List _generateAllCandidates() { final results = []; - // Include the "popular" emoji in their canonical order + // Include the "popular" emoji, in their canonical order // relative to each other. results.addAll(zulipPopularEmojis); diff --git a/test/model/emoji_test.dart b/test/model/emoji_test.dart index 8cde33dcd9..ca0b2988e0 100644 --- a/test/model/emoji_test.dart +++ b/test/model/emoji_test.dart @@ -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'), @@ -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.)