Skip to content

Commit

Permalink
feat(mobile-app): Updated catalog search viewmodel unit tests (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonlom authored Mar 17, 2024
1 parent 1eb68d9 commit 2d6ee72
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.marlonlom.apps.cappajv.core.database.FakeLocalDataSource
import dev.marlonlom.apps.cappajv.util.MainDispatcherRule
import dev.marlonlom.apps.cappajv.util.RethrowingExceptionHandler
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -78,20 +79,9 @@ internal class CatalogSearchViewModelTest {
val expectedTitle = "chamfle"
viewModel.queryText.value = expectedTitle
viewModel.onQueryTextChanged()
val uiState = viewModel.searchResult.first()
assertNotNull(uiState)
when (uiState) {
is CatalogSearchUiState.Success -> {
assertTrue(uiState.results.isNotEmpty())
assertEquals(
3,
uiState.results.filter {
it.title.lowercase().contains(expectedTitle)
}.size
)
}

else -> fail()
viewModel.searchResult.collectLatest { uiState ->
assertNotNull(uiState)
assertTrue(uiState == CatalogSearchUiState.Empty)
}
}
}

0 comments on commit 2d6ee72

Please sign in to comment.