@@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
3
3
import 'package:flutter_checks/flutter_checks.dart' ;
4
4
import 'package:flutter_test/flutter_test.dart' ;
5
5
import 'package:zulip/api/model/model.dart' ;
6
+ import 'package:zulip/basic.dart' ;
6
7
import 'package:zulip/widgets/app_bar.dart' ;
7
8
import 'package:zulip/widgets/compose_box.dart' ;
8
9
import 'package:zulip/widgets/content.dart' ;
10
+ import 'package:zulip/widgets/emoji.dart' ;
9
11
import 'package:zulip/widgets/home.dart' ;
10
12
import 'package:zulip/widgets/icons.dart' ;
11
13
import 'package:zulip/widgets/new_dm_sheet.dart' ;
@@ -21,6 +23,7 @@ import 'test_app.dart';
21
23
22
24
Future <void > setupSheet (WidgetTester tester, {
23
25
required List <User > users,
26
+ List <(int userId, UserStatusChange change)>? userStatuses,
24
27
}) async {
25
28
addTearDown (testBinding.reset);
26
29
@@ -31,6 +34,7 @@ Future<void> setupSheet(WidgetTester tester, {
31
34
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
32
35
final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
33
36
await store.addUsers (users);
37
+ await store.changeUserStatuses (userStatuses ?? []);
34
38
35
39
await tester.pumpWidget (TestZulipApp (
36
40
navigatorObservers: [testNavObserver],
@@ -61,7 +65,8 @@ void main() {
61
65
}
62
66
63
67
Finder findUserTile (User user) =>
64
- find.widgetWithText (InkWell , user.fullName).first;
68
+ find.ancestor (of: find.textContaining (user.fullName),
69
+ matching: find.byType (InkWell )).first;
65
70
66
71
Finder findUserChip (User user) {
67
72
final findAvatar = find.byWidgetPredicate ((widget) =>
@@ -114,18 +119,18 @@ void main() {
114
119
115
120
testWidgets ('shows all users initially' , (tester) async {
116
121
await setupSheet (tester, users: testUsers);
117
- check (find.text ('Alice Anderson' )).findsOne ();
118
- check (find.text ('Bob Brown' )).findsOne ();
119
- check (find.text ('Charlie Carter' )).findsOne ();
122
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
123
+ check (find.textContaining ('Bob Brown' )).findsOne ();
124
+ check (find.textContaining ('Charlie Carter' )).findsOne ();
120
125
});
121
126
122
127
testWidgets ('shows filtered users based on search' , (tester) async {
123
128
await setupSheet (tester, users: testUsers);
124
129
await tester.enterText (find.byType (TextField ), 'Alice' );
125
130
await tester.pump ();
126
- check (find.text ('Alice Anderson' )).findsOne ();
127
- check (find.text ('Charlie Carter' )).findsNothing ();
128
- check (find.text ('Bob Brown' )).findsNothing ();
131
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
132
+ check (find.textContaining ('Charlie Carter' )).findsNothing ();
133
+ check (find.textContaining ('Bob Brown' )).findsNothing ();
129
134
});
130
135
131
136
// TODO test sorting by recent-DMs
@@ -135,43 +140,43 @@ void main() {
135
140
await setupSheet (tester, users: testUsers);
136
141
await tester.enterText (find.byType (TextField ), 'alice' );
137
142
await tester.pump ();
138
- check (find.text ('Alice Anderson' )).findsOne ();
143
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
139
144
140
145
await tester.enterText (find.byType (TextField ), 'ALICE' );
141
146
await tester.pump ();
142
- check (find.text ('Alice Anderson' )).findsOne ();
147
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
143
148
});
144
149
145
150
testWidgets ('partial name and last name search handling' , (tester) async {
146
151
await setupSheet (tester, users: testUsers);
147
152
148
153
await tester.enterText (find.byType (TextField ), 'Ali' );
149
154
await tester.pump ();
150
- check (find.text ('Alice Anderson' )).findsOne ();
151
- check (find.text ('Bob Brown' )).findsNothing ();
152
- check (find.text ('Charlie Carter' )).findsNothing ();
155
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
156
+ check (find.textContaining ('Bob Brown' )).findsNothing ();
157
+ check (find.textContaining ('Charlie Carter' )).findsNothing ();
153
158
154
159
await tester.enterText (find.byType (TextField ), 'Anderson' );
155
160
await tester.pump ();
156
- check (find.text ('Alice Anderson' )).findsOne ();
157
- check (find.text ('Charlie Carter' )).findsNothing ();
158
- check (find.text ('Bob Brown' )).findsNothing ();
161
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
162
+ check (find.textContaining ('Charlie Carter' )).findsNothing ();
163
+ check (find.textContaining ('Bob Brown' )).findsNothing ();
159
164
160
165
await tester.enterText (find.byType (TextField ), 'son' );
161
166
await tester.pump ();
162
- check (find.text ('Alice Anderson' )).findsOne ();
163
- check (find.text ('Charlie Carter' )).findsNothing ();
164
- check (find.text ('Bob Brown' )).findsNothing ();
167
+ check (find.textContaining ('Alice Anderson' )).findsOne ();
168
+ check (find.textContaining ('Charlie Carter' )).findsNothing ();
169
+ check (find.textContaining ('Bob Brown' )).findsNothing ();
165
170
});
166
171
167
172
testWidgets ('shows empty state when no users match' , (tester) async {
168
173
await setupSheet (tester, users: testUsers);
169
174
await tester.enterText (find.byType (TextField ), 'Zebra' );
170
175
await tester.pump ();
171
- check (find.text ('No users found' )).findsOne ();
172
- check (find.text ('Alice Anderson' )).findsNothing ();
173
- check (find.text ('Bob Brown' )).findsNothing ();
174
- check (find.text ('Charlie Carter' )).findsNothing ();
176
+ check (find.textContaining ('No users found' )).findsOne ();
177
+ check (find.textContaining ('Alice Anderson' )).findsNothing ();
178
+ check (find.textContaining ('Bob Brown' )).findsNothing ();
179
+ check (find.textContaining ('Charlie Carter' )).findsNothing ();
175
180
});
176
181
177
182
testWidgets ('search text clears when user is selected' , (tester) async {
@@ -241,7 +246,7 @@ void main() {
241
246
await tester.tap (findUserTile (eg.selfUser));
242
247
await tester.pump ();
243
248
checkUserSelected (tester, eg.selfUser, true );
244
- check (find.text (eg.selfUser.fullName)).findsExactly (2 );
249
+ check (find.textContaining (eg.selfUser.fullName)).findsExactly (2 );
245
250
246
251
await tester.tap (findUserTile (otherUser));
247
252
await tester.pump ();
@@ -253,7 +258,7 @@ void main() {
253
258
final otherUser = eg.user (fullName: 'Other User' );
254
259
await setupSheet (tester, users: [eg.selfUser, otherUser]);
255
260
256
- check (find.text (eg.selfUser.fullName)).findsOne ();
261
+ check (find.textContaining (eg.selfUser.fullName)).findsOne ();
257
262
258
263
await tester.tap (findUserTile (otherUser));
259
264
await tester.pump ();
@@ -274,6 +279,54 @@ void main() {
274
279
});
275
280
});
276
281
282
+ testWidgets ('status emoji is set -> emoji is displayed' , (tester) async {
283
+ void checkTileStatusEmoji (User user, {required bool isPresent}) {
284
+ final statusEmojiFinder = find.ancestor (of: find.byType (UnicodeEmojiWidget ),
285
+ matching: find.byType (UserStatusEmoji ));
286
+
287
+ final tileStatusFinder = find.descendant (of: findUserTile (user),
288
+ matching: statusEmojiFinder);
289
+ check (tileStatusFinder).findsExactly (isPresent ? 1 : 0 );
290
+ }
291
+
292
+ void checkChipStatusEmoji (User user, {required bool isPresent}) {
293
+ final statusEmojiFinder = find.ancestor (of: find.byType (UnicodeEmojiWidget ),
294
+ matching: find.byType (UserStatusEmoji ));
295
+
296
+ final chipStatusFinder = find.descendant (of: findUserChip (user),
297
+ matching: statusEmojiFinder);
298
+ check (chipStatusFinder).findsExactly (isPresent ? 1 : 0 );
299
+ }
300
+
301
+ final user1 = eg.user (userId: 1 , fullName: 'User 1' );
302
+ final user2 = eg.user (userId: 2 , fullName: 'User 2' );
303
+ await setupSheet (tester, users: [user1, user2], userStatuses: [
304
+ (
305
+ user1.userId,
306
+ UserStatusChange (
307
+ text: OptionSome ('Busy' ),
308
+ emoji: OptionSome (StatusEmoji (emojiName: 'working_on_it' ,
309
+ emojiCode: '1f6e0' , reactionType: ReactionType .unicodeEmoji)))
310
+ ),
311
+ ]);
312
+
313
+ checkTileStatusEmoji (user1, isPresent: true );
314
+ checkTileStatusEmoji (user2, isPresent: false );
315
+ check (findUserChip (user1)).findsNothing ();
316
+ check (findUserChip (user2)).findsNothing ();
317
+
318
+ await tester.tap (findUserTile (user1));
319
+ await tester.tap (findUserTile (user2));
320
+ await tester.pump ();
321
+
322
+ checkTileStatusEmoji (user1, isPresent: true );
323
+ checkTileStatusEmoji (user2, isPresent: false );
324
+ check (findUserChip (user1)).findsOne ();
325
+ check (findUserChip (user2)).findsOne ();
326
+ checkChipStatusEmoji (user1, isPresent: true );
327
+ checkChipStatusEmoji (user2, isPresent: false );
328
+ });
329
+
277
330
group ('navigation to DM Narrow' , () {
278
331
Future <void > runAndCheck (WidgetTester tester, {
279
332
required List <User > users,
0 commit comments