Skip to content

Commit

Permalink
Use display brand in remove dialog description (#9594)
Browse files Browse the repository at this point in the history
  • Loading branch information
amk-stripe authored Nov 12, 2024
1 parent 51e452c commit 8f73194
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ internal data class DisplayableSavedPaymentMethod(

fun getDescription() = when (paymentMethod.type) {
PaymentMethod.Type.Card -> {
val brand = paymentMethod.card?.displayBrand?.let { CardBrand.fromCode(it) }
?: paymentMethod.card?.brand
resolvableString(
com.stripe.android.R.string.stripe_card_ending_in,
brand?.displayName,
brandDisplayName(),
paymentMethod.card?.last4
)
}
Expand All @@ -50,4 +48,10 @@ internal data class DisplayableSavedPaymentMethod(
getDescription(),
)
}

fun brandDisplayName(): String? {
val brand = paymentMethod.card?.displayBrand?.let { CardBrand.fromCode(it) }
?: paymentMethod.card?.brand
return brand?.displayName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private fun DisplayableSavedPaymentMethod.getRemoveDialogTitle() = when (payment
private fun DisplayableSavedPaymentMethod.getRemoveDialogDescription() = when (paymentMethod.type) {
PaymentMethod.Type.Card -> resolvableString(
com.stripe.android.R.string.stripe_card_with_last_4,
paymentMethod.card?.brand,
this.brandDisplayName(),
paymentMethod.card?.last4
)
PaymentMethod.Type.SepaDebit -> resolvableString(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.stripe.android.paymentsheet.ui

import android.os.Build
import androidx.compose.ui.test.assertAny
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.onNodeWithTag
import com.stripe.android.model.PaymentMethodFixtures
import com.stripe.android.model.PaymentMethodFixtures.toDisplayableSavedPaymentMethod
import com.stripe.android.ui.core.elements.TEST_TAG_SIMPLE_DIALOG
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import kotlin.test.Test

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.Q])
class RemovePaymentMethodDialogUITest {

@get:Rule
val composeRule = createComposeRule()

@Test
fun removeDescription_usesSelectedBrandIfAvailable() {
val paymentMethod = PaymentMethodFixtures
.CARD_WITH_NETWORKS_PAYMENT_METHOD
.toDisplayableSavedPaymentMethod()

composeRule.setContent {
RemovePaymentMethodDialogUI(
paymentMethod = paymentMethod,
onConfirmListener = {},
onDismissListener = {}
)
}

composeRule.onNodeWithTag(TEST_TAG_SIMPLE_DIALOG).onChildren().assertAny(
hasText("Cartes Bancaires ····4242")
)
}
}

0 comments on commit 8f73194

Please sign in to comment.