From 922b8092aca60f224e07c37d760bb8a43cf56548 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Wed, 1 Feb 2023 18:03:02 +0100 Subject: [PATCH] Render only winner options in past poll list --- .../roomprofile/polls/list/ui/PollSummaryMapper.kt | 4 +++- .../polls/list/ui/PollSummaryMapperTest.kt | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapper.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapper.kt index ea22d7d5a3..748dfd0886 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapper.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapper.kt @@ -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( diff --git a/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapperTest.kt b/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapperTest.kt index b523365970..2459e3c8da 100644 --- a/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapperTest.kt +++ b/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/PollSummaryMapperTest.kt @@ -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() + 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().also { + every { it.isWinner } returns isWinner + } + } }