@@ -153,6 +153,54 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
153153 assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
154154 }
155155
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+
156204 // MARK: - private
157205
158206 private func mockAudioMessage( text: String , isSentByCurrentUser: Bool ) throws -> ChatMessage {
@@ -271,7 +319,7 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
271319 )
272320 }
273321
274- private func mockPollMessage( isSentByCurrentUser: Bool ) throws -> ChatMessage {
322+ private func mockPollMessage( isSentByCurrentUser: Bool , latestVotes : [ PollVote ] = [ ] ) throws -> ChatMessage {
275323 . mock(
276324 id: . unique,
277325 cid: . unique,
@@ -281,7 +329,11 @@ final class ChatChannelListItemView_Tests: StreamChatTestCase {
281329 createdAt: Date ( timeIntervalSince1970: 100 ) ,
282330 localState: nil ,
283331 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+ )
285337 )
286338 }
287339}
0 commit comments