-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8222c37
commit 5d960c9
Showing
3 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Jul 14 15:56:55 IST 2020 | ||
#Tue Jan 25 12:20:13 IST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME |
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
99 changes: 99 additions & 0 deletions
99
ui-jokes/src/test/java/com/mutualmobile/feat/jokes/ui/joke/home/HomeVMTest.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,99 @@ | ||
package com.mutualmobile.feat.jokes.ui.joke.home | ||
|
||
import app.cash.turbine.test | ||
import com.mutualmobile.feat.jokes.ui.model.UIJokeMapper | ||
import com.mutualmobile.praxis.data.repository.JokesRepoImpl | ||
import com.mutualmobile.praxis.domain.SafeResult | ||
import com.mutualmobile.praxis.domain.model.DOMJoke | ||
import com.mutualmobile.praxis.domain.model.DOMJokeList | ||
import com.mutualmobile.praxis.domain.usecases.GetFiveRandomJokesUseCase | ||
import com.mutualmobile.praxis.navigator.ComposeNavigator | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.emptyFlow | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
@ExperimentalCoroutinesApi | ||
class HomeVMTest { | ||
|
||
private val uiJokesMapper = UIJokeMapper() | ||
|
||
@MockK | ||
private lateinit var navigator: ComposeNavigator | ||
private lateinit var getFiveRandomJokesUseCase: GetFiveRandomJokesUseCase | ||
private lateinit var homeVM: HomeVM | ||
|
||
@MockK | ||
private lateinit var jokesRepoImpl: JokesRepoImpl | ||
|
||
@Before | ||
fun setUp() { | ||
MockKAnnotations.init(this, true) | ||
Dispatchers.setMain(StandardTestDispatcher()) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
Dispatchers.resetMain() | ||
} | ||
|
||
@Test | ||
fun `test that loadJokes() completes on success response`() = runTest { | ||
|
||
// This is mocking | ||
coEvery { | ||
navigator.observeResult<String>(any()) | ||
} returns emptyFlow() | ||
|
||
coEvery { | ||
jokesRepoImpl.getFiveRandomJokes() | ||
} returns SafeResult.Success( | ||
data = DOMJokeList( | ||
type = "success", | ||
DOMJokes = listOf( | ||
DOMJoke(0, "Test Joke") | ||
) | ||
) | ||
) | ||
|
||
getFiveRandomJokesUseCase = GetFiveRandomJokesUseCase(jokesRepoImpl) | ||
|
||
homeVM = HomeVM(getFiveRandomJokesUseCase, uiJokesMapper, navigator) | ||
|
||
homeVM.viewState.test { | ||
assert(awaitItem() is HomeViewState.Loading) | ||
assert(awaitItem() is HomeViewState.ShowJokes) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test that loadJokes() fails on failed response`() = runTest { | ||
|
||
// This is mocking | ||
coEvery { | ||
navigator.observeResult<String>(any()) | ||
} returns emptyFlow() | ||
|
||
coEvery { | ||
jokesRepoImpl.getFiveRandomJokes() | ||
} returns SafeResult.Failure() | ||
|
||
getFiveRandomJokesUseCase = GetFiveRandomJokesUseCase(jokesRepoImpl) | ||
|
||
homeVM = HomeVM(getFiveRandomJokesUseCase, uiJokesMapper, navigator) | ||
|
||
homeVM.viewState.test { | ||
assert(awaitItem() is HomeViewState.Loading) | ||
assert(awaitItem() is HomeViewState.Error) | ||
} | ||
} | ||
} |