Skip to content

Commit

Permalink
Add end-to-end tests for Link Card Brand
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Sep 30, 2024
1 parent b0a6dd8 commit 2dbbc0c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -61,7 +61,7 @@ internal class TestInstantDebits : BasePlaygroundTest() {

@Test
fun testInstantDebitsCancelAllowsUserToContinue() {
testDriver.confirmInstantDebits(
testDriver.confirmLinkBankPayment(
testParameters = testParameters.copy(
authorizationAction = AuthorizeAction.Cancel,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ internal class PlaygroundTestDriver(
)
}

fun confirmInstantDebits(
fun confirmLinkBankPayment(
testParameters: TestParameters,
afterAuthorization: (Selectors) -> Unit = {},
): PlaygroundState? {
Expand Down

0 comments on commit 2dbbc0c

Please sign in to comment.