|
| 1 | +// ignore_for_file: avoid_redundant_argument_values |
| 2 | + |
1 | 3 | import 'dart:async'; |
2 | 4 | import 'dart:convert'; |
3 | 5 |
|
@@ -59,7 +61,17 @@ void main() { |
59 | 61 | comments: [ |
60 | 62 | createDefaultCommentResponse(id: 'comment-1', objectId: 'obj-1'), |
61 | 63 | createDefaultCommentResponse(id: 'comment-2', objectId: 'obj-1'), |
62 | | - createDefaultCommentResponse(id: 'comment-3', objectId: 'obj-1'), |
| 64 | + createDefaultCommentResponse( |
| 65 | + id: 'comment-3', |
| 66 | + objectId: 'obj-1', |
| 67 | + reactionGroups: { |
| 68 | + 'like': ReactionGroupResponse( |
| 69 | + count: 1, |
| 70 | + firstReactionAt: DateTime(2025, 1, 1), |
| 71 | + lastReactionAt: DateTime(2025, 1, 1), |
| 72 | + ), |
| 73 | + }, |
| 74 | + ), |
63 | 75 | ], |
64 | 76 | ), |
65 | 77 | ), |
@@ -136,5 +148,90 @@ void main() { |
136 | 148 | expect(commentList.state.comments, hasLength(3)); |
137 | 149 | }, |
138 | 150 | ); |
| 151 | + |
| 152 | + test('comment reaction added', () async { |
| 153 | + final commentList = client.commentList( |
| 154 | + CommentsQuery( |
| 155 | + filter: Filter.equal(CommentsFilterField.status, 'active'), |
| 156 | + ), |
| 157 | + ); |
| 158 | + await commentList.get(); |
| 159 | + expect(commentList.state.comments, hasLength(3)); |
| 160 | + expect(commentList.state.comments[1].reactionCount, 0); |
| 161 | + expect(commentList.state.comments[1].reactionGroups.length, 0); |
| 162 | + |
| 163 | + wsStreamController.add( |
| 164 | + jsonEncode( |
| 165 | + CommentReactionAddedEvent( |
| 166 | + type: EventTypes.commentReactionAdded, |
| 167 | + activity: createDefaultActivityResponse().activity, |
| 168 | + comment: createDefaultCommentResponse( |
| 169 | + id: 'comment-2', |
| 170 | + objectId: 'obj-1', |
| 171 | + ), |
| 172 | + createdAt: DateTime.now(), |
| 173 | + custom: const {}, |
| 174 | + fid: 'user:id', |
| 175 | + reaction: FeedsReactionResponse( |
| 176 | + activityId: 'obj-1', |
| 177 | + commentId: 'comment-2', |
| 178 | + type: 'like', |
| 179 | + createdAt: DateTime.now(), |
| 180 | + updatedAt: DateTime.now(), |
| 181 | + user: createDefaultUserResponse(), |
| 182 | + ), |
| 183 | + ), |
| 184 | + ), |
| 185 | + ); |
| 186 | + |
| 187 | + await Future<Object?>.delayed(Duration.zero); |
| 188 | + |
| 189 | + expect(commentList.state.comments, hasLength(3)); |
| 190 | + expect(commentList.state.comments[1].reactionCount, 1); |
| 191 | + expect(commentList.state.comments[1].reactionGroups.length, 1); |
| 192 | + expect(commentList.state.comments[1].reactionGroups['like']?.count, 1); |
| 193 | + }); |
| 194 | + |
| 195 | + test('comment reaction deleted', () async { |
| 196 | + final commentList = client.commentList( |
| 197 | + CommentsQuery( |
| 198 | + filter: Filter.equal(CommentsFilterField.status, 'active'), |
| 199 | + ), |
| 200 | + ); |
| 201 | + await commentList.get(); |
| 202 | + expect(commentList.state.comments, hasLength(3)); |
| 203 | + expect(commentList.state.comments[2].reactionCount, 1); |
| 204 | + expect(commentList.state.comments[2].reactionGroups.length, 1); |
| 205 | + expect(commentList.state.comments[2].reactionGroups['like']?.count, 1); |
| 206 | + |
| 207 | + wsStreamController.add( |
| 208 | + jsonEncode( |
| 209 | + CommentReactionDeletedEvent( |
| 210 | + type: EventTypes.commentReactionDeleted, |
| 211 | + createdAt: DateTime.now(), |
| 212 | + custom: const {}, |
| 213 | + fid: 'user:id', |
| 214 | + comment: createDefaultCommentResponse( |
| 215 | + id: 'comment-3', |
| 216 | + objectId: 'obj-1', |
| 217 | + ), |
| 218 | + reaction: FeedsReactionResponse( |
| 219 | + activityId: 'obj-1', |
| 220 | + commentId: 'comment-3', |
| 221 | + type: 'like', |
| 222 | + createdAt: DateTime(2025, 1, 1), |
| 223 | + updatedAt: DateTime.now(), |
| 224 | + user: createDefaultUserResponse(), |
| 225 | + ), |
| 226 | + ), |
| 227 | + ), |
| 228 | + ); |
| 229 | + |
| 230 | + await Future<Object?>.delayed(Duration.zero); |
| 231 | + |
| 232 | + expect(commentList.state.comments, hasLength(3)); |
| 233 | + expect(commentList.state.comments[2].reactionCount, 0); |
| 234 | + expect(commentList.state.comments[2].reactionGroups.length, 0); |
| 235 | + }); |
139 | 236 | }); |
140 | 237 | } |
0 commit comments