mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 18:05:59 +03:00
cleaning up test names and bodies to be clearer
This commit is contained in:
parent
b2a1aa17bd
commit
75cbb727a4
2 changed files with 63 additions and 22 deletions
|
@ -37,6 +37,7 @@ import im.vector.app.test.fakes.FakeUri
|
|||
import im.vector.app.test.fakes.FakeUriFilenameResolver
|
||||
import im.vector.app.test.fakes.FakeVectorFeatures
|
||||
import im.vector.app.test.fakes.FakeVectorOverrides
|
||||
import im.vector.app.test.fixtures.aHomeServerCapabilities
|
||||
import im.vector.app.test.test
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import org.junit.Before
|
||||
|
@ -51,6 +52,7 @@ 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_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canChangeDisplayName = true, canChangeAvatar = true)
|
||||
|
||||
class OnboardingViewModelTest {
|
||||
|
||||
|
@ -129,38 +131,27 @@ class OnboardingViewModelTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `given registration has started and has dummy step to do, when handling action, then ignores other steps and executes dummy`() = runBlockingTest {
|
||||
fun `when registering account, then updates state and emits account created event`() = runBlockingTest {
|
||||
givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, RegistrationResult.Success(fakeSession))
|
||||
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
|
||||
val test = viewModel.test(this)
|
||||
|
||||
val homeServerCapabilities = HomeServerCapabilities(canChangeDisplayName = true, canChangeAvatar = true)
|
||||
fakeSession.fakeHomeServerCapabilitiesService.givenCapabilities(homeServerCapabilities)
|
||||
val flowResult = FlowResult(missingStages = listOf(Stage.Dummy(mandatory = true), Stage.Email(true)), completedStages = emptyList())
|
||||
givenRegistrationResultsFor(listOf(
|
||||
A_LOADABLE_REGISTER_ACTION to RegistrationResult.FlowResponse(flowResult),
|
||||
RegisterAction.RegisterDummy to RegistrationResult.Success(fakeSession)
|
||||
))
|
||||
givenSuccessfullyCreatesAccount()
|
||||
|
||||
viewModel.handle(OnboardingAction.PostRegisterAction(A_LOADABLE_REGISTER_ACTION))
|
||||
|
||||
test
|
||||
.assertStatesWithPrevious(
|
||||
initialState,
|
||||
{ copy(asyncRegistration = Loading()) },
|
||||
{ copy(asyncLoginAction = Success(Unit), personalizationState = homeServerCapabilities.toPersonalisationState()) },
|
||||
{ copy(asyncRegistration = Uninitialized) },
|
||||
|
||||
)
|
||||
{ copy(asyncLoginAction = Success(Unit), personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState()) },
|
||||
{ copy(asyncLoginAction = Success(Unit), asyncRegistration = Uninitialized) }
|
||||
)
|
||||
.assertEvents(OnboardingViewEvents.OnAccountCreated)
|
||||
.finish()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given homeserver does not support personalisation, when registering account, then updates state and emits account created event`() = runBlockingTest {
|
||||
val homeServerCapabilities = HomeServerCapabilities(canChangeDisplayName = false, canChangeAvatar = false)
|
||||
fakeSession.fakeHomeServerCapabilitiesService.givenCapabilities(homeServerCapabilities)
|
||||
givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, RegistrationResult.Success(fakeSession))
|
||||
givenSuccessfullyCreatesAccount()
|
||||
fun `given registration has started and has dummy step to do, when handling action, then ignores other steps and executes dummy`() = runBlockingTest {
|
||||
givenSuccessfulRegistrationForStartAndDummySteps(missingStages = listOf(Stage.Dummy(mandatory = true)))
|
||||
val test = viewModel.test(this)
|
||||
|
||||
viewModel.handle(OnboardingAction.PostRegisterAction(A_LOADABLE_REGISTER_ACTION))
|
||||
|
@ -169,8 +160,8 @@ class OnboardingViewModelTest {
|
|||
.assertStatesWithPrevious(
|
||||
initialState,
|
||||
{ copy(asyncRegistration = Loading()) },
|
||||
{ copy(asyncLoginAction = Success(Unit), personalizationState = homeServerCapabilities.toPersonalisationState()) },
|
||||
{ copy(asyncLoginAction = Success(Unit), asyncRegistration = Uninitialized) }
|
||||
{ copy(asyncLoginAction = Success(Unit), personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState()) },
|
||||
{ copy(asyncRegistration = Uninitialized) }
|
||||
)
|
||||
.assertEvents(OnboardingViewEvents.OnAccountCreated)
|
||||
.finish()
|
||||
|
@ -339,7 +330,17 @@ class OnboardingViewModelTest {
|
|||
)
|
||||
}
|
||||
|
||||
private fun givenSuccessfullyCreatesAccount() {
|
||||
private fun givenSuccessfulRegistrationForStartAndDummySteps(missingStages: List<Stage>) {
|
||||
val flowResult = FlowResult(missingStages = missingStages, completedStages = emptyList())
|
||||
givenRegistrationResultsFor(listOf(
|
||||
A_LOADABLE_REGISTER_ACTION to RegistrationResult.FlowResponse(flowResult),
|
||||
RegisterAction.RegisterDummy to RegistrationResult.Success(fakeSession)
|
||||
))
|
||||
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
|
||||
}
|
||||
|
||||
private fun givenSuccessfullyCreatesAccount(homeServerCapabilities: HomeServerCapabilities) {
|
||||
fakeSession.fakeHomeServerCapabilitiesService.givenCapabilities(homeServerCapabilities)
|
||||
fakeActiveSessionHolder.expectSetsActiveSession(fakeSession)
|
||||
fakeAuthenticationService.expectReset()
|
||||
fakeSession.expectStartsSyncing()
|
||||
|
|
40
vector/src/test/java/im/vector/app/test/fixtures/HomeserverCapabilityFixture.kt
vendored
Normal file
40
vector/src/test/java/im/vector/app/test/fixtures/HomeserverCapabilityFixture.kt
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.fixtures
|
||||
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.api.session.homeserver.RoomVersionCapabilities
|
||||
|
||||
fun aHomeServerCapabilities(
|
||||
canChangePassword: Boolean = true,
|
||||
canChangeDisplayName: Boolean = true,
|
||||
canChangeAvatar: Boolean = true,
|
||||
canChange3pid: Boolean = true,
|
||||
maxUploadFileSize: Long = 100L,
|
||||
lastVersionIdentityServerSupported: Boolean = false,
|
||||
defaultIdentityServerUrl: String? = null,
|
||||
roomVersions: RoomVersionCapabilities? = null
|
||||
) = HomeServerCapabilities(
|
||||
canChangePassword,
|
||||
canChangeDisplayName,
|
||||
canChangeAvatar,
|
||||
canChange3pid,
|
||||
maxUploadFileSize,
|
||||
lastVersionIdentityServerSupported,
|
||||
defaultIdentityServerUrl,
|
||||
roomVersions
|
||||
)
|
Loading…
Reference in a new issue