Test poll view state when poll option is deleted.
This commit is contained in:
parent
841b63b819
commit
f13dfb8291
|
@ -28,6 +28,7 @@ import im.vector.app.features.poll.create.FakeCreatePollViewStates.editedPollVie
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.initialCreatePollViewState
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.initialCreatePollViewState
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithOnlyQuestion
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithOnlyQuestion
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndEnoughOptions
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndEnoughOptions
|
||||||
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndEnoughOptionsButDeletedLastOption
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndMaxOptions
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndMaxOptions
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndNotEnoughOptions
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithQuestionAndNotEnoughOptions
|
||||||
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithoutQuestionAndEnoughOptions
|
import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithoutQuestionAndEnoughOptions
|
||||||
|
@ -41,7 +42,6 @@ import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.session.getRoom
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.PollType
|
import org.matrix.android.sdk.api.session.room.model.message.PollType
|
||||||
|
|
||||||
class CreatePollViewModelTest {
|
class CreatePollViewModelTest {
|
||||||
|
@ -203,6 +203,19 @@ class CreatePollViewModelTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given there is a question and enough options when the last option is deleted then view state should be updated accordingly`() = runTest {
|
||||||
|
val createPollViewModel = createPollViewModel(PollMode.CREATE)
|
||||||
|
|
||||||
|
createPollViewModel.handle(CreatePollAction.OnQuestionChanged(A_FAKE_QUESTION))
|
||||||
|
createPollViewModel.handle(CreatePollAction.OnOptionChanged(0, A_FAKE_OPTIONS[0]))
|
||||||
|
createPollViewModel.handle(CreatePollAction.OnOptionChanged(1, A_FAKE_OPTIONS[1]))
|
||||||
|
createPollViewModel.handle(CreatePollAction.OnDeleteOption(1))
|
||||||
|
|
||||||
|
delay(10)
|
||||||
|
createPollViewModel.test().assertState(pollViewStateWithQuestionAndEnoughOptionsButDeletedLastOption)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given an edited poll event when question and options are changed then view state is updated accordingly`() = runTest {
|
fun `given an edited poll event when question and options are changed then view state is updated accordingly`() = runTest {
|
||||||
val createPollViewModel = createPollViewModel(PollMode.EDIT)
|
val createPollViewModel = createPollViewModel(PollMode.EDIT)
|
||||||
|
|
|
@ -108,6 +108,12 @@ object FakeCreatePollViewStates {
|
||||||
canAddMoreOptions = true
|
canAddMoreOptions = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val pollViewStateWithQuestionAndEnoughOptionsButDeletedLastOption = pollViewStateWithQuestionAndEnoughOptions.copy(
|
||||||
|
options = A_FAKE_OPTIONS.take(CreatePollViewModel.MIN_OPTIONS_COUNT).toMutableList().apply { removeLast() },
|
||||||
|
canCreatePoll = false,
|
||||||
|
canAddMoreOptions = true
|
||||||
|
)
|
||||||
|
|
||||||
val pollViewStateWithQuestionAndMaxOptions = initialCreatePollViewState.copy(
|
val pollViewStateWithQuestionAndMaxOptions = initialCreatePollViewState.copy(
|
||||||
question = A_FAKE_QUESTION,
|
question = A_FAKE_QUESTION,
|
||||||
options = A_FAKE_OPTIONS.take(CreatePollViewModel.MAX_OPTIONS_COUNT),
|
options = A_FAKE_OPTIONS.take(CreatePollViewModel.MAX_OPTIONS_COUNT),
|
||||||
|
|
Loading…
Reference in New Issue