-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial
CustomerSheet
end-to-end tests. (#8525)
* Add initial `CustomerSheet` end-to-end tests. * Conditionally click the payment selection if needed. * Remove `SetupIntent` tests & move `CustomerAdapter` to own flow.
- Loading branch information
1 parent
77c3231
commit 9468357
Showing
11 changed files
with
224 additions
and
59 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestCardInCustomerSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.stripe.android.lpm | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.stripe.android.BasePlaygroundTest | ||
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.CustomerSettingsDefinition | ||
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSheetPaymentMethodModeDefinition | ||
import com.stripe.android.paymentsheet.example.playground.settings.CustomerType | ||
import com.stripe.android.paymentsheet.example.playground.settings.PaymentMethodMode | ||
import com.stripe.android.test.core.TestParameters | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class TestCardInCustomerSheet : BasePlaygroundTest() { | ||
@Test | ||
fun testCard() { | ||
testDriver.savePaymentMethodInCustomerSheet( | ||
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings -> | ||
settings[CustomerSettingsDefinition] = CustomerType.NEW | ||
settings[CountrySettingsDefinition] = Country.US | ||
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach | ||
}, | ||
populateCustomLpmFields = { | ||
populateCardDetails() | ||
}, | ||
) | ||
} | ||
|
||
@Test | ||
fun testCardWithNonUsMerchant() { | ||
testDriver.savePaymentMethodInCustomerSheet( | ||
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings -> | ||
settings[CustomerSettingsDefinition] = CustomerType.NEW | ||
settings[CountrySettingsDefinition] = Country.FR | ||
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach | ||
}, | ||
populateCustomLpmFields = { | ||
populateCardDetails() | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/FormElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stripe.android.test.core.ui | ||
|
||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.hasTestTag | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import com.stripe.android.paymentsheet.ui.FORM_ELEMENT_TEST_TAG | ||
import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT | ||
|
||
class FormElement( | ||
private val composeTestRule: ComposeTestRule | ||
) { | ||
@OptIn(ExperimentalTestApi::class) | ||
fun waitFor() { | ||
composeTestRule.waitUntilExactlyOneExists( | ||
hasTestTag(FORM_ELEMENT_TEST_TAG), | ||
DEFAULT_UI_TIMEOUT.inWholeMilliseconds | ||
) | ||
} | ||
} |
39 changes: 12 additions & 27 deletions
39
...entsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/PaymentSelection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,29 @@ | ||
package com.stripe.android.test.core.ui | ||
|
||
import androidx.compose.ui.test.ComposeTimeoutException | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertIsEnabled | ||
import androidx.compose.ui.test.hasTestTag | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.onAllNodesWithTag | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performScrollToNode | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.stripe.android.paymentsheet.ui.TEST_TAG_LIST | ||
import com.stripe.android.test.core.DEFAULT_UI_TIMEOUT | ||
|
||
class PaymentSelection(val composeTestRule: ComposeTestRule, val paymentMethodCode: String) { | ||
fun click() { | ||
val resource = InstrumentationRegistry.getInstrumentation().targetContext.resources | ||
if (composeTestRule.onAllNodes(hasTestTag(TEST_TAG_LIST)).fetchSemanticsNodes().isNotEmpty()) { | ||
val paymentMethodMatcher = hasTestTag(TEST_TAG_LIST + paymentMethodCode) | ||
|
||
try { | ||
// If we don't find the node, it means that there's only one payment method available | ||
// and we don't show the payment method carousel as a result. | ||
composeTestRule.waitUntil(timeoutMillis = DEFAULT_UI_TIMEOUT.inWholeMilliseconds) { | ||
composeTestRule | ||
.onAllNodesWithTag(TEST_TAG_LIST) | ||
.fetchSemanticsNodes().size == 1 | ||
} | ||
} catch (_: ComposeTimeoutException) { | ||
return | ||
} | ||
|
||
val paymentMethodMatcher = hasTestTag(TEST_TAG_LIST + paymentMethodCode) | ||
composeTestRule.onNodeWithTag(TEST_TAG_LIST, true) | ||
.performScrollToNode(paymentMethodMatcher) | ||
composeTestRule.waitForIdle() | ||
composeTestRule | ||
.onNode(paymentMethodMatcher) | ||
.assertIsDisplayed() | ||
.assertIsEnabled() | ||
.performClick() | ||
composeTestRule.onNodeWithTag(TEST_TAG_LIST, true) | ||
.performScrollToNode(paymentMethodMatcher) | ||
composeTestRule.waitForIdle() | ||
composeTestRule | ||
.onNode(paymentMethodMatcher) | ||
.assertIsDisplayed() | ||
.assertIsEnabled() | ||
.performClick() | ||
|
||
composeTestRule.waitForIdle() | ||
composeTestRule.waitForIdle() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.