adding tests around initialising the viewmodel and handling email send success actions
This commit is contained in:
parent
796c5052c0
commit
fd255039f3
@ -102,6 +102,48 @@ class OnboardingViewModelTest {
|
|||||||
viewModelWith(initialState)
|
viewModelWith(initialState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given registration started with currentThreePid, when handling InitWith, then emits restored session OnSendEmailSuccess`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeAuthenticationService.givenRegistrationWizard(FakeRegistrationWizard().also {
|
||||||
|
it.givenRegistrationStarted(hasStarted = true)
|
||||||
|
it.givenCurrentThreePid(AN_EMAIL)
|
||||||
|
})
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.InitWith(LoginConfig(A_HOMESERVER_URL, identityServerUrl = null)))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertEvents(OnboardingViewEvents.OnSendEmailSuccess(AN_EMAIL, isRestoredSession = true))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given registration not started, when handling InitWith, then does nothing`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeAuthenticationService.givenRegistrationWizard(FakeRegistrationWizard().also { it.givenRegistrationStarted(hasStarted = false) })
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.InitWith(LoginConfig(A_HOMESERVER_URL, identityServerUrl = null)))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertNoEvents()
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given registration started without currentThreePid, when handling InitWith, then does nothing`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeAuthenticationService.givenRegistrationWizard(FakeRegistrationWizard().also {
|
||||||
|
it.givenRegistrationStarted(hasStarted = true)
|
||||||
|
it.givenCurrentThreePid(threePid = null)
|
||||||
|
})
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.InitWith(LoginConfig(A_HOMESERVER_URL, identityServerUrl = null)))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertNoEvents()
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when handling PostViewEvent, then emits contents as view event`() = runTest {
|
fun `when handling PostViewEvent, then emits contents as view event`() = runTest {
|
||||||
val test = viewModel.test()
|
val test = viewModel.test()
|
||||||
@ -254,6 +296,24 @@ class OnboardingViewModelTest {
|
|||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given register action returns email success, when handling action, then updates registration state and emits email success`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, RegistrationActionHandler.Result.SendEmailSuccess(AN_EMAIL))
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.PostRegisterAction(A_LOADABLE_REGISTER_ACTION))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertStatesChanges(
|
||||||
|
initialState,
|
||||||
|
{ copy(isLoading = true) },
|
||||||
|
{ copy(registrationState = RegistrationState(email = AN_EMAIL)) },
|
||||||
|
{ copy(isLoading = false) }
|
||||||
|
)
|
||||||
|
.assertEvents(OnboardingViewEvents.OnSendEmailSuccess(AN_EMAIL, isRestoredSession = false))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given unavailable deeplink, when selecting homeserver, then emits failure with default homeserver as retry action`() = runTest {
|
fun `given unavailable deeplink, when selecting homeserver, then emits failure with default homeserver as retry action`() = runTest {
|
||||||
fakeContext.givenHasConnection()
|
fakeContext.givenHasConnection()
|
||||||
|
@ -45,6 +45,14 @@ class FakeRegistrationWizard : RegistrationWizard by mockk(relaxed = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenRegistrationStarted(hasStarted: Boolean) {
|
||||||
|
coEvery { isRegistrationStarted() } returns hasStarted
|
||||||
|
}
|
||||||
|
|
||||||
|
fun givenCurrentThreePid(threePid: String?) {
|
||||||
|
coEvery { getCurrentThreePid() } returns threePid
|
||||||
|
}
|
||||||
|
|
||||||
fun givenUserNameIsAvailable(userName: String) {
|
fun givenUserNameIsAvailable(userName: String) {
|
||||||
coEvery { registrationAvailable(userName) } returns RegistrationAvailability.Available
|
coEvery { registrationAvailable(userName) } returns RegistrationAvailability.Available
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user