From f13dfb829169dbd70ec26b7572b2a258869428a7 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 16 Jun 2022 14:11:17 +0300 Subject: [PATCH] Test poll view state when poll option is deleted. --- .../poll/create/CreatePollViewModelTest.kt | 15 ++++++++++++++- .../poll/create/FakeCreatePollViewStates.kt | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/vector/src/test/java/im/vector/app/features/poll/create/CreatePollViewModelTest.kt b/vector/src/test/java/im/vector/app/features/poll/create/CreatePollViewModelTest.kt index f73175faa3..e0364b286f 100644 --- a/vector/src/test/java/im/vector/app/features/poll/create/CreatePollViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/poll/create/CreatePollViewModelTest.kt @@ -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.pollViewStateWithOnlyQuestion 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.pollViewStateWithQuestionAndNotEnoughOptions import im.vector.app.features.poll.create.FakeCreatePollViewStates.pollViewStateWithoutQuestionAndEnoughOptions @@ -41,7 +42,6 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.PollType 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 fun `given an edited poll event when question and options are changed then view state is updated accordingly`() = runTest { val createPollViewModel = createPollViewModel(PollMode.EDIT) diff --git a/vector/src/test/java/im/vector/app/features/poll/create/FakeCreatePollViewStates.kt b/vector/src/test/java/im/vector/app/features/poll/create/FakeCreatePollViewStates.kt index b384a9a257..e5eeb86b04 100644 --- a/vector/src/test/java/im/vector/app/features/poll/create/FakeCreatePollViewStates.kt +++ b/vector/src/test/java/im/vector/app/features/poll/create/FakeCreatePollViewStates.kt @@ -108,6 +108,12 @@ object FakeCreatePollViewStates { 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( question = A_FAKE_QUESTION, options = A_FAKE_OPTIONS.take(CreatePollViewModel.MAX_OPTIONS_COUNT),