Updating existing unit tests

This commit is contained in:
Maxime NATUREL 2023-02-02 17:53:43 +01:00
parent 361e23ac3f
commit 416f013c05
2 changed files with 28 additions and 25 deletions

View File

@ -36,9 +36,7 @@ class PollItemViewStateFactory @Inject constructor(
isSent: Boolean, isSent: Boolean,
): PollItemViewState { ): PollItemViewState {
val pollCreationInfo = pollContent.getBestPollCreationInfo() val pollCreationInfo = pollContent.getBestPollCreationInfo()
val question = pollCreationInfo?.question?.getBestQuestion().orEmpty() val question = pollCreationInfo?.question?.getBestQuestion().orEmpty()
val totalVotes = pollResponseData?.totalVotes ?: 0 val totalVotes = pollResponseData?.totalVotes ?: 0
return when { return when {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 New Vector Ltd * Copyright (c) 2023 New Vector Ltd
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,9 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.app.features.home.room.detail.timeline.factory package im.vector.app.features.roomprofile.factory
import im.vector.app.R import im.vector.app.R
import im.vector.app.features.home.room.detail.timeline.factory.PollItemViewStateFactory
import im.vector.app.features.home.room.detail.timeline.factory.PollOptionViewStateFactory
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
import im.vector.app.features.home.room.detail.timeline.item.PollVoteSummaryData import im.vector.app.features.home.room.detail.timeline.item.PollVoteSummaryData
import im.vector.app.features.poll.PollItemViewState import im.vector.app.features.poll.PollItemViewState
@ -31,7 +33,6 @@ import io.mockk.verify
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.api.session.room.model.message.PollType import org.matrix.android.sdk.api.session.room.model.message.PollType
import org.matrix.android.sdk.api.session.room.send.SendState
class PollItemViewStateFactoryTest { class PollItemViewStateFactoryTest {
@ -46,14 +47,14 @@ class PollItemViewStateFactoryTest {
@Test @Test
fun `given a sending poll state then poll is not votable and option states are PollSending`() { fun `given a sending poll state then poll is not votable and option states are PollSending`() {
// Given // Given
val sendingPollInformationData = A_MESSAGE_INFORMATION_DATA.copy(sendState = SendState.SENDING)
val optionViewStates = listOf(PollOptionViewState.PollSending(optionId = "", optionAnswer = "")) val optionViewStates = listOf(PollOptionViewState.PollSending(optionId = "", optionAnswer = ""))
every { fakePollOptionViewStateFactory.createPollSendingOptions(A_POLL_CONTENT.getBestPollCreationInfo()) } returns optionViewStates every { fakePollOptionViewStateFactory.createPollSendingOptions(A_POLL_CONTENT.getBestPollCreationInfo()) } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = A_POLL_CONTENT, pollContent = A_POLL_CONTENT,
informationData = sendingPollInformationData, pollResponseData = null,
isSent = false,
) )
// Then // Then
@ -70,7 +71,6 @@ class PollItemViewStateFactoryTest {
fun `given a sent poll state when poll is closed then poll is not votable and option states are Ended`() { fun `given a sent poll state when poll is closed then poll is not votable and option states are Ended`() {
// Given // Given
val closedPollSummary = A_POLL_RESPONSE_DATA.copy(isClosed = true) val closedPollSummary = A_POLL_RESPONSE_DATA.copy(isClosed = true)
val closedPollInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = closedPollSummary)
val optionViewStates = listOf( val optionViewStates = listOf(
PollOptionViewState.PollEnded( PollOptionViewState.PollEnded(
optionId = "", optionAnswer = "", voteCount = 0, votePercentage = 0.0, isWinner = false optionId = "", optionAnswer = "", voteCount = 0, votePercentage = 0.0, isWinner = false
@ -79,14 +79,15 @@ class PollItemViewStateFactoryTest {
every { every {
fakePollOptionViewStateFactory.createPollEndedOptions( fakePollOptionViewStateFactory.createPollEndedOptions(
A_POLL_CONTENT.getBestPollCreationInfo(), A_POLL_CONTENT.getBestPollCreationInfo(),
closedPollInformationData.pollResponseAggregatedSummary, closedPollSummary,
) )
} returns optionViewStates } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = A_POLL_CONTENT, pollContent = A_POLL_CONTENT,
informationData = closedPollInformationData, pollResponseData = closedPollSummary,
isSent = true,
) )
// Then // Then
@ -99,7 +100,7 @@ class PollItemViewStateFactoryTest {
verify { verify {
fakePollOptionViewStateFactory.createPollEndedOptions( fakePollOptionViewStateFactory.createPollEndedOptions(
A_POLL_CONTENT.getBestPollCreationInfo(), A_POLL_CONTENT.getBestPollCreationInfo(),
closedPollInformationData.pollResponseAggregatedSummary, closedPollSummary,
) )
} }
} }
@ -108,7 +109,6 @@ class PollItemViewStateFactoryTest {
fun `given a sent poll state with some decryption error when poll is closed then warning message is displayed`() { fun `given a sent poll state with some decryption error when poll is closed then warning message is displayed`() {
// Given // Given
val closedPollSummary = A_POLL_RESPONSE_DATA.copy(isClosed = true, hasEncryptedRelatedEvents = true) val closedPollSummary = A_POLL_RESPONSE_DATA.copy(isClosed = true, hasEncryptedRelatedEvents = true)
val closedPollInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = closedPollSummary)
val optionViewStates = listOf( val optionViewStates = listOf(
PollOptionViewState.PollEnded( PollOptionViewState.PollEnded(
optionId = "", optionAnswer = "", voteCount = 0, votePercentage = 0.0, isWinner = false optionId = "", optionAnswer = "", voteCount = 0, votePercentage = 0.0, isWinner = false
@ -117,14 +117,15 @@ class PollItemViewStateFactoryTest {
every { every {
fakePollOptionViewStateFactory.createPollEndedOptions( fakePollOptionViewStateFactory.createPollEndedOptions(
A_POLL_CONTENT.getBestPollCreationInfo(), A_POLL_CONTENT.getBestPollCreationInfo(),
closedPollInformationData.pollResponseAggregatedSummary, closedPollSummary,
) )
} returns optionViewStates } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = A_POLL_CONTENT, pollContent = A_POLL_CONTENT,
informationData = closedPollInformationData, pollResponseData = closedPollSummary,
isSent = true,
) )
// Then // Then
@ -134,6 +135,7 @@ class PollItemViewStateFactoryTest {
@Test @Test
fun `given a sent poll when undisclosed poll type is selected then poll is votable and option states are PollUndisclosed`() { fun `given a sent poll when undisclosed poll type is selected then poll is votable and option states are PollUndisclosed`() {
// Given // Given
val pollResponseData = A_POLL_RESPONSE_DATA
val optionViewStates = listOf( val optionViewStates = listOf(
PollOptionViewState.PollUndisclosed( PollOptionViewState.PollUndisclosed(
optionId = "", optionId = "",
@ -144,14 +146,15 @@ class PollItemViewStateFactoryTest {
every { every {
fakePollOptionViewStateFactory.createPollUndisclosedOptions( fakePollOptionViewStateFactory.createPollUndisclosedOptions(
A_POLL_CONTENT.getBestPollCreationInfo(), A_POLL_CONTENT.getBestPollCreationInfo(),
A_MESSAGE_INFORMATION_DATA.pollResponseAggregatedSummary, pollResponseData,
) )
} returns optionViewStates } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = A_POLL_CONTENT, pollContent = A_POLL_CONTENT,
informationData = A_MESSAGE_INFORMATION_DATA, pollResponseData = pollResponseData,
isSent = true,
) )
// Then // Then
@ -164,7 +167,7 @@ class PollItemViewStateFactoryTest {
verify { verify {
fakePollOptionViewStateFactory.createPollUndisclosedOptions( fakePollOptionViewStateFactory.createPollUndisclosedOptions(
A_POLL_CONTENT.getBestPollCreationInfo(), A_POLL_CONTENT.getBestPollCreationInfo(),
A_MESSAGE_INFORMATION_DATA.pollResponseAggregatedSummary, A_POLL_RESPONSE_DATA,
) )
} }
} }
@ -180,7 +183,6 @@ class PollItemViewStateFactoryTest {
kind = PollType.DISCLOSED_UNSTABLE kind = PollType.DISCLOSED_UNSTABLE
), ),
) )
val votedInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = votedPollData)
val optionViewStates = listOf( val optionViewStates = listOf(
PollOptionViewState.PollVoted( PollOptionViewState.PollVoted(
optionId = "", optionId = "",
@ -193,14 +195,15 @@ class PollItemViewStateFactoryTest {
every { every {
fakePollOptionViewStateFactory.createPollVotedOptions( fakePollOptionViewStateFactory.createPollVotedOptions(
disclosedPollContent.getBestPollCreationInfo(), disclosedPollContent.getBestPollCreationInfo(),
votedInformationData.pollResponseAggregatedSummary, votedPollData,
) )
} returns optionViewStates } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = disclosedPollContent, pollContent = disclosedPollContent,
informationData = votedInformationData, pollResponseData = votedPollData,
isSent = true,
) )
// Then // Then
@ -213,7 +216,7 @@ class PollItemViewStateFactoryTest {
verify { verify {
fakePollOptionViewStateFactory.createPollVotedOptions( fakePollOptionViewStateFactory.createPollVotedOptions(
disclosedPollContent.getBestPollCreationInfo(), disclosedPollContent.getBestPollCreationInfo(),
votedInformationData.pollResponseAggregatedSummary, votedPollData,
) )
} }
} }
@ -232,7 +235,6 @@ class PollItemViewStateFactoryTest {
kind = PollType.DISCLOSED_UNSTABLE kind = PollType.DISCLOSED_UNSTABLE
), ),
) )
val votedInformationData = A_MESSAGE_INFORMATION_DATA.copy(pollResponseAggregatedSummary = votedPollData)
val optionViewStates = listOf( val optionViewStates = listOf(
PollOptionViewState.PollVoted( PollOptionViewState.PollVoted(
optionId = "", optionId = "",
@ -245,14 +247,15 @@ class PollItemViewStateFactoryTest {
every { every {
fakePollOptionViewStateFactory.createPollVotedOptions( fakePollOptionViewStateFactory.createPollVotedOptions(
disclosedPollContent.getBestPollCreationInfo(), disclosedPollContent.getBestPollCreationInfo(),
votedInformationData.pollResponseAggregatedSummary, votedPollData,
) )
} returns optionViewStates } returns optionViewStates
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = disclosedPollContent, pollContent = disclosedPollContent,
informationData = votedInformationData, pollResponseData = votedPollData,
isSent = true,
) )
// Then // Then
@ -262,6 +265,7 @@ class PollItemViewStateFactoryTest {
@Test @Test
fun `given a sent poll when poll type is disclosed then poll is votable and option view states are PollReady`() { fun `given a sent poll when poll type is disclosed then poll is votable and option view states are PollReady`() {
// Given // Given
val pollResponseData = A_POLL_RESPONSE_DATA
val disclosedPollContent = A_POLL_CONTENT.copy( val disclosedPollContent = A_POLL_CONTENT.copy(
unstablePollCreationInfo = A_POLL_CONTENT.getBestPollCreationInfo()?.copy( unstablePollCreationInfo = A_POLL_CONTENT.getBestPollCreationInfo()?.copy(
kind = PollType.DISCLOSED_UNSTABLE kind = PollType.DISCLOSED_UNSTABLE
@ -282,7 +286,8 @@ class PollItemViewStateFactoryTest {
// When // When
val pollViewState = pollItemViewStateFactory.create( val pollViewState = pollItemViewStateFactory.create(
pollContent = disclosedPollContent, pollContent = disclosedPollContent,
informationData = A_MESSAGE_INFORMATION_DATA, pollResponseData = pollResponseData,
isSent = true,
) )
// Then // Then