@@ -153,6 +153,54 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
153
153
assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
154
154
}
155
155
156
+ func test_channelListItem_pollMessage_youVoted( ) throws {
157
+ // Given
158
+ let currentUserId = UserId . unique
159
+ let message = try mockPollMessage ( isSentByCurrentUser: false , latestVotes: [
160
+ . unique,
161
+ . unique,
162
+ . mock( pollId: . unique, optionId: . unique, user: . mock( id: currentUserId) )
163
+ ] )
164
+ let channel = ChatChannel . mock ( cid: . unique, membership: . mock( id: currentUserId) , latestMessages: [ message] )
165
+
166
+ // When
167
+ let view = ChatChannelListItem (
168
+ channel: channel,
169
+ channelName: " Test " ,
170
+ avatar: . circleImage,
171
+ onlineIndicatorShown: true ,
172
+ onItemTap: { _ in }
173
+ )
174
+ . frame ( width: defaultScreenSize. width)
175
+
176
+ // Then
177
+ assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
178
+ }
179
+
180
+ func test_channelListItem_pollMessage_someoneVoted( ) throws {
181
+ // Given
182
+ let currentUserId = UserId . unique
183
+ let message = try mockPollMessage ( isSentByCurrentUser: false , latestVotes: [
184
+ . unique,
185
+ . mock( pollId: . unique, optionId: . unique, user: . mock( id: currentUserId) ) ,
186
+ . mock( pollId: . unique, optionId: . unique, user: . mock( id: . unique, name: " Steve Jobs " ) )
187
+ ] )
188
+ let channel = ChatChannel . mock ( cid: . unique, membership: . mock( id: currentUserId) , latestMessages: [ message] )
189
+
190
+ // When
191
+ let view = ChatChannelListItem (
192
+ channel: channel,
193
+ channelName: " Test " ,
194
+ avatar: . circleImage,
195
+ onlineIndicatorShown: true ,
196
+ onItemTap: { _ in }
197
+ )
198
+ . frame ( width: defaultScreenSize. width)
199
+
200
+ // Then
201
+ assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
202
+ }
203
+
156
204
// MARK: - private
157
205
158
206
private func mockAudioMessage( text: String , isSentByCurrentUser: Bool ) throws -> ChatMessage {
@@ -271,7 +319,7 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
271
319
)
272
320
}
273
321
274
- private func mockPollMessage( isSentByCurrentUser: Bool ) throws -> ChatMessage {
322
+ private func mockPollMessage( isSentByCurrentUser: Bool , latestVotes : [ PollVote ] = [ ] ) throws -> ChatMessage {
275
323
. mock(
276
324
id: . unique,
277
325
cid: . unique,
@@ -281,7 +329,11 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
281
329
createdAt: Date ( timeIntervalSince1970: 100 ) ,
282
330
localState: nil ,
283
331
isSentByCurrentUser: isSentByCurrentUser,
284
- poll: . mock( optionCount: 1 , voteCountForOption: { _ in 0 } )
332
+ poll: . mock(
333
+ name: " Test poll " ,
334
+ createdBy: . mock( id: " test " , name: " test " ) ,
335
+ latestVotes: latestVotes
336
+ )
285
337
)
286
338
}
287
339
}
0 commit comments