Created
April 30, 2019 17:23
-
-
Save alexsullivan114/8281c3c5a9fdc8aa0b920c8da7be3079 to your computer and use it in GitHub Desktop.
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
@Test | |
fun `An invalid message is sent if a user inputs an invalid password`() { | |
val api = mockk<CostarApi>() | |
val remoteConfig = mockk<RemoteConfig>() | |
every { api.validatePassword(any()) } returns Single.just(Invalid(listOf(PasswordLengthShouldGT6))) | |
every { remoteConfig.getString(validation_password_too_short) } returns "Too short" | |
val viewModel = buildViewModel(api, remoteConfig = remoteConfig) | |
viewModel.newPasswordInput("test") | |
viewModel.fabClicked() | |
assertEquals("Too short", viewModel.errorMessageLiveData.value) | |
} | |
@Test | |
fun `A loading indicator is shown while a password is being validated`() { | |
val api = mockk<CostarApi>() | |
val testScheduler = TestScheduler() | |
every { api.validatePassword(any()) } returns Single.just(Valid) | |
val viewModel = buildViewModel(api, testScheduler.toContainer()) | |
viewModel.newPasswordInput("valid") | |
viewModel.fabClicked() | |
assertEquals(true, viewModel.showLoadingLiveData.value) | |
testScheduler.triggerActions() | |
assertEquals(false, viewModel.showLoadingLiveData.value) | |
} | |
@Test | |
fun `An analytic event is sent when the user submits their password`() { | |
val analytics = mockk<Analytics>(relaxed = true) | |
val viewModel = buildViewModel(analytics = analytics) | |
viewModel.fabClicked() | |
verify(exactly = 1) { analytics.logEvent(IncrementalPasswordSubmit) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment