Skip to content

Commit c39f1bc

Browse files
committed
emoji: Add EmojiStore.getUnicodeEmojiNameByCode method
1 parent 7b5d6fa commit c39f1bc

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/model/emoji.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ mixin EmojiStore {
119119

120120
Iterable<EmojiCandidate> allEmojiCandidates();
121121

122+
String? getUnicodeEmojiNameByCode(String emojiCode);
123+
122124
// TODO cut debugServerEmojiData once we can query for lists of emoji;
123125
// have tests make those queries end-to-end
124126
Map<String, List<String>>? get debugServerEmojiData;
@@ -144,6 +146,10 @@ mixin ProxyEmojiStore on EmojiStore {
144146
@override
145147
Iterable<EmojiCandidate> allEmojiCandidates() => emojiStore.allEmojiCandidates();
146148

149+
@override
150+
String? getUnicodeEmojiNameByCode(String emojiCode) =>
151+
emojiStore.getUnicodeEmojiNameByCode(emojiCode);
152+
147153
@override
148154
Map<String, List<String>>? get debugServerEmojiData => emojiStore.debugServerEmojiData;
149155
}
@@ -396,6 +402,11 @@ class EmojiStoreImpl extends PerAccountStoreBase with EmojiStore {
396402
return _allEmojiCandidates ??= _generateAllCandidates();
397403
}
398404

405+
@override
406+
String? getUnicodeEmojiNameByCode(String emojiCode) =>
407+
// TODO(log) if null; not supposed to happen
408+
_serverEmojiData?[emojiCode]?.firstOrNull;
409+
399410
void setServerEmojiData(ServerEmojiData data) {
400411
_serverEmojiData = data.codeToNames;
401412
_popularCandidates = null;

test/model/emoji_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,37 @@ void main() {
331331
});
332332
});
333333

334+
group('getUnicodeEmojiNameByCode', () {
335+
test('happy path', () {
336+
final store = prepare(unicodeEmoji: {
337+
'1f4c5': ['calendar'],
338+
'1f34a': ['orange', 'tangerine', 'mandarin'],
339+
});
340+
check(store.getUnicodeEmojiNameByCode('1f4c5')).equals('calendar');
341+
check(store.getUnicodeEmojiNameByCode('1f34a')).equals('orange');
342+
});
343+
344+
test('server emoji data present, emoji code not present', () {
345+
final store = prepare(unicodeEmoji: {
346+
'1f4c5': ['calendar'],
347+
});
348+
check(store.getUnicodeEmojiNameByCode('1f34a')).isNull();
349+
});
350+
351+
test('server emoji data present, emoji code corresponds to empty emoji name list', () {
352+
final store = prepare(unicodeEmoji: {
353+
'1f4c5': [],
354+
});
355+
check(store.getUnicodeEmojiNameByCode('1f516')).isNull();
356+
});
357+
358+
test('server emoji data is not present', () {
359+
final store = prepare(addServerDataForPopular: false);
360+
check(store.debugServerEmojiData).isNull();
361+
check(store.getUnicodeEmojiNameByCode('1f516')).isNull();
362+
});
363+
});
364+
334365
group('EmojiAutocompleteView', () {
335366
Condition<Object?> isUnicodeResult({String? emojiCode, List<String>? names}) {
336367
return (it) => it.isA<EmojiAutocompleteResult>().candidate.which(

0 commit comments

Comments
 (0)