Skip to content

Commit f1b65bb

Browse files
chrisbobbegnprice
authored andcommitted
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 eee7bcd commit f1b65bb

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-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: 25 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,25 @@ 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));
129+
130+
if (addServerDataForPopular || unicodeEmoji != null) {
131+
final extraEmojiData = ServerEmojiData(codeToNames: unicodeEmoji ?? {});
132+
final emojiData = addServerDataForPopular
133+
? eg.serverEmojiDataPopularPlus(extraEmojiData)
134+
: extraEmojiData;
135+
store.setServerEmojiData(emojiData);
127136
}
128137
return store;
129138
}
130139

131140
test('popular emoji appear even when no server emoji data', () {
132-
final store = prepare(unicodeEmoji: null);
141+
final store = prepare(unicodeEmoji: null, addServerDataForPopular: false);
142+
check(store.debugServerEmojiData).isNull();
133143
check(store.allEmojiCandidates()).deepEquals([
134144
...arePopularCandidates,
135145
isZulipCandidate(),
@@ -139,7 +149,8 @@ void main() {
139149
test('popular emoji appear in their canonical order', () {
140150
// In the server's emoji data, have the popular emoji in a permuted order,
141151
// and interspersed with other emoji.
142-
final store = prepare(unicodeEmoji: {
152+
assert(popularCandidates.length == 6);
153+
final store = prepare(addServerDataForPopular: false, unicodeEmoji: {
143154
'1f603': ['smiley'],
144155
for (final candidate in popularCandidates.skip(3))
145156
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
@@ -246,15 +257,17 @@ void main() {
246257
});
247258

248259
test('updates on setServerEmojiData', () {
249-
final store = prepare();
260+
final store = prepare(unicodeEmoji: null, addServerDataForPopular: false);
261+
check(store.debugServerEmojiData).isNull();
250262
check(store.allEmojiCandidates()).deepEquals([
251263
...arePopularCandidates,
252264
isZulipCandidate(),
253265
]);
254266

255-
store.setServerEmojiData(ServerEmojiData(codeToNames: {
256-
'1f516': ['bookmark'],
257-
}));
267+
store.setServerEmojiData(eg.serverEmojiDataPopularPlus(
268+
ServerEmojiData(codeToNames: {
269+
'1f516': ['bookmark'],
270+
})));
258271
check(store.allEmojiCandidates()).deepEquals([
259272
...arePopularCandidates,
260273
isUnicodeCandidate('1f516', ['bookmark']),
@@ -318,9 +331,9 @@ void main() {
318331
for (final MapEntry(:key, :value) in realmEmoji.entries)
319332
key: eg.realmEmojiItem(emojiCode: key, emojiName: value),
320333
}));
321-
if (unicodeEmoji != null) {
322-
store.setServerEmojiData(ServerEmojiData(codeToNames: unicodeEmoji));
323-
}
334+
final extraEmojiData = ServerEmojiData(codeToNames: unicodeEmoji ?? {});
335+
ServerEmojiData emojiData = eg.serverEmojiDataPopularPlus(extraEmojiData);
336+
store.setServerEmojiData(emojiData);
324337
return store;
325338
}
326339

test/widgets/action_sheet_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
7878
await store.addSubscription(eg.subscription(stream));
7979
}
8080
connection = store.connection as FakeApiConnection;
81+
store.setServerEmojiData(eg.serverEmojiDataPopular);
8182

8283
connection.prepare(json: eg.newestGetMessagesResult(
8384
foundOldest: true, messages: [message]).toJson());
@@ -829,7 +830,9 @@ void main() {
829830

830831
group('message action sheet', () {
831832
group('ReactionButtons', () {
832-
final popularCandidates = eg.store().popularEmojiCandidates();
833+
final popularCandidates =
834+
(eg.store()..setServerEmojiData(eg.serverEmojiDataPopular))
835+
.popularEmojiCandidates();
833836

834837
for (final emoji in popularCandidates) {
835838
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)