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