-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to verifying initial state when view binds
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/edwnmrtnz/trendingrepo/ui/MainPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/edwnmrtnz/trendingrepo/ui/MainScreenView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/edwnmrtnz/trendingrepo/ui/MainUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
34 changes: 34 additions & 0 deletions
34
app/src/test/java/com/edwnmrtnz/trendingrepo/ui/MainPresenterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |