Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSchildhorn committed Jan 1, 2024
1 parent b01a108 commit 6594f0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ data class LoginCredentials(

override fun toString(): String {
return """
hostname: $hostname
username: $username
password: $password
sharedFolder: $sharedFolder
shouldAutoConnect: $shouldAutoConnect
LoginCredentials(
hostname: $hostname
username: $username
password: $password
sharedFolder: $sharedFolder
shouldAutoConnect: $shouldAutoConnect
)
""".trimIndent()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.kevinschildhorn.fotopresenter.ui.viewmodel

import app.cash.turbine.test
import com.kevinschildhorn.fotopresenter.testingModule
import com.kevinschildhorn.fotopresenter.ui.UiState
import com.kevinschildhorn.fotopresenter.ui.screens.login.LoginViewModel
import com.russhwolf.settings.MapSettings
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.koin.core.context.startKoin
Expand Down Expand Up @@ -77,7 +79,7 @@ class LoginViewModelTest : KoinTest {
assertEquals("defaultUsername", username)
assertEquals("defaultPassword", password)
assertEquals("", sharedFolder)
assertEquals( false, shouldAutoConnect)
assertEquals(false, shouldAutoConnect)
assertEquals(UiState.IDLE, state)
}
}
Expand Down Expand Up @@ -147,17 +149,17 @@ class LoginViewModelTest : KoinTest {
viewModel.updateShouldAutoConnect(true)
viewModel.login()

with(viewModel.uiState.value) {
assertEquals(UiState.LOADING, state)
}

advanceUntilIdle()
with(viewModel.uiState.value) {
print(this.state)
// assertTrue(state is UiState.ERROR) TODO
viewModel.uiState.test {
var state = awaitItem()
while (state.state == UiState.LOADING || state.state == UiState.IDLE) {
state = awaitItem()
}
assertTrue(state.state is UiState.ERROR)
cancelAndIgnoreRemainingEvents()
}
}


@Test
fun `Login Success`() =
runTest {
Expand All @@ -171,13 +173,13 @@ class LoginViewModelTest : KoinTest {
viewModel.updateShouldAutoConnect(false)
viewModel.login()

with(viewModel.uiState.value) {
assertEquals(UiState.LOADING, state)
}

advanceUntilIdle()
with(viewModel.uiState.value) {
// assertEquals(UiState.SUCCESS, state) TODO
viewModel.uiState.test {
var state = awaitItem()
while (state.state == UiState.LOADING || state.state == UiState.IDLE) {
state = awaitItem()
}
assertEquals(UiState.SUCCESS, state.state)
cancelAndIgnoreRemainingEvents()
}
}

Expand Down

0 comments on commit 6594f0d

Please sign in to comment.