Skip to content

Commit 774542e

Browse files
committed
test: Add eg.serverEmojiDataPopular for tests that would break without it
This brings the tests closer to being representative, because this data (and more) is part of the app's setup for an account on startup, via fetchServerEmojiData. For #1495, the app will start depending on this data for the names of popular emoji. So, prepare for that by filling in the data in tests that would break without it.
1 parent 13292a9 commit 774542e

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

test/example_data.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ GetServerSettingsResult serverSettings({
129129
);
130130
}
131131

132+
ServerEmojiData serverEmojiDataPopular = ServerEmojiData(codeToNames: {
133+
'1f44d': ['+1', 'thumbs_up', 'like'],
134+
'1f389': ['tada'],
135+
'1f642': ['smile'],
136+
'2764': ['heart', 'love', 'love_you'],
137+
'1f6e0': ['working_on_it', 'hammer_and_wrench', 'tools'],
138+
'1f419': ['octopus'],
139+
});
140+
141+
ServerEmojiData serverEmojiDataPopularPlus(ServerEmojiData data) {
142+
final a = serverEmojiDataPopular;
143+
final b = data;
144+
final result = ServerEmojiData(
145+
codeToNames: {...a.codeToNames, ...b.codeToNames},
146+
);
147+
assert(
148+
result.codeToNames.length == a.codeToNames.length + b.codeToNames.length,
149+
'eg.serverEmojiDataPopularPlus called with data that collides with eg.serverEmojiDataPopular',
150+
);
151+
return result;
152+
}
153+
132154
RealmEmojiItem realmEmojiItem({
133155
required String emojiCode,
134156
required String emojiName,

test/model/emoji_test.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ void main() {
7878
});
7979
});
8080

81-
final popularCandidates = eg.store().popularEmojiCandidates();
81+
final popularCandidates = (
82+
eg.store()..setServerEmojiData(eg.serverEmojiDataPopular)
83+
).popularEmojiCandidates();
84+
assert(popularCandidates.length == 6);
8285

8386
Condition<Object?> isUnicodeCandidate(String? emojiCode, List<String>? names) {
8487
return (it_) {
@@ -118,18 +121,22 @@ void main() {
118121

119122
PerAccountStore prepare({
120123
Map<String, RealmEmojiItem> realmEmoji = const {},
124+
bool addServerDataForPopular = true,
121125
Map<String, List<String>>? unicodeEmoji,
122126
}) {
123127
final store = eg.store(
124128
initialSnapshot: eg.initialSnapshot(realmEmoji: realmEmoji));
125-
if (unicodeEmoji != null) {
126-
store.setServerEmojiData(ServerEmojiData(codeToNames: unicodeEmoji));
127-
}
129+
130+
final extraEmojiData = ServerEmojiData(codeToNames: unicodeEmoji ?? {});
131+
final emojiData = addServerDataForPopular
132+
? eg.serverEmojiDataPopularPlus(extraEmojiData)
133+
: extraEmojiData;
134+
store.setServerEmojiData(emojiData);
128135
return store;
129136
}
130137

131138
test('popular emoji appear even when no server emoji data', () {
132-
final store = prepare(unicodeEmoji: null);
139+
final store = prepare(unicodeEmoji: null, addServerDataForPopular: false);
133140
check(store.allEmojiCandidates()).deepEquals([
134141
...arePopularCandidates,
135142
isZulipCandidate(),
@@ -139,7 +146,8 @@ void main() {
139146
test('popular emoji appear in their canonical order', () {
140147
// In the server's emoji data, have the popular emoji in a permuted order,
141148
// and interspersed with other emoji.
142-
final store = prepare(unicodeEmoji: {
149+
assert(popularCandidates.length == 6);
150+
final store = prepare(addServerDataForPopular: false, unicodeEmoji: {
143151
'1f603': ['smiley'],
144152
for (final candidate in popularCandidates.skip(3))
145153
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
@@ -252,9 +260,10 @@ void main() {
252260
isZulipCandidate(),
253261
]);
254262

255-
store.setServerEmojiData(ServerEmojiData(codeToNames: {
256-
'1f516': ['bookmark'],
257-
}));
263+
store.setServerEmojiData(eg.serverEmojiDataPopularPlus(
264+
ServerEmojiData(codeToNames: {
265+
'1f516': ['bookmark'],
266+
})));
258267
check(store.allEmojiCandidates()).deepEquals([
259268
...arePopularCandidates,
260269
isUnicodeCandidate('1f516', ['bookmark']),
@@ -318,9 +327,9 @@ void main() {
318327
for (final MapEntry(:key, :value) in realmEmoji.entries)
319328
key: eg.realmEmojiItem(emojiCode: key, emojiName: value),
320329
}));
321-
if (unicodeEmoji != null) {
322-
store.setServerEmojiData(ServerEmojiData(codeToNames: unicodeEmoji));
323-
}
330+
final extraEmojiData = ServerEmojiData(codeToNames: unicodeEmoji ?? {});
331+
ServerEmojiData emojiData = eg.serverEmojiDataPopularPlus(extraEmojiData);
332+
store.setServerEmojiData(emojiData);
324333
return store;
325334
}
326335

test/widgets/action_sheet_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
7070
await store.addSubscription(eg.subscription(stream));
7171
}
7272
connection = store.connection as FakeApiConnection;
73+
store.setServerEmojiData(eg.serverEmojiDataPopular);
7374

7475
connection.prepare(json: eg.newestGetMessagesResult(
7576
foundOldest: true, messages: [message]).toJson());
@@ -810,7 +811,9 @@ void main() {
810811

811812
group('message action sheet', () {
812813
group('ReactionButtons', () {
813-
final popularCandidates = eg.store().popularEmojiCandidates();
814+
final popularCandidates =
815+
(eg.store()..setServerEmojiData(eg.serverEmojiDataPopular))
816+
.popularEmojiCandidates();
814817

815818
for (final emoji in popularCandidates) {
816819
final emojiDisplay = emoji.emojiDisplay as UnicodeEmojiDisplay;

test/widgets/emoji_reaction_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ void main() {
299299
// - Non-animated image emoji is selected when intended
300300

301301
group('EmojiPicker', () {
302-
final popularCandidates = eg.store().popularEmojiCandidates();
302+
final popularCandidates =
303+
(eg.store()..setServerEmojiData(eg.serverEmojiDataPopular))
304+
.popularEmojiCandidates();
303305

304306
Future<void> setupEmojiPicker(WidgetTester tester, {
305307
required StreamMessage message,
@@ -337,9 +339,10 @@ void main() {
337339
// sheet appears onscreen; default duration of bottom-sheet enter animation
338340
await tester.pump(const Duration(milliseconds: 250));
339341

340-
store.setServerEmojiData(ServerEmojiData(codeToNames: {
341-
'1f4a4': ['zzz', 'sleepy'], // (just 'zzz' in real data)
342-
}));
342+
store.setServerEmojiData(eg.serverEmojiDataPopularPlus(
343+
ServerEmojiData(codeToNames: {
344+
'1f4a4': ['zzz', 'sleepy'], // (just 'zzz' in real data)
345+
})));
343346
await store.handleEvent(RealmEmojiUpdateEvent(id: 1, realmEmoji: {
344347
'1': eg.realmEmojiItem(emojiCode: '1', emojiName: 'buzzing'),
345348
}));

0 commit comments

Comments
 (0)