Skip to content

Commit

Permalink
Fix regression where default label was not shown in horizontal mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amk-stripe authored Feb 24, 2025
1 parent 7048c91 commit ef9b4cb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal class SavedPaymentMethodMutator(

private val paymentOptionsItemsMapper: PaymentOptionsItemsMapper by lazy {
PaymentOptionsItemsMapper(
customerMetadata = paymentMethodMetadataFlow.value?.customerMetadata,
customerMetadata = paymentMethodMetadataFlow.mapAsStateFlow { it?.customerMetadata },
customerState = customerStateHolder.customer,
isGooglePayReady = paymentMethodMetadataFlow.mapAsStateFlow { it?.isGooglePayReady == true },
isLinkEnabled = isLinkEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.stripe.android.uicore.utils.combineAsStateFlow
import kotlinx.coroutines.flow.StateFlow

internal class PaymentOptionsItemsMapper(
private val customerMetadata: CustomerMetadata?,
private val customerMetadata: StateFlow<CustomerMetadata?>,
private val customerState: StateFlow<CustomerState?>,
private val isGooglePayReady: StateFlow<Boolean>,
private val isLinkEnabled: StateFlow<Boolean?>,
Expand All @@ -25,7 +25,8 @@ internal class PaymentOptionsItemsMapper(
customerState,
isLinkEnabled,
isGooglePayReady,
) { customerState, isLinkEnabled, isGooglePayReady ->
customerMetadata,
) { customerState, isLinkEnabled, isGooglePayReady, customerMetadata ->
createPaymentOptionsItems(
paymentMethods = customerState?.paymentMethods ?: listOf(),
isLinkEnabled = isLinkEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasAnyDescendant
Expand All @@ -12,6 +13,7 @@ import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isEnabled
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
Expand All @@ -26,6 +28,7 @@ import com.stripe.android.paymentsheet.state.PaymentElementLoader
import com.stripe.android.paymentsheet.ui.PAYMENT_SHEET_EDIT_BUTTON_TEST_TAG
import com.stripe.android.paymentsheet.ui.SAVED_PAYMENT_OPTION_TAB_LAYOUT_TEST_TAG
import com.stripe.android.paymentsheet.ui.SAVED_PAYMENT_OPTION_TEST_TAG
import com.stripe.android.paymentsheet.ui.TEST_TAG_DEFAULT_PAYMENT_METHOD_LABEL
import com.stripe.android.paymentsheet.ui.TEST_TAG_MODIFY_BADGE
import com.stripe.android.paymentsheet.ui.UPDATE_PM_REMOVE_BUTTON_TEST_TAG
import com.stripe.android.testing.PaymentConfigurationTestRule
Expand Down Expand Up @@ -332,6 +335,23 @@ internal class CustomerSessionPaymentSheetActivityTest {
}
}

@Test
fun `Default badge displayed in edit mode when set as default feature enabled`() {
val cards = PaymentMethodFixtures.createCards(2)
runTest(
cards = cards,
setAsDefaultFeatureEnabled = true,
defaultPaymentMethod = cards.first().id,
) {
composeTestRule.onEditButton().performClick()

composeTestRule.onAllNodesWithTag(
TEST_TAG_DEFAULT_PAYMENT_METHOD_LABEL,
useUnmergedTree = true
).assertCountEquals(1)
}
}

private fun setDefaultPaymentMethod() {
editPage.waitUntilVisible()
editPage.clickSetAsDefaultCheckbox()
Expand All @@ -354,6 +374,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodServer: Boolean = true,
setAsDefaultFeatureEnabled: Boolean = false,
paymentMethodLayout: PaymentSheet.PaymentMethodLayout = PaymentSheet.PaymentMethodLayout.Horizontal,
defaultPaymentMethod: String? = null,
test: (PaymentSheetActivity) -> Unit,
) {
networkRule.enqueue(
Expand All @@ -367,6 +388,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
isPaymentMethodRemoveEnabled = isPaymentMethodRemoveEnabled,
canRemoveLastPaymentMethod = canRemoveLastPaymentMethodServer,
setAsDefaultFeatureEnabled = setAsDefaultFeatureEnabled,
defaultPaymentMethod = defaultPaymentMethod,
)
)
}
Expand Down Expand Up @@ -451,6 +473,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
isPaymentMethodRemoveEnabled: Boolean,
canRemoveLastPaymentMethod: Boolean,
setAsDefaultFeatureEnabled: Boolean,
defaultPaymentMethod: String?,
): String {
val cardsArray = JSONArray()

Expand Down Expand Up @@ -505,7 +528,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
}
}
},
"default_payment_method": null
"default_payment_method": $defaultPaymentMethod
},
"payment_method_preference": {
"object": "payment_method_preference",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class PaymentOptionsItemsMapperTest {
isNotPaymentFlow = true,
nameProvider = { it!!.resolvableString },
isCbcEligible = { false },
customerMetadata = CustomerMetadata(
hasCustomerConfiguration = false,
isPaymentMethodSetAsDefaultEnabled = false
customerMetadata = MutableStateFlow(
CustomerMetadata(
hasCustomerConfiguration = false,
isPaymentMethodSetAsDefaultEnabled = false
)
),
)

Expand Down Expand Up @@ -66,9 +68,11 @@ class PaymentOptionsItemsMapperTest {
isNotPaymentFlow = false,
nameProvider = { it!!.resolvableString },
isCbcEligible = { false },
customerMetadata = CustomerMetadata(
hasCustomerConfiguration = false,
isPaymentMethodSetAsDefaultEnabled = false
customerMetadata = MutableStateFlow(
CustomerMetadata(
hasCustomerConfiguration = false,
isPaymentMethodSetAsDefaultEnabled = false
)
),
)

Expand Down

0 comments on commit ef9b4cb

Please sign in to comment.