Skip to content

Commit

Permalink
More updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe committed Jan 13, 2025
1 parent 21d56e7 commit 44c75d0
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.stripe.android.common.ui

import androidx.compose.ui.input.key.Key
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.invokeGlobalAssertions
import androidx.compose.ui.test.performKeyInput
import androidx.compose.ui.test.requestFocus

fun SemanticsNodeInteraction.performClickWithKeyboard(): SemanticsNodeInteraction {
@OptIn(ExperimentalTestApi::class)
return this.invokeGlobalAssertions()
.requestFocus()
.performKeyInput {
keyDown(Key.Enter)
keyUp(Key.Enter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import android.app.Application
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import androidx.lifecycle.testing.TestLifecycleOwner
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.common.ui.performClickWithKeyboard
import com.stripe.android.core.utils.urlEncode
import com.stripe.android.customersheet.util.CustomerSheetHacks
import com.stripe.android.model.CardBrand
Expand Down Expand Up @@ -74,7 +74,7 @@ class CustomerSessionCustomerSheetActivityTest {
isPaymentMethodRemoveEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242").assertIsEnabled()
savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "5544").assertIsEnabled()
Expand All @@ -89,7 +89,7 @@ class CustomerSessionCustomerSheetActivityTest {
isPaymentMethodRemoveEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242").assertIsEnabled()
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class CustomerSessionCustomerSheetActivityTest {
isPaymentMethodRemoveEnabled = false,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

val nonCbcCard = savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "5544")
nonCbcCard.assertIsEnabled()
Expand All @@ -151,7 +151,7 @@ class CustomerSessionCustomerSheetActivityTest {
isPaymentMethodRemoveEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "5544").assertIsEnabled()

Expand All @@ -160,7 +160,7 @@ class CustomerSessionCustomerSheetActivityTest {
cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

editPage.onRemoveButton().assertIsEnabled()
}
Expand All @@ -175,14 +175,14 @@ class CustomerSessionCustomerSheetActivityTest {
isCanRemoveLastPaymentMethodEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

val cbcCard = savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

editPage.onRemoveButton().assertIsEnabled()
}
Expand All @@ -197,14 +197,14 @@ class CustomerSessionCustomerSheetActivityTest {
isCanRemoveLastPaymentMethodEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

val cbcCard = savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

editPage.onRemoveButton().assertDoesNotExist()
}
Expand All @@ -219,14 +219,14 @@ class CustomerSessionCustomerSheetActivityTest {
isCanRemoveLastPaymentMethodEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = false,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

val cbcCard = savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

editPage.onRemoveButton().assertDoesNotExist()
}
Expand All @@ -241,14 +241,14 @@ class CustomerSessionCustomerSheetActivityTest {
isCanRemoveLastPaymentMethodEnabled = false,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()

val cbcCard = savedPaymentMethodsPage.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

editPage.onRemoveButton().assertDoesNotExist()
}
Expand All @@ -262,8 +262,8 @@ class CustomerSessionCustomerSheetActivityTest {
isPaymentMethodRemoveEnabled = true,
allowsRemovalOfLastSavedPaymentMethod = true,
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()
savedPaymentMethodsPage.clickRemoveButton()

enqueuePaymentMethods(
Expand Down Expand Up @@ -293,8 +293,8 @@ class CustomerSessionCustomerSheetActivityTest {
PaymentMethodFactory.card(last4 = "1001"),
),
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

enqueuePaymentMethods(
cards = listOf(
Expand All @@ -310,7 +310,7 @@ class CustomerSessionCustomerSheetActivityTest {
enqueueDetachPaymentMethod(id = "pm_3")
enqueueDetachPaymentMethod(id = "pm_4")

editPage.onRemoveButton().performClick()
editPage.onRemoveButton().performClickWithKeyboard()
removeDialog.confirm()

savedPaymentMethodsPage.waitUntilVisible()
Expand All @@ -325,8 +325,8 @@ class CustomerSessionCustomerSheetActivityTest {
.update(last4 = "1001", addCbcNetworks = true),
),
) {
savedPaymentMethodsPage.onEditButton().performClick()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "1001").performClick()
savedPaymentMethodsPage.onEditButton().performClickWithKeyboard()
savedPaymentMethodsPage.onModifyBadgeFor(last4 = "1001").performClickWithKeyboard()

editPage.setCardBrand("Visa")
editPage.update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.hasTextExactly
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import com.stripe.android.common.ui.performClickWithKeyboard
import com.stripe.android.paymentsheet.ui.SAVED_PAYMENT_METHOD_CARD_TEST_TAG

internal class CustomerSheetPage(
Expand All @@ -14,7 +14,7 @@ internal class CustomerSheetPage(
fun clickOnText(text: String) {
waitForText(text)

composeTestRule.onNode(hasText(text, ignoreCase = true)).performClick()
composeTestRule.onNode(hasText(text, ignoreCase = true)).performClickWithKeyboard()
}

fun clickPaymentOptionItem(text: String) {
Expand All @@ -25,7 +25,7 @@ internal class CustomerSheetPage(
}

composeTestRule.onNodeWithTag("${SAVED_PAYMENT_METHOD_CARD_TEST_TAG}_$text")
.performClick()
.performClickWithKeyboard()

composeTestRule.waitForIdle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import com.stripe.android.common.ui.performClickWithKeyboard
import com.stripe.android.model.CardBrand
import com.stripe.android.model.PaymentMethod
import com.stripe.android.networktesting.NetworkRule
Expand Down Expand Up @@ -60,7 +60,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = true,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

composeTestRule.onSavedPaymentMethod(last4 = "4242").assertIsEnabled()
composeTestRule.onSavedPaymentMethod(last4 = "5544").assertIsEnabled()
Expand All @@ -76,7 +76,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = true,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

composeTestRule.onSavedPaymentMethod(last4 = "4242").assertIsEnabled()
}
Expand Down Expand Up @@ -145,7 +145,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = false,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val nonCbcCard = composeTestRule.onSavedPaymentMethod(last4 = "5544")
nonCbcCard.assertIsEnabled()
Expand All @@ -168,7 +168,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = false,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

composeTestRule.onSavedPaymentMethod(last4 = "5544").assertIsEnabled()

Expand All @@ -177,7 +177,7 @@ internal class CustomerSessionPaymentSheetActivityTest {
cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertIsEnabled()
}
Expand All @@ -192,14 +192,14 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = false,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val cbcCard = composeTestRule.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertDoesNotExist()
}
Expand All @@ -214,14 +214,14 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = false,
canRemoveLastPaymentMethodServer = true,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val cbcCard = composeTestRule.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertDoesNotExist()
}
Expand All @@ -236,14 +236,14 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = true,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val cbcCard = composeTestRule.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertIsEnabled()
}
Expand All @@ -258,14 +258,14 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = true,
canRemoveLastPaymentMethodServer = false,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val cbcCard = composeTestRule.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertDoesNotExist()
}
Expand All @@ -280,14 +280,14 @@ internal class CustomerSessionPaymentSheetActivityTest {
canRemoveLastPaymentMethodConfig = false,
canRemoveLastPaymentMethodServer = false,
) {
composeTestRule.onEditButton().performClick()
composeTestRule.onEditButton().performClickWithKeyboard()

val cbcCard = composeTestRule.onSavedPaymentMethod(last4 = "4242")

cbcCard.assertIsEnabled()
cbcCard.assertHasModifyBadge()

composeTestRule.onModifyBadgeFor(last4 = "4242").performClick()
composeTestRule.onModifyBadgeFor(last4 = "4242").performClickWithKeyboard()

composeTestRule.onUpdateScreenRemoveButton().assertDoesNotExist()
}
Expand Down
Loading

0 comments on commit 44c75d0

Please sign in to comment.