@@ -7,6 +7,12 @@ import '../api/model/model_checks.dart';
7
7
import '../example_data.dart' as eg;
8
8
import 'test_store.dart' ;
9
9
10
+ typedef StatusData = (String ? statusText, String ? emojiName, String ? emojiCode,
11
+ String ? reactionType);
12
+
13
+ typedef StatusEventData = (int userId, String ? statusText, String ? emojiName,
14
+ String ? emojiCode, String ? reactionType);
15
+
10
16
void main () {
11
17
group ('userDisplayName' , () {
12
18
test ('on a known user' , () async {
@@ -80,6 +86,82 @@ void main() {
80
86
});
81
87
});
82
88
89
+ testWidgets ('UserStatusEvent' , (tester) async {
90
+ UserStatusChange userStatus (StatusData data) => UserStatusChange .fromJson ({
91
+ 'status_text' : data.$1,
92
+ 'emoji_name' : data.$2,
93
+ 'emoji_code' : data.$3,
94
+ 'reaction_type' : data.$4,
95
+ });
96
+
97
+ void checkUserStatus (UserStatus userStatus, StatusData expected) {
98
+ check (userStatus)
99
+ .text.equals (expected.$1);
100
+
101
+ switch (expected) {
102
+ case (_, String emojiName, String emojiCode, String reactionType):
103
+ check (userStatus.emoji! )
104
+ ..emojiName.equals (emojiName)
105
+ ..emojiCode.equals (emojiCode)
106
+ ..reactionType.equals (ReactionType .fromApiValue (reactionType));
107
+ default :
108
+ check (userStatus.emoji).isNull ();
109
+ }
110
+ }
111
+
112
+ UserStatusEvent userStatusEvent (StatusEventData data) => UserStatusEvent (
113
+ id: 1 ,
114
+ userId: data.$1,
115
+ change: UserStatusChange .fromJson ({
116
+ 'status_text' : data.$2,
117
+ 'emoji_name' : data.$3,
118
+ 'emoji_code' : data.$4,
119
+ 'reaction_type' : data.$5,
120
+ }),
121
+ );
122
+
123
+ final store = eg.store (initialSnapshot: eg.initialSnapshot (
124
+ userStatuses: {
125
+ 1 : userStatus (('Busy' , 'working_on_it' , '1f6e0' , 'unicode_emoji' )),
126
+ 2 : userStatus ((null , 'calendar' , '1f4c5' , 'unicode_emoji' )),
127
+ 3 : userStatus (('Commuting' , null , null , null )),
128
+ }
129
+ ));
130
+ checkUserStatus (store.getUserStatus (1 ),
131
+ ('Busy' , 'working_on_it' , '1f6e0' , 'unicode_emoji' ));
132
+ checkUserStatus (store.getUserStatus (2 ),
133
+ (null , 'calendar' , '1f4c5' , 'unicode_emoji' ));
134
+ checkUserStatus (store.getUserStatus (3 ),
135
+ ('Commuting' , null , null , null ));
136
+ check (store.getUserStatus (4 ))..text.isNull ()..emoji.isNull ();
137
+ check (store.getUserStatus (5 ))..text.isNull ()..emoji.isNull ();
138
+
139
+ await store.handleEvent (userStatusEvent ((1 ,
140
+ 'Out sick' , 'sick' , '1f912' , 'unicode_emoji' )));
141
+ checkUserStatus (store.getUserStatus (1 ),
142
+ ('Out sick' , 'sick' , '1f912' , 'unicode_emoji' ));
143
+
144
+ await store.handleEvent (userStatusEvent ((2 ,
145
+ 'In a meeting' , null , null , null )));
146
+ checkUserStatus (store.getUserStatus (2 ),
147
+ ('In a meeting' , 'calendar' , '1f4c5' , 'unicode_emoji' ));
148
+
149
+ await store.handleEvent (userStatusEvent ((3 ,
150
+ '' , 'bus' , '1f68c' , 'unicode_emoji' )));
151
+ checkUserStatus (store.getUserStatus (3 ),
152
+ (null , 'bus' , '1f68c' , 'unicode_emoji' ));
153
+
154
+ await store.handleEvent (userStatusEvent ((4 ,
155
+ 'Vacationing' , null , null , null )));
156
+ checkUserStatus (store.getUserStatus (4 ),
157
+ ('Vacationing' , null , null , null ));
158
+
159
+ await store.handleEvent (userStatusEvent ((5 ,
160
+ 'Working remotely' , '' , '' , '' )));
161
+ checkUserStatus (store.getUserStatus (5 ),
162
+ ('Working remotely' , null , null , null ));
163
+ });
164
+
83
165
testWidgets ('MutedUsersEvent' , (tester) async {
84
166
final user1 = eg.user (userId: 1 );
85
167
final user2 = eg.user (userId: 2 );
0 commit comments