Skip to content

Commit dc24b4c

Browse files
sm-sayedignprice
authored andcommitted
emoji: Add EmojiStore.getUnicodeEmojiNameByCode method
1 parent 9468767 commit dc24b4c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/model/emoji.dart

Lines changed: 10 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,10 @@ class EmojiStoreImpl extends PerAccountStoreBase with EmojiStore {
396402
return _allEmojiCandidates ??= _generateAllCandidates();
397403
}
398404

405+
@override
406+
String? getUnicodeEmojiNameByCode(String emojiCode) =>
407+
_serverEmojiData?[emojiCode]?.first; // TODO(log) if null
408+
399409
void setServerEmojiData(ServerEmojiData data) {
400410
_serverEmojiData = data.codeToNames;
401411
_popularCandidates = null;

test/model/emoji_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ 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 is not present', () {
352+
final store = prepare(addServerDataForPopular: false);
353+
check(store.debugServerEmojiData).isNull();
354+
check(store.getUnicodeEmojiNameByCode('1f516')).isNull();
355+
});
356+
});
357+
334358
group('EmojiAutocompleteView', () {
335359
Condition<Object?> isUnicodeResult({String? emojiCode, List<String>? names}) {
336360
return (it) => it.isA<EmojiAutocompleteResult>().candidate.which(

0 commit comments

Comments
 (0)