From 0184ff8603bc3bca20e04287f4c0d0fd5933d8c7 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 22 Dec 2022 13:31:43 +0100 Subject: [PATCH] Updating unit tests for PollItemViewStateFactory --- .../factory/PollItemViewStateFactory.kt | 1 - .../factory/PollItemViewStateFactoryTest.kt | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactory.kt index 64f529fb59..28c560e161 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactory.kt @@ -31,7 +31,6 @@ class PollItemViewStateFactory @Inject constructor( private val stringProvider: StringProvider, ) { - // TODO update unit tests fun create( pollContent: MessagePollContent, informationData: MessageInformationData, diff --git a/vector/src/test/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactoryTest.kt b/vector/src/test/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactoryTest.kt index 78e544f79d..4d14458e7f 100644 --- a/vector/src/test/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactoryTest.kt +++ b/vector/src/test/java/im/vector/app/features/home/room/detail/timeline/factory/PollItemViewStateFactoryTest.kt @@ -131,6 +131,24 @@ class PollItemViewStateFactoryTest { ) } + @Test + fun `given a sent poll state with some decryption error when poll is closed then warning message is displayed`() { + // Given + val stringProvider = FakeStringProvider() + val pollItemViewStateFactory = PollItemViewStateFactory(stringProvider.instance) + val closedPollSummary = A_POLL_RESPONSE_DATA.copy(isClosed = true, hasDecryptionError = true) + val closedPollInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = closedPollSummary) + + // When + val pollViewState = pollItemViewStateFactory.create( + pollContent = A_POLL_CONTENT, + informationData = closedPollInformationData, + ) + + // Then + pollViewState.votesStatus shouldBeEqualTo stringProvider.instance.getString(R.string.unable_to_decrypt_some_events_in_poll) + } + @Test fun `given a sent poll when undisclosed poll type is selected then poll is votable and option states are PollUndisclosed`() { val stringProvider = FakeStringProvider() @@ -193,6 +211,34 @@ class PollItemViewStateFactoryTest { ) } + @Test + fun `given a sent poll with decryption failure when my vote exists then a warning message is displayed`() { + // Given + val stringProvider = FakeStringProvider() + val pollItemViewStateFactory = PollItemViewStateFactory(stringProvider.instance) + val votedPollData = A_POLL_RESPONSE_DATA.copy( + totalVotes = 1, + myVote = A_POLL_OPTION_IDS[0], + votes = mapOf(A_POLL_OPTION_IDS[0] to PollVoteSummaryData(total = 1, percentage = 1.0)), + hasDecryptionError = true, + ) + val disclosedPollContent = A_POLL_CONTENT.copy( + unstablePollCreationInfo = A_POLL_CONTENT.getBestPollCreationInfo()?.copy( + kind = PollType.DISCLOSED_UNSTABLE + ), + ) + val votedInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = votedPollData) + + // When + val pollViewState = pollItemViewStateFactory.create( + pollContent = disclosedPollContent, + informationData = votedInformationData, + ) + + // Then + pollViewState.votesStatus shouldBeEqualTo stringProvider.instance.getString(R.string.unable_to_decrypt_some_events_in_poll) + } + @Test fun `given a sent poll when poll type is disclosed then poll is votable and option view states are PollReady`() { val stringProvider = FakeStringProvider()