Skip to content

Commit

Permalink
Updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaturel committed Jan 5, 2023
1 parent cb45056 commit 740591c
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.flowOf
import org.amshove.kluent.shouldNotBeNull
import org.junit.Rule
import org.junit.Test

Expand All @@ -45,28 +44,22 @@ class RoomPollsViewModelTest {
}

@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
val filter = RoomPollsFilterType.ACTIVE
val action = RoomPollsAction.SetFilter(filter = filter)
val polls = listOf(givenAPollSummary())
every { fakeGetPollsUseCase.execute(any()) } returns flowOf(polls)
val viewModel = createViewModel()
every { fakeGetPollsUseCase.execute() } returns flowOf(polls)
val expectedViewState = initialState.copy(polls = polls)

// When
val viewModel = createViewModel()
val viewModelTest = viewModel.test()
viewModel.pollsCollectionJob = null
viewModel.handle(action)

// Then
viewModelTest
.assertLatestState(expectedViewState)
.finish()
viewModel.pollsCollectionJob.shouldNotBeNull()
verify {
viewModel.pollsCollectionJob?.cancel()
fakeGetPollsUseCase.execute(filter)
fakeGetPollsUseCase.execute()
}
}

Expand Down

0 comments on commit 740591c

Please sign in to comment.