Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Nov 19, 2024
1 parent 4ba61cf commit 521b349
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 110 deletions.
171 changes: 83 additions & 88 deletions link/src/main/java/com/stripe/android/link/ui/wallet/PaymentDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.RadioButton
import androidx.compose.material.RadioButtonDefaults
Expand Down Expand Up @@ -51,95 +50,98 @@ internal fun PaymentDetailsListItem(
onClick: () -> Unit,
onMenuButtonClick: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.defaultMinSize(minHeight = 56.dp)
.clickable(enabled = enabled, onClick = onClick),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = isSelected,
onClick = null,
modifier = Modifier.padding(start = 20.dp, end = 6.dp),
colors = RadioButtonDefaults.colors(
selectedColor = MaterialTheme.linkColors.actionLabelLight,
unselectedColor = MaterialTheme.linkColors.disabledText
)
)
Column(
Column {
Row(
modifier = Modifier
.padding(vertical = 8.dp)
.weight(1f)
.fillMaxWidth()
.defaultMinSize(minHeight = 56.dp)
.clickable(enabled = enabled, onClick = onClick),
verticalAlignment = Alignment.CenterVertically
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
RadioButton(
selected = isSelected,
onClick = null,
modifier = Modifier.padding(start = 20.dp, end = 6.dp),
colors = RadioButtonDefaults.colors(
selectedColor = MaterialTheme.linkColors.actionLabelLight,
unselectedColor = MaterialTheme.linkColors.disabledText
)
)
Column(
modifier = Modifier
.padding(vertical = 8.dp)
.weight(1f)
) {
PaymentDetails(paymentDetails = paymentDetails)
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
PaymentDetails(paymentDetails = paymentDetails)

if (paymentDetails.isDefault) {
Box(
modifier = Modifier
.background(
color = MaterialTheme.colors.secondary,
shape = MaterialTheme.linkShapes.extraSmall
),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(id = R.string.stripe_wallet_default),
modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp),
color = MaterialTheme.linkColors.disabledText,
fontSize = 12.sp,
fontWeight = FontWeight.Medium
)
if (paymentDetails.isDefault) {
Box(
modifier = Modifier
.background(
color = MaterialTheme.colors.secondary,
shape = MaterialTheme.linkShapes.extraSmall
),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(id = R.string.stripe_wallet_default),
modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp),
color = MaterialTheme.linkColors.disabledText,
fontSize = 12.sp,
fontWeight = FontWeight.Medium
)
}
}
}

val showWarning = (paymentDetails as? Card)?.isExpired ?: false
if (showWarning && !isSelected) {
Icon(
painter = painterResource(R.drawable.stripe_link_error),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.linkColors.errorText
)
val showWarning = (paymentDetails as? Card)?.isExpired ?: false
if (showWarning && !isSelected) {
Icon(
painter = painterResource(R.drawable.stripe_link_error),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.linkColors.errorText
)
}
}
}
}

Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(MinimumTouchTargetSize)
.padding(end = 12.dp)
) {
if (isUpdating) {
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
strokeWidth = 2.dp
)
} else {
IconButton(
onClick = onMenuButtonClick,
enabled = enabled
) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = stringResource(StripeR.string.stripe_edit),
tint = MaterialTheme.linkColors.actionLabelLight,
modifier = Modifier.size(24.dp)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(MinimumTouchTargetSize)
.padding(end = 12.dp)
) {
if (isUpdating) {
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
strokeWidth = 2.dp
)
} else {
IconButton(
onClick = onMenuButtonClick,
enabled = enabled
) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = stringResource(StripeR.string.stripe_edit),
tint = MaterialTheme.linkColors.actionLabelLight,
modifier = Modifier.size(24.dp)
)
}
}
}
}

TabRowDefaults.Divider(
modifier = Modifier.padding(horizontal = 20.dp),
color = MaterialTheme.linkColors.componentDivider,
thickness = 1.dp
)
}
TabRowDefaults.Divider(
modifier = Modifier.padding(horizontal = 20.dp),
color = MaterialTheme.linkColors.componentDivider,
thickness = 1.dp
)
}

