-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1474: PPO Message creator navigation (#2059)
- Loading branch information
1 parent
2342c96
commit 207fb92
Showing
7 changed files
with
175 additions
and
6 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
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
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
74 changes: 74 additions & 0 deletions
74
...tarter/features/pledgedprojectsoverview/viewmodel/PledgedProjectsOverviewViewModelTest.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,74 @@ | ||
package com.kickstarter.features.pledgedprojectsoverview.viewmodel | ||
|
||
import com.kickstarter.KSRobolectricTestCase | ||
import com.kickstarter.R | ||
import com.kickstarter.mock.factories.ProjectFactory | ||
import com.kickstarter.mock.services.MockApolloClientV2 | ||
import com.kickstarter.models.Project | ||
import io.reactivex.Observable | ||
import kotlinx.coroutines.flow.toList | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() { | ||
|
||
private lateinit var viewModel: PledgedProjectsOverviewViewModel | ||
|
||
@Before | ||
fun setUpEnvrionment() { | ||
viewModel = PledgedProjectsOverviewViewModel.Factory(environment = environment()) | ||
.create(PledgedProjectsOverviewViewModel::class.java) | ||
} | ||
|
||
@Test | ||
fun `emits_project_when_message_creator_called`() = | ||
runTest { | ||
val projectState = mutableListOf<Project>() | ||
|
||
val project = ProjectFactory.successfulProject() | ||
viewModel = PledgedProjectsOverviewViewModel.Factory( | ||
environment = environment().toBuilder() | ||
.apolloClientV2(object : MockApolloClientV2() { | ||
override fun getProject(slug: String): Observable<Project> { | ||
return Observable.just(project) | ||
} | ||
}).build() | ||
).create(PledgedProjectsOverviewViewModel::class.java) | ||
|
||
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) { | ||
viewModel.projectFlow.toList(projectState) | ||
} | ||
viewModel.onMessageCreatorClicked("test_project_slug") | ||
|
||
assertEquals( | ||
projectState.last(), | ||
project | ||
) | ||
} | ||
|
||
@Test | ||
fun `emits_error_when_message_creator_called`() = | ||
runTest { | ||
var snackbarAction = 0 | ||
viewModel = PledgedProjectsOverviewViewModel.Factory( | ||
environment = environment().toBuilder() | ||
.apolloClientV2(object : MockApolloClientV2() { | ||
override fun getProject(slug: String): Observable<Project> { | ||
return Observable.error(Throwable("error")) | ||
} | ||
}).build() | ||
).create(PledgedProjectsOverviewViewModel::class.java) | ||
|
||
viewModel.provideSnackbarMessage { snackbarAction = it } | ||
viewModel.onMessageCreatorClicked("test_project_slug") | ||
|
||
// Should equal error string id | ||
assertEquals( | ||
snackbarAction, | ||
R.string.Something_went_wrong_please_try_again | ||
) | ||
} | ||
} |