@@ -5,7 +5,9 @@ import 'package:flutter_checks/flutter_checks.dart';
5
5
import 'package:flutter_test/flutter_test.dart' ;
6
6
import 'package:zulip/api/model/events.dart' ;
7
7
import 'package:zulip/api/model/model.dart' ;
8
+ import 'package:zulip/basic.dart' ;
8
9
import 'package:zulip/model/narrow.dart' ;
10
+ import 'package:zulip/model/store.dart' ;
9
11
import 'package:zulip/widgets/content.dart' ;
10
12
import 'package:zulip/widgets/home.dart' ;
11
13
import 'package:zulip/widgets/icons.dart' ;
@@ -24,6 +26,8 @@ import 'message_list_checks.dart';
24
26
import 'page_checks.dart' ;
25
27
import 'test_app.dart' ;
26
28
29
+ late PerAccountStore store;
30
+
27
31
Future <void > setupPage (WidgetTester tester, {
28
32
required List <DmMessage > dmMessages,
29
33
required List <User > users,
@@ -34,7 +38,7 @@ Future<void> setupPage(WidgetTester tester, {
34
38
addTearDown (testBinding.reset);
35
39
36
40
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
37
- final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
41
+ store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
38
42
39
43
await store.addUser (eg.selfUser);
40
44
for (final user in users) {
@@ -176,7 +180,7 @@ void main() {
176
180
// TODO(#232): syntax like `check(find(…), findsOneWidget)`
177
181
final widget = tester.widget (find.descendant (
178
182
of: find.byType (RecentDmConversationsItem ),
179
- matching: find.text (expectedText),
183
+ matching: find.textContaining (expectedText),
180
184
));
181
185
if (expectedLines != null ) {
182
186
final renderObject = tester.renderObject <RenderParagraph >(find.byWidget (widget));
@@ -186,6 +190,16 @@ void main() {
186
190
}
187
191
}
188
192
193
+ void checkFindsStatusEmoji (WidgetTester tester, Finder emojiFinder) {
194
+ final statusEmojiFinder = find.ancestor (of: emojiFinder,
195
+ matching: find.byType (UserStatusEmoji ));
196
+ check (statusEmojiFinder).findsOne ();
197
+ check (tester.widget <UserStatusEmoji >(statusEmojiFinder)
198
+ .neverAnimate).isTrue ();
199
+ check (find.ancestor (of: statusEmojiFinder,
200
+ matching: find.byType (RecentDmConversationsItem ))).findsOne ();
201
+ }
202
+
189
203
Future <void > markMessageAsRead (WidgetTester tester, Message message) async {
190
204
final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
191
205
await store.handleEvent (UpdateMessageFlagsAddEvent (
@@ -231,6 +245,31 @@ void main() {
231
245
checkTitle (tester, name, 2 );
232
246
});
233
247
248
+ group ('User status' , () {
249
+ testWidgets ('status emoji & text are set -> emoji is displayed, text is not' , (tester) async {
250
+ final message = eg.dmMessage (from: eg.selfUser, to: []);
251
+ await setupPage (tester, dmMessages: [message], users: []);
252
+ await store.changeUserStatus (eg.selfUser.userId, UserStatusChange (
253
+ text: OptionSome ('Busy' ),
254
+ emoji: OptionSome (StatusEmoji (emojiName: 'working_on_it' ,
255
+ emojiCode: '1f6e0' , reactionType: ReactionType .unicodeEmoji))));
256
+ await tester.pump ();
257
+
258
+ checkFindsStatusEmoji (tester, find.text ('\u {1f6e0}' ));
259
+ check (find.text ('Busy' )).findsNothing ();
260
+ });
261
+
262
+ testWidgets ('status emoji is not set, text is set -> text is not displayed' , (tester) async {
263
+ final message = eg.dmMessage (from: eg.selfUser, to: []);
264
+ await setupPage (tester, dmMessages: [message], users: []);
265
+ await store.changeUserStatus (eg.selfUser.userId, UserStatusChange (
266
+ text: OptionSome ('Busy' ), emoji: OptionNone ()));
267
+ await tester.pump ();
268
+
269
+ check (find.text ('Busy' )).findsNothing ();
270
+ });
271
+ });
272
+
234
273
testWidgets ('unread counts' , (tester) async {
235
274
final message = eg.dmMessage (from: eg.selfUser, to: []);
236
275
await setupPage (tester, users: [], dmMessages: [message]);
@@ -291,6 +330,33 @@ void main() {
291
330
checkTitle (tester, user.fullName, 2 );
292
331
});
293
332
333
+ group ('User status' , () {
334
+ testWidgets ('status emoji & text are set -> emoji is displayed, text is not' , (tester) async {
335
+ final user = eg.user ();
336
+ final message = eg.dmMessage (from: eg.selfUser, to: [user]);
337
+ await setupPage (tester, users: [user], dmMessages: [message]);
338
+ await store.changeUserStatus (user.userId, UserStatusChange (
339
+ text: OptionSome ('Busy' ),
340
+ emoji: OptionSome (StatusEmoji (emojiName: 'working_on_it' ,
341
+ emojiCode: '1f6e0' , reactionType: ReactionType .unicodeEmoji))));
342
+ await tester.pump ();
343
+
344
+ checkFindsStatusEmoji (tester, find.text ('\u {1f6e0}' ));
345
+ check (find.text ('Busy' )).findsNothing ();
346
+ });
347
+
348
+ testWidgets ('status emoji is not set, text is set -> text is not displayed' , (tester) async {
349
+ final user = eg.user ();
350
+ final message = eg.dmMessage (from: eg.selfUser, to: [user]);
351
+ await setupPage (tester, users: [user], dmMessages: [message]);
352
+ await store.changeUserStatus (user.userId, UserStatusChange (
353
+ text: OptionSome ('Busy' ), emoji: OptionNone ()));
354
+ await tester.pump ();
355
+
356
+ check (find.text ('Busy' )).findsNothing ();
357
+ });
358
+ });
359
+
294
360
testWidgets ('unread counts' , (tester) async {
295
361
final message = eg.dmMessage (from: eg.otherUser, to: [eg.selfUser]);
296
362
await setupPage (tester, users: [], dmMessages: [message]);
@@ -379,6 +445,22 @@ void main() {
379
445
checkTitle (tester, users.map ((u) => u.fullName).join (', ' ), 2 );
380
446
});
381
447
448
+ testWidgets ('status emoji & text are set -> none of them is displayed' , (tester) async {
449
+ final users = usersList (4 );
450
+ final message = eg.dmMessage (from: eg.selfUser, to: users);
451
+ await setupPage (tester, users: users, dmMessages: [message]);
452
+ await store.changeUserStatus (users.first.userId, UserStatusChange (
453
+ text: OptionSome ('Busy' ),
454
+ emoji: OptionSome (StatusEmoji (emojiName: 'working_on_it' ,
455
+ emojiCode: '1f6e0' , reactionType: ReactionType .unicodeEmoji))));
456
+ await tester.pump ();
457
+
458
+ check (find.descendant (of: find.byType (RecentDmConversationsItem ),
459
+ matching: find.text ('\u {1f6e0}' ))).findsNothing ();
460
+ check (find.descendant (of: find.byType (RecentDmConversationsItem ),
461
+ matching: find.text ('Busy' ))).findsNothing ();
462
+ });
463
+
382
464
testWidgets ('unread counts' , (tester) async {
383
465
final message = eg.dmMessage (from: eg.thirdUser, to: [eg.selfUser, eg.otherUser]);
384
466
await setupPage (tester, users: [], dmMessages: [message]);
0 commit comments