@Composable
Expand Down Expand Up @@ -184,17 +186,14 @@ private fun RowScope.CardInfo(
.width(38.dp)
.padding(horizontal = 6.dp),
alignment = Alignment.Center,
alpha = LocalContentAlpha.current
)
Text(
text = "•••• ",
color = MaterialTheme.colors.onPrimary
.copy(alpha = LocalContentAlpha.current)
color = MaterialTheme.colors.onBackground
)
Text(
text = last4,
color = MaterialTheme.colors.onPrimary
.copy(alpha = LocalContentAlpha.current),
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.h6
)
}
Expand All @@ -215,29 +214,25 @@ private fun RowScope.BankAccountInfo(
.width(38.dp)
.padding(horizontal = 6.dp),
alignment = Alignment.Center,
alpha = LocalContentAlpha.current,
colorFilter = ColorFilter.tint(MaterialTheme.linkColors.actionLabelLight)
)
Column(horizontalAlignment = Alignment.Start) {
Text(
text = bankAccount.bankName ?: "Bank",
color = MaterialTheme.colors.onPrimary
.copy(alpha = LocalContentAlpha.current),
color = MaterialTheme.colors.onBackground,
overflow = TextOverflow.Ellipsis,
maxLines = 1,
style = MaterialTheme.typography.h6
)
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = "•••• ",
color = MaterialTheme.colors.onSecondary
.copy(alpha = LocalContentAlpha.current),
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.body2
)
Text(
text = bankAccount.last4,
color = MaterialTheme.colors.onSecondary
.copy(alpha = LocalContentAlpha.current),
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.body2
)
}
Expand Down
29 changes: 19 additions & 10 deletions link/src/test/java/com/stripe/android/link/TestFactory.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.stripe.android.link

import com.stripe.android.core.model.CountryCode
import com.stripe.android.link.model.LinkAccount
import com.stripe.android.link.model.StripeIntentFixtures
import com.stripe.android.model.CardBrand
import com.stripe.android.model.CardParams
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.ConsumerSession
import com.stripe.android.model.ConsumerSessionLookup
import com.stripe.android.model.ConsumerSessionSignup
import com.stripe.android.model.CvcCheck
import com.stripe.android.model.PaymentMethodCreateParams
import org.mockito.kotlin.mock

Expand Down Expand Up @@ -65,24 +68,30 @@ internal object TestFactory {
)
)

val PAYMENT_DETAILS_CARD = ConsumerPaymentDetails.Card(
id = "pm_123",
last4 = "4242",
expiryYear = 2024,
expiryMonth = 4,
brand = CardBrand.DinersClub,
cvcCheck = CvcCheck.Fail,
isDefault = false,
billingAddress = ConsumerPaymentDetails.BillingAddress(
countryCode = CountryCode.US,
postalCode = "42424"
)
)

val LINK_NEW_PAYMENT_DETAILS = LinkPaymentDetails.New(
paymentDetails = ConsumerPaymentDetails.Card(
id = "pm_123",
last4 = "4242",
),
paymentDetails = PAYMENT_DETAILS_CARD,
paymentMethodCreateParams = PAYMENT_METHOD_CREATE_PARAMS,
originalParams = mock()
)

val LINK_ACCOUNT = LinkAccount(CONSUMER_SESSION)

val CONSUMER_PAYMENT_DETAILS: ConsumerPaymentDetails = ConsumerPaymentDetails(
paymentDetails = listOf(
ConsumerPaymentDetails.Card(
id = "pm_123",
last4 = "4242",
)
)
paymentDetails = listOf(PAYMENT_DETAILS_CARD)
)

val LINK_CONFIGURATION = LinkConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ internal open class FakeLinkAccountManager : LinkAccountManager {
var logOutResult: Result<ConsumerSession> = Result.success(ConsumerSession("", "", "", ""))
var createCardPaymentDetailsResult: Result<LinkPaymentDetails> = Result.success(
value = LinkPaymentDetails.Saved(
paymentDetails = ConsumerPaymentDetails.Card(
id = "pm_123",
last4 = "4242",
),
paymentDetails = TestFactory.PAYMENT_DETAILS_CARD,
paymentMethodCreateParams = mock(),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.stripe.android.core.model.CountryCode
import com.stripe.android.link.theme.StripeThemeForLink
import com.stripe.android.model.CardBrand
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.CvcCheck
Expand Down Expand Up @@ -32,14 +33,16 @@ internal class PaymentDetailsListItemScreenShotTest(
@Test
fun test() {
paparazziRule.snapshot {
PaymentDetailsListItem(
paymentDetails = testCase.state.details,
enabled = testCase.state.enabled,
isSelected = testCase.state.isSelected,
isUpdating = testCase.state.isUpdating,
onClick = {},
onMenuButtonClick = {}
)
StripeThemeForLink {
PaymentDetailsListItem(
paymentDetails = testCase.state.details,
enabled = testCase.state.enabled,
isSelected = testCase.state.isSelected,
isUpdating = testCase.state.isUpdating,
onClick = {},
onMenuButtonClick = {}
)
}
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 521b349

Please sign in to comment.