Skip to content

Commit

Permalink
Fixes for UI State testing example
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy-chernysh committed Feb 17, 2024
1 parent cf8acb6 commit 3bb7399
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/testing-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ dependencies {
androidTestImplementation(libs.bundle("test.android"))
androidTestImplementation(libs.bundle("test.koin"))

testImplementation(libs.bundle("test"))
testImplementation(libs.bundle("test.common"))
testImplementation(libs.bundle("test.koin"))
}
6 changes: 1 addition & 5 deletions feature/people_list/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
plugins {
id("feature-module")
id("testing-module")
}

dependencies {
testImplementation(libs.bundles.test.common)
androidTestImplementation(libs.bundles.test.android)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.mobiledevpro.peoplelist.view

import android.util.Log
import androidx.lifecycle.viewModelScope
import com.mobiledevpro.peoplelist.domain.usecase.GetPeopleListUseCase
import com.mobiledevpro.ui.vm.BaseViewModel
Expand All @@ -29,10 +28,9 @@ class PeopleListViewModel(
private val getPeopleListUseCase: GetPeopleListUseCase
) : BaseViewModel<PeopleProfileUIState>() {

override fun initUIState(): PeopleProfileUIState = PeopleProfileUIState.Empty
override fun initUIState(): PeopleProfileUIState = PeopleProfileUIState.Loading

init {
Log.d("UI", "PeopleListViewModel init")
observePeopleList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
package com.mobiledevpro.peoplelist

import app.cash.turbine.test
import com.mobiledevpro.peoplelist.domain.usecase.GetPeopleListUseCase
import com.mobiledevpro.peoplelist.view.PeopleListViewModel
import com.mobiledevpro.peoplelist.view.PeopleProfileUIState
import com.mobiledevpro.ui.state.UIState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
Expand All @@ -36,26 +38,24 @@ class PeopleListViewModelTest {

private lateinit var vm: PeopleListViewModel

@OptIn(ExperimentalCoroutinesApi::class)
@Before
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher())
/*
val mocked = mockk<PeopleProfile>()
every { mocked.photo } returns Uri.EMPTY

*/
vm = PeopleListViewModel()
val useCase = GetPeopleListUseCase()
vm = PeopleListViewModel(getPeopleListUseCase = useCase)
assertTrue(
"Initial state is incorrect: ${vm.uiState.value}",
vm.uiState.value == PeopleProfileUIState.Empty
(vm.uiState.value as UIState) == PeopleProfileUIState.Loading
)
}

@Test
fun stateTest() = runTest {

vm.uiState.test {
assertEquals("State is not Loading", PeopleProfileUIState.Loading, awaitItem())
// assertEquals("State is not Loading", PeopleProfileUIState.Loading, awaitItem())

assertTrue(
"People list is empty",
Expand Down

0 comments on commit 3bb7399

Please sign in to comment.