@@ -7,14 +7,17 @@ import 'package:zulip/api/model/model.dart';
7
7
import 'package:zulip/api/route/messages.dart' ;
8
8
import 'package:zulip/api/route/channels.dart' ;
9
9
import 'package:zulip/api/route/realm.dart' ;
10
+ import 'package:zulip/basic.dart' ;
10
11
import 'package:zulip/model/compose.dart' ;
11
12
import 'package:zulip/model/emoji.dart' ;
12
13
import 'package:zulip/model/localizations.dart' ;
13
14
import 'package:zulip/model/narrow.dart' ;
14
15
import 'package:zulip/model/store.dart' ;
15
16
import 'package:zulip/model/typing_status.dart' ;
17
+ import 'package:zulip/widgets/autocomplete.dart' ;
16
18
import 'package:zulip/widgets/compose_box.dart' ;
17
19
import 'package:zulip/widgets/content.dart' ;
20
+ import 'package:zulip/widgets/emoji.dart' ;
18
21
import 'package:zulip/widgets/message_list.dart' ;
19
22
20
23
import '../api/fake_api.dart' ;
@@ -25,6 +28,8 @@ import '../model/test_store.dart';
25
28
import '../test_images.dart' ;
26
29
import 'test_app.dart' ;
27
30
31
+ late PerAccountStore store;
32
+
28
33
/// Simulates loading a [MessageListPage] and tapping to focus the compose input.
29
34
///
30
35
/// Also adds [users] to the [PerAccountStore] ,
@@ -44,7 +49,7 @@ Future<Finder> setupToComposeInput(WidgetTester tester, {
44
49
45
50
addTearDown (testBinding.reset);
46
51
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
47
- final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
52
+ store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
48
53
await store.addUsers ([eg.selfUser, eg.otherUser]);
49
54
await store.addUsers (users);
50
55
final connection = store.connection as FakeApiConnection ;
@@ -202,6 +207,84 @@ void main() {
202
207
debugNetworkImageHttpClientProvider = null ;
203
208
});
204
209
210
+ group ('User status' , () {
211
+ void checkStatusEmoji (WidgetTester tester, {required bool isPresent}) {
212
+ final statusEmojiFinder = find.ancestor (
213
+ of: find.byType (UnicodeEmojiWidget ),
214
+ matching: find.byType (UserStatusEmoji ));
215
+ if (isPresent) {
216
+ check (statusEmojiFinder).findsOne ();
217
+ check (tester.firstWidget <UserStatusEmoji >(statusEmojiFinder)
218
+ .neverAnimate).isTrue ();
219
+
220
+ final itemFinder = find.ancestor (of: statusEmojiFinder,
221
+ matching: find.byType (MentionAutocompleteItem ));
222
+ check (itemFinder).findsOne ();
223
+ } else {
224
+ check (statusEmojiFinder).findsNothing ();
225
+ }
226
+ }
227
+
228
+ testWidgets ('status emoji & text are set -> emoji is displayed, text is not' , (tester) async {
229
+ final user = eg.user (fullName: 'User' );
230
+ final composeInputFinder = await setupToComposeInput (tester, users: [user]);
231
+ await store.changeUserStatuses ({
232
+ user.userId: UserStatusChange (
233
+ text: OptionSome ('Busy' ),
234
+ emoji: OptionSome (StatusEmoji (emojiName: 'working_on_it' ,
235
+ emojiCode: '1f6e0' , reactionType: ReactionType .unicodeEmoji))),
236
+ });
237
+ await tester.pump ();
238
+
239
+ // // TODO(#226): Remove this extra edit when this bug is fixed.
240
+ await tester.enterText (composeInputFinder, 'hello @u' );
241
+ await tester.enterText (composeInputFinder, 'hello @' );
242
+ await tester.pumpAndSettle (); // async computation; options appear
243
+
244
+ checkStatusEmoji (tester, isPresent: true );
245
+ check (find.descendant (of: find.byType (MentionAutocompleteItem ),
246
+ matching: find.text ('Busy' ))).findsNothing ();
247
+
248
+ debugNetworkImageHttpClientProvider = null ;
249
+ });
250
+
251
+ testWidgets ('status emoji is not set, text is set -> none of them is displayed' , (tester) async {
252
+ final user = eg.user (fullName: 'User' );
253
+ final composeInputFinder = await setupToComposeInput (tester, users: [user]);
254
+ await store.changeUserStatuses ({
255
+ user.userId: UserStatusChange (
256
+ text: OptionSome ('Busy' ),
257
+ emoji: OptionNone ()),
258
+ });
259
+ await tester.pump ();
260
+
261
+ // // TODO(#226): Remove this extra edit when this bug is fixed.
262
+ await tester.enterText (composeInputFinder, 'hello @u' );
263
+ await tester.enterText (composeInputFinder, 'hello @' );
264
+ await tester.pumpAndSettle (); // async computation; options appear
265
+
266
+ checkStatusEmoji (tester, isPresent: false );
267
+ check (find.descendant (of: find.byType (MentionAutocompleteItem ),
268
+ matching: find.text ('Busy' ))).findsNothing ();
269
+
270
+ debugNetworkImageHttpClientProvider = null ;
271
+ });
272
+
273
+ testWidgets ('status is not set -> emoji is not displayed' , (tester) async {
274
+ final user = eg.user (fullName: 'User' );
275
+ final composeInputFinder = await setupToComposeInput (tester, users: [user]);
276
+
277
+ // // TODO(#226): Remove this extra edit when this bug is fixed.
278
+ await tester.enterText (composeInputFinder, 'hello @u' );
279
+ await tester.enterText (composeInputFinder, 'hello @' );
280
+ await tester.pumpAndSettle (); // async computation; options appear
281
+
282
+ checkStatusEmoji (tester, isPresent: false );
283
+
284
+ debugNetworkImageHttpClientProvider = null ;
285
+ });
286
+ });
287
+
205
288
void checkWildcardShown (WildcardMentionOption wildcard, {required bool expected}) {
206
289
check (find.text (wildcard.canonicalString)).findsExactly (expected ? 1 : 0 );
207
290
}
0 commit comments