Skip to content

Commit

Permalink
Add test to verifying initial state when view binds
Browse files Browse the repository at this point in the history
  • Loading branch information
edwnmrtnz committed Jun 6, 2023
1 parent 5831fc7 commit 80ec150
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.edwnmrtnz.trendingrepo.ui

import com.edwnmrtnz.trendingrepo.StatefulPresenter

class MainPresenter : StatefulPresenter<MainUiState, MainScreenView>() {

override fun initialState() = MainUiState(isLoading = true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.edwnmrtnz.trendingrepo.ui

import com.edwnmrtnz.trendingrepo.ScreenView

interface MainScreenView : ScreenView<MainUiState>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.edwnmrtnz.trendingrepo.ui

data class MainUiState(
val isLoading: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.edwnmrtnz.trendingrepo.ui

import com.edwnmrtnz.trendingrepo.StatefulPresenter
import com.edwnmrtnz.trendingrepo.TestView
import com.github.amaterasu.localtest.CoroutineTestRule
import com.google.common.truth.Truth
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class MainPresenterTest {

internal class FakeView : MainScreenView, TestView<MainUiState>()
private lateinit var presenter: MainPresenter
private lateinit var view: FakeView

@get:Rule
val coroutineTestRule = CoroutineTestRule()

@Before
fun setup() {
StatefulPresenter.setScope(coroutineTestRule.scope)
presenter = MainPresenter()
view = FakeView()
}

@Test
fun `initial state must be loading`() = runBlocking {
presenter.bind(view)

Truth.assertThat(view.first().isLoading).isTrue()
}
}

0 comments on commit 80ec150

Please sign in to comment.