adding tests around forwarding to the edit server selection when the initial server selection fails

This commit is contained in:
Adam Brown 2022-08-19 13:03:59 +01:00
parent b50b6daca1
commit d7bc43584d

View File

@ -411,6 +411,63 @@ class OnboardingViewModelTest {
.finish()
}
@Test
fun `given in sign in flow, when selecting homeserver fails with network error, then emits Failure`() = runTest {
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignIn))
fakeVectorFeatures.givenCombinedLoginEnabled()
givenHomeserverSelectionFailsWith(AN_ERROR)
val test = viewModel.test()
viewModel.handle(OnboardingAction.HomeServerChange.SelectHomeServer(A_HOMESERVER_URL))
test
.assertStatesChanges(
initialState,
{ copy(isLoading = true) },
{ copy(isLoading = false) }
)
.assertEvents(OnboardingViewEvents.Failure(AN_ERROR))
.finish()
}
@Test
fun `given in sign in flow, when selecting homeserver fails with network error, then emits EditServerSelection`() = runTest {
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignIn))
fakeVectorFeatures.givenCombinedLoginEnabled()
givenHomeserverSelectionFailsWithNetworkError()
val test = viewModel.test()
viewModel.handle(OnboardingAction.HomeServerChange.SelectHomeServer(A_HOMESERVER_URL))
test
.assertStatesChanges(
initialState,
{ copy(isLoading = true) },
{ copy(isLoading = false) }
)
.assertEvents(OnboardingViewEvents.EditServerSelection)
.finish()
}
@Test
fun `given in sign up flow, when selecting homeserver fails with network error, then emits EditServerSelection`() = runTest {
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignUp))
fakeVectorFeatures.givenCombinedRegisterEnabled()
givenHomeserverSelectionFailsWithNetworkError()
val test = viewModel.test()
viewModel.handle(OnboardingAction.HomeServerChange.SelectHomeServer(A_HOMESERVER_URL))
test
.assertStatesChanges(
initialState,
{ copy(isLoading = true) },
{ copy(isLoading = false) }
)
.assertEvents(OnboardingViewEvents.EditServerSelection)
.finish()
}
@Test
fun `given in the sign up flow, when editing homeserver, then updates selected homeserver state and emits edited event`() = runTest {
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignUp))
@ -1121,6 +1178,18 @@ class OnboardingViewModelTest {
private fun initialRegistrationState(homeServerUrl: String) = initialState.copy(
onboardingFlow = OnboardingFlow.SignUp, selectedHomeserver = SelectedHomeserverState(userFacingUrl = homeServerUrl)
)
private fun givenHomeserverSelectionFailsWithNetworkError() {
fakeContext.givenHasConnection()
fakeHomeServerConnectionConfigFactory.givenConfigFor(A_HOMESERVER_URL, fingerprint = null, A_HOMESERVER_CONFIG)
fakeStartAuthenticationFlowUseCase.givenHomeserverUnavailable(A_HOMESERVER_CONFIG)
}
private fun givenHomeserverSelectionFailsWith(cause: Throwable) {
fakeContext.givenHasConnection()
fakeHomeServerConnectionConfigFactory.givenConfigFor(A_HOMESERVER_URL, fingerprint = null, A_HOMESERVER_CONFIG)
fakeStartAuthenticationFlowUseCase.givenErrors(A_HOMESERVER_CONFIG, cause)
}
}
private fun HomeServerCapabilities.toPersonalisationState(displayName: String? = null) = PersonalizationState(