diff --git a/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestInstantDebits.kt b/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestInstantDebits.kt index 59d2e6cca91..52a8f9d97a6 100644 --- a/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestInstantDebits.kt +++ b/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestInstantDebits.kt @@ -46,7 +46,7 @@ internal class TestInstantDebits : BasePlaygroundTest() { it[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On } - testDriver.confirmInstantDebits( + testDriver.confirmLinkBankPayment( testParameters = params, afterAuthorization = { rules.compose.waitUntil(DEFAULT_UI_TIMEOUT.inWholeMilliseconds) { @@ -61,7 +61,7 @@ internal class TestInstantDebits : BasePlaygroundTest() { @Test fun testInstantDebitsCancelAllowsUserToContinue() { - testDriver.confirmInstantDebits( + testDriver.confirmLinkBankPayment( testParameters = testParameters.copy( authorizationAction = AuthorizeAction.Cancel, ), diff --git a/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestLinkCardBrand.kt b/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestLinkCardBrand.kt new file mode 100644 index 00000000000..4060ccb25c6 --- /dev/null +++ b/paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestLinkCardBrand.kt @@ -0,0 +1,83 @@ +package com.stripe.android.lpm + +import androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.isEnabled +import androidx.compose.ui.test.onAllNodesWithText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.stripe.android.BasePlaygroundTest +import com.stripe.android.paymentsheet.example.playground.settings.AutomaticPaymentMethodsSettingsDefinition +import com.stripe.android.paymentsheet.example.playground.settings.Country +import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition +import com.stripe.android.paymentsheet.example.playground.settings.Currency +import com.stripe.android.paymentsheet.example.playground.settings.CurrencySettingsDefinition +import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddress +import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddressSettingsDefinition +import com.stripe.android.paymentsheet.example.playground.settings.LinkSettingsDefinition +import com.stripe.android.paymentsheet.example.playground.settings.SupportedPaymentMethodsSettingsDefinition +import com.stripe.android.paymentsheet.ui.PAYMENT_SHEET_PRIMARY_BUTTON_TEST_TAG +import com.stripe.android.test.core.AuthorizeAction +import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT +import com.stripe.android.test.core.TestParameters +import com.stripe.android.test.core.ui.ComposeButton +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +internal class TestLinkCardBrand : BasePlaygroundTest() { + + private val testParameters = TestParameters.create( + paymentMethodCode = "link", + ) { settings -> + settings[CountrySettingsDefinition] = Country.US + settings[CurrencySettingsDefinition] = Currency.USD + settings[AutomaticPaymentMethodsSettingsDefinition] = false + settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On + settings[LinkSettingsDefinition] = true + settings[SupportedPaymentMethodsSettingsDefinition] = "card" + } + + @Test + fun testLinkCardBrandSuccess() { + val params = testParameters.copyPlaygroundSettings { + it[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On + } + + testDriver.confirmLinkBankPayment( + testParameters = params, + afterAuthorization = { + rules.compose.waitUntil(DEFAULT_UI_TIMEOUT.inWholeMilliseconds) { + rules.compose + .onAllNodesWithText("STRIPE TEST BANK •••• 6789") + .fetchSemanticsNodes(atLeastOneRootRequired = false) + .isNotEmpty() + } + } + ) + } + + @Test + fun testLinkCardBrandCancelAllowsUserToContinue() { + testDriver.confirmLinkBankPayment( + testParameters = testParameters.copy( + authorizationAction = AuthorizeAction.Cancel, + ), + afterAuthorization = { + ComposeButton(rules.compose, hasTestTag(PAYMENT_SHEET_PRIMARY_BUTTON_TEST_TAG)) + .waitFor(isEnabled()) + } + ) + } + + @Test + fun testLinkCardBrandCancelAllowsUserToContinueInCustomFlow() { + testDriver.confirmInstantDebitsInCustomFlow( + testParameters = testParameters.copy( + authorizationAction = AuthorizeAction.Cancel, + ), + afterAuthorization = { + ComposeButton(rules.compose, hasTestTag(PAYMENT_SHEET_PRIMARY_BUTTON_TEST_TAG)) + .waitFor(isEnabled()) + } + ) + } +} diff --git a/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/PlaygroundTestDriver.kt b/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/PlaygroundTestDriver.kt index cdb3a523ac5..826b4463065 100644 --- a/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/PlaygroundTestDriver.kt +++ b/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/PlaygroundTestDriver.kt @@ -781,7 +781,7 @@ internal class PlaygroundTestDriver( ) } - fun confirmInstantDebits( + fun confirmLinkBankPayment( testParameters: TestParameters, afterAuthorization: (Selectors) -> Unit = {}, ): PlaygroundState? {