diff --git a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt index b1b4674e28..5051b7c8eb 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt @@ -68,6 +68,7 @@ import com.kickstarter.ui.data.ActivityResult.Companion.create import com.kickstarter.ui.data.CheckoutData import com.kickstarter.ui.data.LoginReason import com.kickstarter.ui.data.PledgeData +import com.kickstarter.ui.data.PledgeFlowContext import com.kickstarter.ui.data.PledgeReason import com.kickstarter.ui.data.ProjectData import com.kickstarter.ui.extensions.finishWithAnimation @@ -103,6 +104,7 @@ import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.launch import timber.log.Timber +import type.CreditCardPaymentType class ProjectPageActivity : AppCompatActivity(), @@ -503,6 +505,7 @@ class ProjectPageActivity : val indexOfBackedReward = rewardSelectionUIState.initialRewardIndex val rewardsList = rewardSelectionUIState.rewardList val showRewardCarouselAlertDialog = rewardSelectionUIState.showAlertDialog + val selectedReward = rewardSelectionUIState.selectedReward rewardsSelectionViewModel.sendEvent(expanded, currentPage, projectData) LaunchedEffect(Unit) { @@ -622,7 +625,6 @@ class ProjectPageActivity : } } - var selectedReward: Reward? = null ProjectPledgeButtonAndFragmentContainer( expanded = expanded, onContinueClicked = { checkoutFlowViewModel.onBackThisProjectClicked() }, @@ -650,7 +652,6 @@ class ProjectPageActivity : addOns = addOns, project = projectData.project(), onRewardSelected = { reward -> - selectedReward = reward checkoutFlowViewModel.userRewardSelection(reward) addOnsViewModel.userRewardSelection(reward) rewardsSelectionViewModel.onUserRewardSelection(reward) @@ -697,6 +698,28 @@ class ProjectPageActivity : latePledgeCheckoutViewModel.onAddNewCardClicked(project = projectData.project(), totalAmount = totalAmount) } ) + + val successfulPledge = latePledgeCheckoutViewModel.onPledgeSuccess.collectAsStateWithLifecycle(initialValue = false).value + + LaunchedEffect(successfulPledge) { + if (successfulPledge) { + latePledgeCheckoutViewModel.onPledgeSuccess.collect { + val checkoutData = CheckoutData.builder() + .amount(totalAmount) + .id(checkoutPayment.id) + .paymentType(CreditCardPaymentType.CREDIT_CARD) + .bonusAmount(totalBonusSupportAmount) + .shippingAmount(shippingAmount) + .build() + val pledgeData = PledgeData.with(PledgeFlowContext.forPledgeReason(PledgeReason.PLEDGE), projectData, selectedReward) + showCreatePledgeSuccess(Pair(checkoutData, pledgeData), userEmail) + checkoutFlowViewModel.onProjectSuccess() + refreshProject() + binding.pledgeContainerCompose.isGone = true + binding.pledgeContainerLayout.pledgeContainerRoot.isGone = false + } + } + } } } } @@ -1042,13 +1065,17 @@ class ProjectPageActivity : showSnackbar(binding.snackbarAnchor, getString(R.string.Youve_canceled_your_pledge)) } - private fun showCreatePledgeSuccess(checkoutDatandProjectData: Pair) { - val checkoutData = checkoutDatandProjectData.first - val pledgeData = checkoutDatandProjectData.second + private fun showCreatePledgeSuccess(checkoutDataAndProjectData: Pair, email: String = "") { + val checkoutData = checkoutDataAndProjectData.first + val pledgeData = checkoutDataAndProjectData.second val projectData = pledgeData.projectData() - if (clearFragmentBackStack()) { + + val fFLatePledge = getEnvironment()?.featureFlagClient()?.getBoolean(FlagKey.ANDROID_POST_CAMPAIGN_PLEDGES) ?: false + + if (clearFragmentBackStack() || (projectData.project().showLatePledgeFlow() && fFLatePledge)) { startActivity( Intent(this, ThanksActivity::class.java) + .putExtra(IntentKey.EMAIL, email) .putExtra(IntentKey.PROJECT, projectData.project()) .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) diff --git a/app/src/main/java/com/kickstarter/ui/adapters/ThanksAdapter.java b/app/src/main/java/com/kickstarter/ui/adapters/ThanksAdapter.java index b39d2d1617..94ab239cca 100644 --- a/app/src/main/java/com/kickstarter/ui/adapters/ThanksAdapter.java +++ b/app/src/main/java/com/kickstarter/ui/adapters/ThanksAdapter.java @@ -1,5 +1,6 @@ package com.kickstarter.ui.adapters; +import android.util.Pair; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -20,6 +21,7 @@ import java.util.Collections; + public final class ThanksAdapter extends KSAdapter { private static final int SECTION_SHARE_VIEW = 0; private static final int SECTION_RECOMMENDED_PROJECTS_VIEW = 1; @@ -60,7 +62,7 @@ public ThanksAdapter(final @NonNull Delegate delegate) { } public void takeData(final @NonNull ThanksData data) { - setSection(SECTION_SHARE_VIEW, Collections.singletonList(data.getBackedProject())); + setSection(SECTION_SHARE_VIEW, Collections.singletonList(Pair.create(Pair.create(data.getBackedProject(), data.getCheckoutData()), data.getUserEmail()))); setSection(SECTION_RECOMMENDED_PROJECTS_VIEW, data.getRecommendedProjects()); setSection(SECTION_CATEGORY_VIEW, Collections.singletonList(data.getCategory())); notifyDataSetChanged(); diff --git a/app/src/main/java/com/kickstarter/ui/adapters/data/ThanksData.kt b/app/src/main/java/com/kickstarter/ui/adapters/data/ThanksData.kt index 14cc161767..827c14d621 100644 --- a/app/src/main/java/com/kickstarter/ui/adapters/data/ThanksData.kt +++ b/app/src/main/java/com/kickstarter/ui/adapters/data/ThanksData.kt @@ -4,9 +4,12 @@ import android.util.Pair import com.kickstarter.models.Category import com.kickstarter.models.Project import com.kickstarter.services.DiscoveryParams +import com.kickstarter.ui.data.CheckoutData class ThanksData( val backedProject: Project, + val checkoutData: CheckoutData, + val userEmail: String, val category: Category, val recommendedProjects: List> ) diff --git a/app/src/main/java/com/kickstarter/ui/viewholders/ThanksShareViewHolder.kt b/app/src/main/java/com/kickstarter/ui/viewholders/ThanksShareViewHolder.kt index dc4c4768e3..c7166201d0 100644 --- a/app/src/main/java/com/kickstarter/ui/viewholders/ThanksShareViewHolder.kt +++ b/app/src/main/java/com/kickstarter/ui/viewholders/ThanksShareViewHolder.kt @@ -12,13 +12,16 @@ import com.kickstarter.databinding.ThanksShareViewBinding import com.kickstarter.libs.TweetComposer import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.models.Project +import com.kickstarter.ui.data.CheckoutData import com.kickstarter.viewmodels.ThanksShareHolderViewModel import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable +import java.math.RoundingMode class ThanksShareViewHolder(private val binding: ThanksShareViewBinding) : KSViewHolder(binding.root) { - private val viewModel = ThanksShareHolderViewModel.ThanksShareViewHolderViewModel() + private val viewModel = ThanksShareHolderViewModel.ThanksShareViewHolderViewModel(environment()) private val ksString = requireNotNull(environment().ksString()) + private var ksCurrency = requireNotNull(environment().ksCurrency()) private val shareDialog: ShareDialog = ShareDialog(context() as Activity) private var disposables = CompositeDisposable() @@ -28,6 +31,11 @@ class ThanksShareViewHolder(private val binding: ThanksShareViewBinding) : KSVie .subscribe { showBackedProject(it) } .addToDisposable(disposables) + viewModel.outputs.postCampaignPledgeText() + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { showPostCampaignPledgeText(it) } + .addToDisposable(disposables) + viewModel.outputs.startShare() .observeOn(AndroidSchedulers.mainThread()) .subscribe { startShare(it) } @@ -68,8 +76,8 @@ class ThanksShareViewHolder(private val binding: ThanksShareViewBinding) : KSVie @Throws(Exception::class) override fun bindData(data: Any?) { - val project = requireNotNull(data as Project?) - viewModel.inputs.configureWith(project) + val projectAndCheckoutData = requireNotNull(data as Pair, String>?) + viewModel.inputs.configureWith(projectAndCheckoutData) } private fun shareString(projectName: String): String { @@ -80,6 +88,10 @@ class ThanksShareViewHolder(private val binding: ThanksShareViewBinding) : KSVie binding.backedProject.text = Html.fromHtml(ksString.format(context().getString(R.string.You_have_successfully_backed_project_html), "project_name", projectName)) } + private fun showPostCampaignPledgeText(pcptext: Triple) { + binding.backedProject.text = Html.fromHtml(ksString.format(context().getString(R.string.You_have_successfully_pledged_to_project_post_campaign_html), "project_name", pcptext.first.name(), "pledge_total", ksCurrency.format(initialValue = pcptext.second, project = pcptext.first, roundingMode = RoundingMode.HALF_UP), "user_email", pcptext.third)) + } + private fun startShare(projectNameAndShareUrl: Pair) { val projectName = projectNameAndShareUrl.first val shareUrl = projectNameAndShareUrl.second diff --git a/app/src/main/java/com/kickstarter/viewmodels/ThanksShareHolderViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/ThanksShareHolderViewModel.kt index 7132e37922..77838bc15c 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/ThanksShareHolderViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/ThanksShareHolderViewModel.kt @@ -1,13 +1,17 @@ package com.kickstarter.viewmodels import android.util.Pair +import com.kickstarter.libs.Environment import com.kickstarter.libs.RefTag.Companion.thanksFacebookShare import com.kickstarter.libs.RefTag.Companion.thanksShare import com.kickstarter.libs.RefTag.Companion.thanksTwitterShare import com.kickstarter.libs.rx.transformers.Transformers import com.kickstarter.libs.utils.UrlUtils.appendRefTag import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.isFalse +import com.kickstarter.libs.utils.extensions.isTrue import com.kickstarter.models.Project +import com.kickstarter.ui.data.CheckoutData import io.reactivex.Observable import io.reactivex.disposables.CompositeDisposable import io.reactivex.subjects.BehaviorSubject @@ -16,7 +20,7 @@ import io.reactivex.subjects.PublishSubject interface ThanksShareHolderViewModel { interface Inputs { /** Call to configure the view model with a project. */ - fun configureWith(project: Project) + fun configureWith(thanksShareData: Pair, String>) /** Call when the share button is clicked. */ fun shareClick() @@ -42,10 +46,13 @@ interface ThanksShareHolderViewModel { /** Emits the project name and url to share using Twitter. */ fun startShareOnTwitter(): Observable> + + fun postCampaignPledgeText(): Observable> } - class ThanksShareViewHolderViewModel : Inputs, Outputs { + class ThanksShareViewHolderViewModel(environment: Environment) : Inputs, Outputs { + private val thanksShareData = PublishSubject.create, String>>() private val project = PublishSubject.create() private val shareClick = PublishSubject.create() private val shareOnFacebookClick = PublishSubject.create() @@ -54,6 +61,7 @@ interface ThanksShareHolderViewModel { private val startShare = PublishSubject.create>() private val startShareOnFacebook = PublishSubject.create>() private val startShareOnTwitter = PublishSubject.create>() + private val postCampaignText = PublishSubject.create>() val inputs: Inputs = this val outputs: Outputs = this @@ -61,11 +69,25 @@ interface ThanksShareHolderViewModel { private var disposables = CompositeDisposable() init { - project - .map { it.name() } + thanksShareData + .map { it.first } + .subscribe { project.onNext(it.first) } + .addToDisposable(disposables) + + thanksShareData + .filter { it.first.first.isInPostCampaignPledgingPhase().isFalse() } + .filter { it.first.first.postCampaignPledgingEnabled().isFalse() } + .map { it.first.first.name() } .subscribe { projectName.onNext(it) } .addToDisposable(disposables) + thanksShareData + .filter { it.first.first.isInPostCampaignPledgingPhase().isTrue() } + .filter { it.first.first.postCampaignPledgingEnabled().isTrue() } + .subscribe { + postCampaignText.onNext(Triple(it.first.first, it.first.second.amount(), it.second)) + } + .addToDisposable(disposables) project .map { Pair.create( @@ -100,8 +122,8 @@ interface ThanksShareHolderViewModel { .addToDisposable(disposables) } - override fun configureWith(project: Project) { - this.project.onNext(project) + override fun configureWith(thanksShareData: Pair, String>) { + this.thanksShareData.onNext(thanksShareData) } override fun shareClick() { @@ -121,6 +143,7 @@ interface ThanksShareHolderViewModel { override fun startShareOnTwitter(): Observable> = startShareOnTwitter override fun projectName(): Observable = projectName + override fun postCampaignPledgeText(): Observable> = postCampaignText override fun onCleared() { disposables.clear() } diff --git a/app/src/main/java/com/kickstarter/viewmodels/ThanksViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/ThanksViewModel.kt index 4dc0e09eb9..4d8799ab4f 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/ThanksViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/ThanksViewModel.kt @@ -127,6 +127,12 @@ interface ThanksViewModel { .ofType(Project::class.java) .take(1) + val userEmail = intent() + .filter { it.getStringExtra(IntentKey.EMAIL).isNotNull() } + .map { it.getStringExtra(IntentKey.EMAIL) } + .ofType(String::class.java) + .take(1) + val rootCategory = project .switchMap { rootCategory(it, apolloClient) @@ -193,28 +199,6 @@ interface ThanksViewModel { ) } - Observable.combineLatest( - project, - rootCategory, - recommendedProjects.startWith(listOf()) - ) { backedProject, category, projects -> - ThanksData(backedProject, category, projects) - }.subscribe { adapterData.onNext(it) } - .addToDisposable(disposables) - - adapterData - .compose(Transformers.takePairWhenV2(projectOnUserChangeSave)) - .map { - Pair(it.first, it.second.updateStartedProjectAndDiscoveryParamsList(it.first.recommendedProjects)) - } - .map { - ThanksData(it.first.backedProject, it.first.category, it.second) - }.distinctUntilChanged() - .subscribe { - adapterData.onNext(it) - } - .addToDisposable(disposables) - projectOnUserChangeSave .subscribe { this.analyticEvents?.trackWatchProjectCTA(it, THANKS) } .addToDisposable(disposables) @@ -289,6 +273,30 @@ interface ThanksViewModel { } .addToDisposable(disposables) + Observable.combineLatest( + project, + rootCategory, + recommendedProjects.startWith(listOf()), + checkoutData, + userEmail + ) { backedProject, category, projects, checkoutData, email -> + ThanksData(backedProject, checkoutData, email, category, projects) + }.subscribe { adapterData.onNext(it) } + .addToDisposable(disposables) + + adapterData + .compose(Transformers.takePairWhenV2(projectOnUserChangeSave)) + .withLatestFrom(userEmail) { adapterAndProjectData, email -> + Triple(adapterAndProjectData.first, adapterAndProjectData.second.updateStartedProjectAndDiscoveryParamsList(adapterAndProjectData.first.recommendedProjects), email) + } + .map { + ThanksData(it.first.backedProject, it.first.checkoutData, it.third, it.first.category, it.second) + }.distinctUntilChanged() + .subscribe { + adapterData.onNext(it) + } + .addToDisposable(disposables) + SendThirdPartyEventUseCaseV2(sharedPreferences, ffClient) .sendThirdPartyEvent( project = project, diff --git a/app/src/main/java/com/kickstarter/viewmodels/projectpage/CheckoutFlowViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/projectpage/CheckoutFlowViewModel.kt index 91aac56cee..4fdaa4f5de 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/projectpage/CheckoutFlowViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/projectpage/CheckoutFlowViewModel.kt @@ -107,6 +107,13 @@ class CheckoutFlowViewModel(val environment: Environment) : ViewModel() { } } + fun onProjectSuccess() { + viewModelScope.launch { + // Open Flow + mutableFlowUIState.emit(FlowUIState(currentPage = 0, expanded = false)) + } + } + class Factory(private val environment: Environment) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { diff --git a/app/src/main/java/com/kickstarter/viewmodels/projectpage/LatePledgeCheckoutViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/projectpage/LatePledgeCheckoutViewModel.kt index f8368eebce..a8c457246d 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/projectpage/LatePledgeCheckoutViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/projectpage/LatePledgeCheckoutViewModel.kt @@ -60,6 +60,17 @@ class LatePledgeCheckoutViewModel(val environment: Environment) : ViewModel() { private var selectedReward: Reward? = null private var mutableLatePledgeCheckoutUIState = MutableStateFlow(LatePledgeCheckoutUIState()) + + private var mutableOnPledgeSuccessAction = MutableSharedFlow() + val onPledgeSuccess: SharedFlow + get() = mutableOnPledgeSuccessAction + .asSharedFlow() + .stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(), + initialValue = false + ) + val latePledgeCheckoutUIState: StateFlow get() = mutableLatePledgeCheckoutUIState .asStateFlow() @@ -263,7 +274,7 @@ class LatePledgeCheckoutViewModel(val environment: Environment) : ViewModel() { if (iDRequiresActionPair.second) { mutablePaymentRequiresAction.emit(clientSecret) } else { - // Go to Thanks Page, full complete flow + mutableOnPledgeSuccessAction.emit(true) } }.onCompletion { emitCurrentState() diff --git a/app/src/main/java/com/kickstarter/viewmodels/projectpage/RewardsSelectionViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/projectpage/RewardsSelectionViewModel.kt index 68a0ecd72a..b547ba613c 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/projectpage/RewardsSelectionViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/projectpage/RewardsSelectionViewModel.kt @@ -27,6 +27,7 @@ import java.util.Locale data class RewardSelectionUIState( val rewardList: List = listOf(), + val selectedReward: Reward = Reward.builder().build(), val initialRewardIndex: Int = 0, val project: ProjectData = ProjectData.builder().build(), val showAlertDialog: Boolean = false @@ -38,8 +39,8 @@ class RewardsSelectionViewModel(environment: Environment) : ViewModel() { private lateinit var currentProjectData: ProjectData private var previousUserBacking: Backing? = null private var previouslyBackedReward: Reward? = null - private lateinit var newUserReward: Reward private var indexOfBackedReward = 0 + private var newUserReward: Reward = Reward.builder().build() private val mutableRewardSelectionUIState = MutableStateFlow(RewardSelectionUIState()) val rewardSelectionUIState: StateFlow diff --git a/app/src/test/java/com/kickstarter/viewmodels/ThanksShareHolderViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ThanksShareHolderViewModelTest.kt index 1ca2065c42..fb5c0be063 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ThanksShareHolderViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ThanksShareHolderViewModelTest.kt @@ -3,6 +3,7 @@ package com.kickstarter.viewmodels import android.util.Pair import com.kickstarter.KSRobolectricTestCase import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.mock.factories.CheckoutDataFactory import com.kickstarter.mock.factories.ProjectFactory.project import com.kickstarter.mock.factories.UserFactory.creator import com.kickstarter.models.Project @@ -20,16 +21,19 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { private val startShare = TestSubscriber>() private val startShareOnFacebook = TestSubscriber>() private val startShareOnTwitter = TestSubscriber>() + private val postCampaignText = TestSubscriber>() private val disposables = CompositeDisposable() private fun setUpEnvironment() { - vm = ThanksShareHolderViewModel.ThanksShareViewHolderViewModel() + vm = ThanksShareHolderViewModel.ThanksShareViewHolderViewModel(environment()) vm.outputs.projectName().subscribe { projectName.onNext(it) }.addToDisposable(disposables) vm.outputs.startShare().subscribe { startShare.onNext(it) }.addToDisposable(disposables) vm.outputs.startShareOnFacebook().subscribe { startShareOnFacebook.onNext(it) } .addToDisposable(disposables) vm.outputs.startShareOnTwitter().subscribe { startShareOnTwitter.onNext(it) } .addToDisposable(disposables) + vm.outputs.postCampaignPledgeText().subscribe { postCampaignText.onNext(it) } + .addToDisposable(disposables) } @Test @@ -37,7 +41,12 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { val project = project() setUpEnvironment() - vm.configureWith(project) + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "")) projectName.assertValues(project.name()) } @@ -47,8 +56,12 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { setUpEnvironment() val project = setUpProjectWithWebUrls() - - vm.configureWith(project) + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "")) vm.inputs.shareClick() val expectedShareUrl = "https://www.kck.str/projects/15/best-project-2k19?ref=android_thanks_share" @@ -61,7 +74,14 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { setUpEnvironment() val project = setUpProjectWithWebUrls() - vm.configureWith(project) + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + + vm.configureWith(Pair(Pair(project, checkoutData), "")) + vm.inputs.shareOnFacebookClick() val expectedShareUrl = "https://www.kck.str/projects/15/best-project-2k19?ref=android_thanks_facebook_share" @@ -74,7 +94,12 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { setUpEnvironment() val project = setUpProjectWithWebUrls() - vm.configureWith(project) + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "")) vm.inputs.shareOnTwitterClick() val expectedShareUrl = "https://www.kck.str/projects/15/best-project-2k19?ref=android_thanks_twitter_share" @@ -82,6 +107,54 @@ class ThanksShareHolderViewModelTest : KSRobolectricTestCase() { startShareOnTwitter.assertValue(Pair.create("Best Project 2K19", expectedShareUrl)) } + @Test + fun testShowLatePledges_whenTrue_ShowLatePledgeFlow() { + setUpEnvironment() + + val project = setUpProjectWithWebUrls().toBuilder().isInPostCampaignPledgingPhase(true).postCampaignPledgingEnabled(true).build() + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "email@email.com")) + + postCampaignText.assertValue(Triple(project, checkoutData.amount(), "email@email.com")) + projectName.assertNoValues() + } + + @Test + fun testShowLatePledges_whenFalse_noEmission() { + setUpEnvironment() + + val project = setUpProjectWithWebUrls().toBuilder().isInPostCampaignPledgingPhase(false).postCampaignPledgingEnabled(false).build() + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "email@email.com")) + + postCampaignText.assertNoValues() + projectName.assertValue(project.name()) + } + + @Test + fun testShowLatePledges_whenNull_noEmission() { + setUpEnvironment() + + val project = setUpProjectWithWebUrls().toBuilder().isInPostCampaignPledgingPhase(null).postCampaignPledgingEnabled(null).build() + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + vm.configureWith(Pair(Pair(project, checkoutData), "email@email.com")) + + postCampaignText.assertNoValues() + projectName.assertValue(project.name()) + } + private fun setUpProjectWithWebUrls(): Project { val creatorId = 15L val creator = creator() diff --git a/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt index b567f4e39a..5882599ebc 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt @@ -20,6 +20,7 @@ import com.kickstarter.mock.factories.CategoryFactory.artCategory import com.kickstarter.mock.factories.CategoryFactory.category import com.kickstarter.mock.factories.CategoryFactory.ceramicsCategory import com.kickstarter.mock.factories.CategoryFactory.tabletopGamesCategory +import com.kickstarter.mock.factories.CheckoutDataFactory import com.kickstarter.mock.factories.CheckoutDataFactory.checkoutData import com.kickstarter.mock.factories.LocationFactory.germany import com.kickstarter.mock.factories.ProjectDataFactory.project @@ -95,7 +96,19 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .toBuilder() .category(artCategory()) .build() - setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project)) + + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + + setUpEnvironment( + intent = Intent() + .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) + .putExtra(IntentKey.EMAIL, "email@email.com") + ) adapterData.assertValueCount(1) vm.inputs.onHeartButtonClicked(project) @@ -111,7 +124,18 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .category(artCategory()) .build() - setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project)) + val checkoutData = CheckoutDataFactory.checkoutData( + 3L, + 20.0, + 30.0 + ) + + setUpEnvironment( + intent = Intent() + .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) + .putExtra(IntentKey.EMAIL, "email@email.com") + ) adapterData.assertValueCount(1) }