Render only winner options in past poll list

This commit is contained in:
Maxime NATUREL 2023-02-01 18:03:02 +01:00
parent d3df58c607
commit 922b8092ac
2 changed files with 14 additions and 4 deletions

View file

@ -69,7 +69,9 @@ class PollSummaryMapper @Inject constructor(
creationTimestamp = creationTimestamp,
title = pollTitle,
totalVotes = pollResponseData.totalVotes,
winnerOptions = pollOptionViewStateFactory.createPollEndedOptions(pollCreationInfo, pollResponseData),
winnerOptions = pollOptionViewStateFactory
.createPollEndedOptions(pollCreationInfo, pollResponseData)
.filter { it.isWinner },
)
} else {
PollSummary.ActivePoll(

View file

@ -84,10 +84,12 @@ internal class PollSummaryMapperTest {
}
@Test
fun `given an ended poll event when mapping to model then result is ended poll`() {
fun `given an ended poll event when mapping to model then result is ended poll with only winner options`() {
// Given
val totalVotes = 10
val winnerOptions = listOf<PollOptionViewState.PollEnded>()
val option1 = givenAPollEndedOption(isWinner = false)
val option2 = givenAPollEndedOption(isWinner = true)
val winnerOptions = listOf(option1, option2)
val endedPollEvent = givenAPollTimelineEvent(
eventId = AN_EVENT_ID,
creationTimestamp = AN_EVENT_TIMESTAMP,
@ -101,7 +103,7 @@ internal class PollSummaryMapperTest {
creationTimestamp = AN_EVENT_TIMESTAMP,
title = A_POLL_TITLE,
totalVotes = totalVotes,
winnerOptions = winnerOptions,
winnerOptions = listOf(option2),
)
// When
@ -198,4 +200,10 @@ internal class PollSummaryMapperTest {
totalVotes = totalVotes,
)
}
private fun givenAPollEndedOption(isWinner: Boolean): PollOptionViewState.PollEnded {
return mockk<PollOptionViewState.PollEnded>().also {
every { it.isWinner } returns isWinner
}
}
}