Updating unit tests
This commit is contained in:
parent
cb45056c1a
commit
740591cd38
@ -23,7 +23,6 @@ import io.mockk.every
|
|||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import org.amshove.kluent.shouldNotBeNull
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@ -45,28 +44,22 @@ class RoomPollsViewModelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given SetFilter action when handle then useCase is called with given filter and viewState is updated`() {
|
fun `given viewModel when created then polls list is observed and viewState is updated`() {
|
||||||
// Given
|
// Given
|
||||||
val filter = RoomPollsFilterType.ACTIVE
|
|
||||||
val action = RoomPollsAction.SetFilter(filter = filter)
|
|
||||||
val polls = listOf(givenAPollSummary())
|
val polls = listOf(givenAPollSummary())
|
||||||
every { fakeGetPollsUseCase.execute(any()) } returns flowOf(polls)
|
every { fakeGetPollsUseCase.execute() } returns flowOf(polls)
|
||||||
val viewModel = createViewModel()
|
|
||||||
val expectedViewState = initialState.copy(polls = polls)
|
val expectedViewState = initialState.copy(polls = polls)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
val viewModel = createViewModel()
|
||||||
val viewModelTest = viewModel.test()
|
val viewModelTest = viewModel.test()
|
||||||
viewModel.pollsCollectionJob = null
|
|
||||||
viewModel.handle(action)
|
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
viewModelTest
|
viewModelTest
|
||||||
.assertLatestState(expectedViewState)
|
.assertLatestState(expectedViewState)
|
||||||
.finish()
|
.finish()
|
||||||
viewModel.pollsCollectionJob.shouldNotBeNull()
|
|
||||||
verify {
|
verify {
|
||||||
viewModel.pollsCollectionJob?.cancel()
|
fakeGetPollsUseCase.execute()
|
||||||
fakeGetPollsUseCase.execute(filter)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user