From 48eb734e558d5ccc0dd6523822350951928d3e3a Mon Sep 17 00:00:00 2001 From: jlplks Date: Mon, 18 Nov 2024 11:08:41 -0700 Subject: [PATCH] MLB -1798: Added plot selected badge to PledgeItemizedDetails (#2166) * Added plot selected badge to PledgeItemizedDetails - added plotSelected prop, created component, added tests and added previews * fix * added 'false' default value for plotSelected --------- Co-authored-by: Isabel Martin Co-authored-by: Leigh Douglas --- .../compose/projectpage/CheckoutScreen.kt | 6 +- .../compose/checkout/PledgeItemizedDetails.kt | 69 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + .../compose/PledgeItemizedDetailsTest.kt | 54 ++++++++++++--- 4 files changed, 119 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt index 5c4d352e17..784c233d47 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt @@ -489,7 +489,8 @@ fun CheckoutScreen( totalBonusSupport = totalBonusSupportString, deliveryDateString = deliveryDateString, rewardsHaveShippables = rewardsHaveShippables, - disclaimerText = disclaimerText + disclaimerText = disclaimerText, + plotSelected = false ) } else { // - For noReward, totalAmount = bonusAmount as there is no reward @@ -499,7 +500,8 @@ fun CheckoutScreen( initialBonusSupport = initialBonusSupportString, totalBonusSupport = totalAmountString, shippingAmount = shippingAmount, - disclaimerText = disclaimerText + disclaimerText = disclaimerText, + plotSelected = false ) } diff --git a/app/src/main/java/com/kickstarter/ui/views/compose/checkout/PledgeItemizedDetails.kt b/app/src/main/java/com/kickstarter/ui/views/compose/checkout/PledgeItemizedDetails.kt index 3903fbca1c..6602c5e126 100644 --- a/app/src/main/java/com/kickstarter/ui/views/compose/checkout/PledgeItemizedDetails.kt +++ b/app/src/main/java/com/kickstarter/ui/views/compose/checkout/PledgeItemizedDetails.kt @@ -2,12 +2,15 @@ package com.kickstarter.ui.views.compose.checkout import android.content.res.Configuration import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -39,6 +42,7 @@ fun ItemizedContainerForNoRewardPreview() { initialBonusSupport = "US$ 0", totalBonusSupport = "US$ 1", shippingAmount = -1.0, + plotSelected = false ) } } @@ -66,12 +70,34 @@ fun ItemizedRewardListContainerPreview() { totalBonusSupport = "0", deliveryDateString = "", rewardsHaveShippables = false, + plotSelected = false, disclaimerText = stringResource(id = R.string.If_the_project_reaches_its_funding_goal_you_will_be_charged_total_on_project_deadline_and_receive_proof_of_pledge) ) } } } +@Preview(name = "Light", uiMode = Configuration.UI_MODE_NIGHT_NO) +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +fun ItemizedContainerForNoRewardPlotSelectedPreview() { + KSTheme { + Scaffold( + backgroundColor = KSTheme.colors.backgroundAccentGraySubtle + ) { padding -> + ItemizedRewardListContainer( + modifier = Modifier.padding(paddingValues = padding), + totalAmount = "US$ 1", + totalAmountCurrencyConverted = "About CA$ 1.38", + initialBonusSupport = "US$ 0", + totalBonusSupport = "US$ 1", + shippingAmount = -1.0, + plotSelected = true + ) + } + } +} + enum class PledgeItemizedDetailsTestTag { DELIVERY_DATE, PAGE_TITLE, @@ -85,6 +111,7 @@ enum class PledgeItemizedDetailsTestTag { SHIPPING_TITLE, SHIPPING_AMOUNT, CURRENCY_CONVERSION, + PLOT_SELECTED_BADGE, } @Composable @@ -101,7 +128,8 @@ fun ItemizedRewardListContainer( totalBonusSupport: String, deliveryDateString: String = "", rewardsHaveShippables: Boolean = false, - disclaimerText: String = "" + disclaimerText: String = "", + plotSelected: Boolean = false ) { Column( modifier = Modifier @@ -255,6 +283,45 @@ fun ItemizedRewardListContainer( } } + if (plotSelected) { + Spacer(modifier = Modifier.height(dimensions.paddingMedium)) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.fillMaxWidth() + ) { + + Box( + modifier = modifier + .background( + color = colors.kds_create_700.copy(alpha = 0.2f), + shape = RoundedCornerShape(dimensions.radiusSmall) + ) + .padding( + start = dimensions.paddingSmall, + end = dimensions.paddingSmall, + top = dimensions.paddingXSmall, + bottom = dimensions.paddingXSmall, + ) + ) { + Text( + modifier = Modifier.testTag(PledgeItemizedDetailsTestTag.PLOT_SELECTED_BADGE.name), + text = stringResource( + id = R.string.fpo_pledge_over_time + ), + style = typography.body2Medium, + color = colors.kds_create_700 + ) + } + Text( + modifier = Modifier.testTag(PledgeItemizedDetailsTestTag.DISCLAIMER_TEXT.name), + text = stringResource(id = R.string.fpo_charged_as_4_payments), + style = typography.footnote, + color = colors.textPrimary + ) + } + } + if (disclaimerText.isNotEmpty()) { Spacer(modifier = Modifier.height(dimensions.paddingMedium)) Row { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74acb636df..fc8ee6505f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -98,4 +98,5 @@ See our Terms of Use You will be charged for your pledge over four payments, at no extra cost. The first charge will be 24 hours after the project ends successfully, then every 2 weeks until fully paid. When this option is selected no further edits can be made to your pledge. + Charged as 4 payments diff --git a/app/src/test/java/com/kickstarter/ui/activities/compose/PledgeItemizedDetailsTest.kt b/app/src/test/java/com/kickstarter/ui/activities/compose/PledgeItemizedDetailsTest.kt index 2a91579d1f..ae52504f90 100644 --- a/app/src/test/java/com/kickstarter/ui/activities/compose/PledgeItemizedDetailsTest.kt +++ b/app/src/test/java/com/kickstarter/ui/activities/compose/PledgeItemizedDetailsTest.kt @@ -45,6 +45,9 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { private val currencyConversion = composeTestRule.onNodeWithTag(PledgeItemizedDetailsTestTag.CURRENCY_CONVERSION.name) + private val plotSelectedBadge = + composeTestRule.onNodeWithTag(PledgeItemizedDetailsTestTag.PLOT_SELECTED_BADGE.name) + @Test fun `test view init`() { val rewardsList = listOf(Pair("T-shirt", "$22"), Pair("Pin", "$10")) @@ -63,7 +66,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "0", deliveryDateString = "", rewardsHaveShippables = false, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } @@ -114,7 +118,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "", rewardsHaveShippables = false, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } @@ -144,7 +149,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "", rewardsHaveShippables = false, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } @@ -174,7 +180,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "", rewardsHaveShippables = true, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } @@ -202,7 +209,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "", rewardsHaveShippables = true, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } @@ -214,7 +222,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { @Test fun `test disclaimer, when disclaimer not null, should show disclaimer text`() { val rewardsList = listOf(Pair("T-shirt", "$22"), Pair("Pin", "$10")) - val disclaimer = context.getString(R.string.If_the_project_reaches_its_funding_goal_you_will_be_charged_total_on_project_deadline_and_receive_proof_of_pledge) + val disclaimer = + context.getString(R.string.If_the_project_reaches_its_funding_goal_you_will_be_charged_total_on_project_deadline_and_receive_proof_of_pledge) composeTestRule.setContent { KSTheme { @@ -230,7 +239,8 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "", rewardsHaveShippables = true, - disclaimerText = disclaimer + disclaimerText = disclaimer, + plotSelected = false ) } } @@ -256,11 +266,39 @@ class PledgeItemizedDetailsTest : KSRobolectricTestCase() { totalBonusSupport = "10", deliveryDateString = "April 10", rewardsHaveShippables = true, - disclaimerText = "" + disclaimerText = "", + plotSelected = false ) } } deliveryDate.assertIsDisplayed() deliveryDate.assertTextEquals("April 10") } + + @Test + fun `test plot selected, when plot selected should show plot selected badge`() { + val rewardsList = listOf(Pair("T-shirt", "$22"), Pair("Pin", "$10")) + + composeTestRule.setContent { + KSTheme { + ItemizedRewardListContainer( + ksString = null, + rewardsList = rewardsList, + shippingAmount = 20.0, + shippingAmountString = "$20.0", + initialShippingLocation = "USA", + totalAmount = "50$", + totalAmountCurrencyConverted = "About CA\$ 1.38", + initialBonusSupport = "1", + totalBonusSupport = "10", + deliveryDateString = "April 10", + rewardsHaveShippables = true, + disclaimerText = "", + plotSelected = true + ) + } + } + plotSelectedBadge.assertIsDisplayed() + plotSelectedBadge.assertTextEquals(context.getString(R.string.fpo_pledge_over_time)) + } }