-
Notifications
You must be signed in to change notification settings - Fork 1
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
Guillaume M
committed
Jun 24, 2019
1 parent
0ef2a2a
commit bc9ef93
Showing
6 changed files
with
172 additions
and
7 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
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
13 changes: 13 additions & 0 deletions
13
home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoApplicationTest.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,13 @@ | ||
package io.freshdroid.mymonzo.home | ||
|
||
import io.freshdroid.mymonzo.MyMonzoApplication | ||
|
||
internal class MyMonzoApplicationTest : MyMonzoApplication() { | ||
|
||
override fun isInUnitTests(): Boolean = true | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
home/src/test/java/io/freshdroid/mymonzo/home/MyMonzoRobolectricTestCase.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,41 @@ | ||
package io.freshdroid.mymonzo.home | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider | ||
import com.uber.autodispose.android.lifecycle.test.TestLifecycleOwner | ||
import io.freshdroid.mymonzo.core.di.CoreComponent | ||
import junit.framework.TestCase | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(application = MyMonzoApplicationTest::class) | ||
internal abstract class MyMonzoRobolectricTestCase : TestCase() { | ||
|
||
private var mApplication: MyMonzoApplicationTest? = null | ||
|
||
protected fun application(): MyMonzoApplicationTest { | ||
if (mApplication != null) { | ||
return mApplication as MyMonzoApplicationTest | ||
} | ||
|
||
mApplication = ApplicationProvider.getApplicationContext() as MyMonzoApplicationTest | ||
return mApplication as MyMonzoApplicationTest | ||
} | ||
|
||
protected fun context(): Context { | ||
return application().applicationContext | ||
} | ||
|
||
protected fun coreComponent(): CoreComponent { | ||
return application().coreComponent() | ||
} | ||
|
||
protected fun scopeProvider(): AndroidLifecycleScopeProvider { | ||
val testLifecycleOwner = TestLifecycleOwner.create() | ||
return AndroidLifecycleScopeProvider.from(testLifecycleOwner) | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
home/src/test/java/io/freshdroid/mymonzo/home/viewmodels/HomeViewModelTest.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,104 @@ | ||
package io.freshdroid.mymonzo.home.viewmodels | ||
|
||
import android.content.Intent | ||
import io.freshdroid.mymonzo.home.MyMonzoRobolectricTestCase | ||
import io.freshdroid.mymonzo.home.views.FragmentState | ||
import io.freshdroid.mymonzo.navigation.Activities | ||
import io.reactivex.subscribers.TestSubscriber | ||
import org.junit.Test | ||
|
||
internal class HomeViewModelTest : MyMonzoRobolectricTestCase() { | ||
|
||
@Test | ||
fun testDisplaySelectedFragment_feed() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val displaySelectedFragment = TestSubscriber<FragmentState>() | ||
vm.outputs.displaySelectedFragment().subscribe(displaySelectedFragment::onNext) | ||
|
||
vm.inputs.onFeedClick() | ||
displaySelectedFragment.assertValue { it == FragmentState.FEED } | ||
} | ||
|
||
@Test | ||
fun testDisplaySelectedFragment_summary() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val displaySelectedFragment = TestSubscriber<FragmentState>() | ||
vm.outputs.displaySelectedFragment().subscribe(displaySelectedFragment::onNext) | ||
|
||
vm.inputs.onSummaryClick() | ||
displaySelectedFragment.assertValue { it == FragmentState.SUMMARY } | ||
} | ||
|
||
@Test | ||
fun testDisplaySelectedFragment_account() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val displaySelectedFragment = TestSubscriber<FragmentState>() | ||
vm.outputs.displaySelectedFragment().subscribe(displaySelectedFragment::onNext) | ||
|
||
vm.inputs.onAccountClick() | ||
displaySelectedFragment.assertValue { it == FragmentState.ACCOUNT } | ||
} | ||
|
||
@Test | ||
fun testDisplaySelectedFragment_help() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val displaySelectedFragment = TestSubscriber<FragmentState>() | ||
vm.outputs.displaySelectedFragment().subscribe(displaySelectedFragment::onNext) | ||
|
||
vm.inputs.onHelpClick() | ||
displaySelectedFragment.assertValue { it == FragmentState.HELP } | ||
} | ||
|
||
@Test | ||
fun testInitBottomNavigationBar_feed() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val initBottomNavigationBar = TestSubscriber<FragmentState>() | ||
vm.outputs.initBottomNavigationBar().subscribe(initBottomNavigationBar::onNext) | ||
|
||
val homeIntent = Intent() | ||
homeIntent.putExtra(Activities.Home.KEY_EXTRA_HOME_ACTIVE_TAB, FragmentState.FEED.tag) | ||
vm.intent(homeIntent) | ||
|
||
initBottomNavigationBar.assertValue { it == FragmentState.FEED } | ||
} | ||
|
||
@Test | ||
fun testInitBottomNavigationBar_summary() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val initBottomNavigationBar = TestSubscriber<FragmentState>() | ||
vm.outputs.initBottomNavigationBar().subscribe(initBottomNavigationBar::onNext) | ||
|
||
val homeIntent = Intent() | ||
homeIntent.putExtra(Activities.Home.KEY_EXTRA_HOME_ACTIVE_TAB, FragmentState.SUMMARY.tag) | ||
vm.intent(homeIntent) | ||
|
||
initBottomNavigationBar.assertValue { it == FragmentState.SUMMARY } | ||
} | ||
|
||
@Test | ||
fun testInitBottomNavigationBar_account() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val initBottomNavigationBar = TestSubscriber<FragmentState>() | ||
vm.outputs.initBottomNavigationBar().subscribe(initBottomNavigationBar::onNext) | ||
|
||
val homeIntent = Intent() | ||
homeIntent.putExtra(Activities.Home.KEY_EXTRA_HOME_ACTIVE_TAB, FragmentState.ACCOUNT.tag) | ||
vm.intent(homeIntent) | ||
|
||
initBottomNavigationBar.assertValue { it == FragmentState.ACCOUNT } | ||
} | ||
|
||
@Test | ||
fun testInitBottomNavigationBar_help() { | ||
val vm = HomeViewModel(scopeProvider()) | ||
val initBottomNavigationBar = TestSubscriber<FragmentState>() | ||
vm.outputs.initBottomNavigationBar().subscribe(initBottomNavigationBar::onNext) | ||
|
||
val homeIntent = Intent() | ||
homeIntent.putExtra(Activities.Home.KEY_EXTRA_HOME_ACTIVE_TAB, FragmentState.HELP.tag) | ||
vm.intent(homeIntent) | ||
|
||
initBottomNavigationBar.assertValue { it == FragmentState.HELP } | ||
} | ||
|
||
} |
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 @@ | ||
application=io.freshdroid.mymonzo.home.MyMonzoApplicationTest |