-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding missing loading state when confirming password reset
- adds reset test cases to the onboarding view model
- Loading branch information
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import im.vector.app.test.fakes.FakeContext | |
import im.vector.app.test.fakes.FakeDirectLoginUseCase | ||
import im.vector.app.test.fakes.FakeHomeServerConnectionConfigFactory | ||
import im.vector.app.test.fakes.FakeHomeServerHistoryService | ||
import im.vector.app.test.fakes.FakeLoginWizard | ||
import im.vector.app.test.fakes.FakeRegisterActionHandler | ||
import im.vector.app.test.fakes.FakeRegistrationWizard | ||
import im.vector.app.test.fakes.FakeSession | ||
|
@@ -67,6 +68,8 @@ private val A_DIRECT_LOGIN = OnboardingAction.AuthenticateAction.LoginDirect("@a | |
private const val A_HOMESERVER_URL = "https://edited-homeserver.org" | ||
private val A_HOMESERVER_CONFIG = HomeServerConnectionConfig(FakeUri().instance) | ||
private val SELECTED_HOMESERVER_STATE = SelectedHomeserverState(preferredLoginMode = LoginMode.Password) | ||
private const val AN_EMAIL = "[email protected]" | ||
private const val A_PASSWORD = "a-password" | ||
|
||
class OnboardingViewModelTest { | ||
|
||
|
@@ -85,6 +88,7 @@ class OnboardingViewModelTest { | |
private val fakeHomeServerConnectionConfigFactory = FakeHomeServerConnectionConfigFactory() | ||
private val fakeStartAuthenticationFlowUseCase = FakeStartAuthenticationFlowUseCase() | ||
private val fakeHomeServerHistoryService = FakeHomeServerHistoryService() | ||
private val fakeLoginWizard = FakeLoginWizard() | ||
|
||
private var initialState = OnboardingViewState() | ||
private lateinit var viewModel: OnboardingViewModel | ||
|
@@ -466,6 +470,43 @@ class OnboardingViewModelTest { | |
.finish() | ||
} | ||
|
||
@Test | ||
fun `given can successfully reset password, when resetting password, then emits reset done event`() = runTest { | ||
val test = viewModel.test() | ||
fakeLoginWizard.givenResetPasswordSuccess(AN_EMAIL) | ||
fakeAuthenticationService.givenLoginWizard(fakeLoginWizard) | ||
|
||
viewModel.handle(OnboardingAction.ResetPassword(email = AN_EMAIL, newPassword = A_PASSWORD)) | ||
|
||
test | ||
.assertStatesChanges( | ||
initialState, | ||
{ copy(isLoading = true) }, | ||
{ copy(isLoading = false, resetState = ResetState(AN_EMAIL, A_PASSWORD)) } | ||
) | ||
.assertEvents(OnboardingViewEvents.OnResetPasswordSendThreePidDone) | ||
.finish() | ||
} | ||
|
||
@Test | ||
fun `given can successfully confirm reset password, when confirm reset password, then emits reset success`() = runTest { | ||
viewModelWith(initialState.copy(resetState = ResetState(AN_EMAIL, A_PASSWORD))) | ||
val test = viewModel.test() | ||
fakeLoginWizard.givenConfirmResetPasswordSuccess(A_PASSWORD) | ||
fakeAuthenticationService.givenLoginWizard(fakeLoginWizard) | ||
|
||
viewModel.handle(OnboardingAction.ResetPasswordMailConfirmed) | ||
|
||
test | ||
.assertStatesChanges( | ||
initialState, | ||
{ copy(isLoading = true) }, | ||
{ copy(isLoading = false, resetState = ResetState()) } | ||
) | ||
.assertEvents(OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess) | ||
.finish() | ||
} | ||
|
||
private fun viewModelWith(state: OnboardingViewState) { | ||
OnboardingViewModel( | ||
state, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
vector/src/test/java/im/vector/app/test/fakes/FakeLoginWizard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.test.fakes | ||
|
||
import io.mockk.coJustRun | ||
import io.mockk.mockk | ||
import org.matrix.android.sdk.api.auth.login.LoginWizard | ||
|
||
class FakeLoginWizard : LoginWizard by mockk() { | ||
|
||
fun givenResetPasswordSuccess(email: String) { | ||
coJustRun { resetPassword(email) } | ||
} | ||
|
||
fun givenConfirmResetPasswordSuccess(password: String) { | ||
coJustRun { resetPasswordMailConfirmed(password) } | ||
} | ||
} |