From 804513c808de54f318f808cc2d8c07e28d130d6b Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 2 Mar 2022 17:53:12 +0000 Subject: [PATCH] adding case for result ignoring register actions --- .../onboarding/OnboardingViewModelTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt index b485a3fa44..3c8279bafa 100644 --- a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt @@ -44,6 +44,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.matrix.android.sdk.api.auth.registration.FlowResult +import org.matrix.android.sdk.api.auth.registration.RegisterThreePid import org.matrix.android.sdk.api.auth.registration.RegistrationResult import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities @@ -52,7 +53,9 @@ private const val A_DISPLAY_NAME = "a display name" private const val A_PICTURE_FILENAME = "a-picture.png" private val AN_ERROR = RuntimeException("an error!") private val A_LOADABLE_REGISTER_ACTION = RegisterAction.StartRegistration +private val A_RESULT_IGNORED_REGISTER_ACTION = RegisterAction.AddThreePid(RegisterThreePid.Email("an email")) private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canChangeDisplayName = true, canChangeAvatar = true) +private val AN_IGNORED_FLOW_RESULT = FlowResult(missingStages = emptyList(), completedStages = emptyList()) class OnboardingViewModelTest { @@ -130,6 +133,23 @@ class OnboardingViewModelTest { .finish() } + @Test + fun `given register action ignores result, when handling action, then does nothing on success`() = runBlockingTest { + val test = viewModel.test(this) + givenRegistrationResultFor(A_RESULT_IGNORED_REGISTER_ACTION, RegistrationResult.FlowResponse(AN_IGNORED_FLOW_RESULT)) + + viewModel.handle(OnboardingAction.PostRegisterAction(A_RESULT_IGNORED_REGISTER_ACTION)) + + test + .assertStatesWithPrevious( + initialState, + { copy(asyncRegistration = Loading()) }, + { copy(asyncRegistration = Uninitialized) } + ) + .assertNoEvents() + .finish() + } + @Test fun `when registering account, then updates state and emits account created event`() = runBlockingTest { givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, RegistrationResult.Success(fakeSession))