Skip to content

Commit

Permalink
Add discoverScreenModel test.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskioko committed Nov 28, 2023
1 parent 0812138 commit 6ecaa72
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 99 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@ import app.cash.turbine.test
import com.thomaskioko.tvmaniac.shows.testing.FakeDiscoverRepository
import com.thomaskioko.tvmaniac.tmdb.testing.FakeShowImagesRepository
import io.kotest.matchers.shouldBe
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 kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test

internal class DiscoverStateMachineTest {
@OptIn(ExperimentalCoroutinesApi::class)
internal class DiscoverScreenModelTest {

private val testDispatcher = StandardTestDispatcher()
private val discoverRepository = FakeDiscoverRepository()
private val imagesRepository = FakeShowImagesRepository()
private val stateMachine = DiscoverStateMachine(discoverRepository, imagesRepository)

private lateinit var screenModel: DiscoverScreenModel

@BeforeTest
fun setUp() {
Dispatchers.setMain(testDispatcher)
screenModel = DiscoverScreenModel(discoverRepository, imagesRepository)
}

@AfterTest
fun tearDown() {
Dispatchers.resetMain()
}

@Test
fun `given an result is loaded then correct state is emitted`() = runTest {
Expand All @@ -20,7 +41,7 @@ internal class DiscoverStateMachineTest {
discoverRepository.setShowCategory(categoryResult(3))
discoverRepository.setShowCategory(categoryResult(4))

stateMachine.state.test {
screenModel.state.test {
awaitItem() shouldBe Loading
awaitItem() shouldBe discoverContent
}
Expand Down

0 comments on commit 6ecaa72

Please sign in to comment.