Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Aug 11, 2023
1 parent 6dc6a64 commit 4b1032f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.stripe.android.paymentsheet.ui
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.stripe.android.paymentsheet.PaymentSheetFixtures.PAYMENT_OPTIONS_CONT
import com.stripe.android.paymentsheet.PaymentSheetFixtures.updateState
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.android.paymentsheet.databinding.StripePrimaryButtonBinding
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.paymentsheet.ui.getLabel
import com.stripe.android.ui.core.forms.resources.LpmRepository
Expand Down Expand Up @@ -93,55 +94,57 @@ internal class PaymentOptionsActivityTest {
WeakMapInjectorRegistry.clear()
}

// @Test
// fun `click outside of bottom sheet before selection should return cancel result without selection`() {
// runActivityScenario {
// it.onActivity { activity ->
// activity.viewBinding.root.performClick()
// activity.finish()
// }
//
// assertThat(
// PaymentOptionResult.fromIntent(it.getResult().resultData)
// ).isEqualTo(
// PaymentOptionResult.Canceled(null, null, listOf())
// )
// }
// }

// @Test
// fun `click outside of bottom sheet should return cancel result even if there is a selection`() {
// val initialSelection = PaymentSelection.Saved(
// paymentMethod = PaymentMethodFixtures.createCard(),
// )
//
// val usBankAccount = PaymentMethodFixtures.US_BANK_ACCOUNT
// val paymentMethods = listOf(initialSelection.paymentMethod, usBankAccount)
//
// val args = PAYMENT_OPTIONS_CONTRACT_ARGS.updateState(
// paymentSelection = initialSelection,
// paymentMethods = paymentMethods,
// )
//
// runActivityScenario(args) {
// it.onActivity { activity ->
// // We use US Bank Account because they don't dismiss PaymentSheet upon selection
// // due to their mandate requirement.
// val usBankAccountLabel = usBankAccount.getLabel(context.resources)
// composeTestRule
// .onNodeWithTag("${PAYMENT_OPTION_CARD_TEST_TAG}_$usBankAccountLabel")
// .performClick()
//
// activity.viewBinding.root.performClick()
// activity.finish()
// }
//
// val result = PaymentOptionResult.fromIntent(it.getResult().resultData)
// assertThat(result).isEqualTo(
// PaymentOptionResult.Canceled(null, initialSelection, paymentMethods)
// )
// }
// }
@Test
fun `click outside of bottom sheet before selection should return cancel result without selection`() {
runActivityScenario {
it.onActivity {
pressBack()
}

composeTestRule.waitForIdle()

assertThat(
PaymentOptionResult.fromIntent(it.getResult().resultData)
).isEqualTo(
PaymentOptionResult.Canceled(null, null, listOf())
)
}
}

@Test
fun `click outside of bottom sheet should return cancel result even if there is a selection`() {
val initialSelection = PaymentSelection.Saved(
paymentMethod = PaymentMethodFixtures.createCard(),
)

val usBankAccount = PaymentMethodFixtures.US_BANK_ACCOUNT
val paymentMethods = listOf(initialSelection.paymentMethod, usBankAccount)

val args = PAYMENT_OPTIONS_CONTRACT_ARGS.updateState(
paymentSelection = initialSelection,
paymentMethods = paymentMethods,
)

runActivityScenario(args) {
it.onActivity {
// We use US Bank Account because they don't dismiss PaymentSheet upon selection
// due to their mandate requirement.
val usBankAccountLabel = usBankAccount.getLabel(context.resources)
composeTestRule
.onNodeWithTag("${PAYMENT_OPTION_CARD_TEST_TAG}_$usBankAccountLabel")
.performClick()

pressBack()
}

composeTestRule.waitForIdle()

val result = PaymentOptionResult.fromIntent(it.getResult().resultData)
assertThat(result).isEqualTo(
PaymentOptionResult.Canceled(null, initialSelection, paymentMethods)
)
}
}

@Test
fun `ContinueButton should be hidden when showing payment options`() {
Expand Down Expand Up @@ -222,26 +225,28 @@ internal class PaymentOptionsActivityTest {
}
}

// @Test
// fun `Verify selecting a payment method closes the sheet`() {
// val args = PAYMENT_OPTIONS_CONTRACT_ARGS.updateState(isGooglePayReady = true)
//
// runActivityScenario(args) {
// it.onActivity { activity ->
// composeTestRule
// .onNodeWithTag("${PAYMENT_OPTION_CARD_TEST_TAG}_Google Pay")
// .performClick()
//
// composeTestRule.waitForIdle()
//
// idleLooper()
//
// composeTestRule
// .onNodeWithTag(BottomSheetContentTestTag)
// .assertIsNotDisplayed()
// }
// }
// }
@Test
fun `Verify selecting a payment method closes the sheet`() {
val args = PAYMENT_OPTIONS_CONTRACT_ARGS.updateState(isGooglePayReady = true)

runActivityScenario(args) { scenario ->
scenario.onActivity {
composeTestRule
.onNodeWithTag("${PAYMENT_OPTION_CARD_TEST_TAG}_Google Pay")
.performClick()
}

composeTestRule.waitForIdle()

val result = PaymentOptionResult.fromIntent(scenario.getResult().resultData)
assertThat(result).isEqualTo(
PaymentOptionResult.Succeeded(
paymentSelection = PaymentSelection.GooglePay,
paymentMethods = emptyList(),
)
)
}
}

@Test
fun `notes visibility is set correctly`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ internal class PaymentSheetActivityTest {
}

@Test
fun `Verify ProcessResult state closes the sheet`() = runTest(testDispatcher) {
fun `Verify ProcessResult state closes the sheet`() {
val viewModel = createViewModel()
val scenario = activityScenario(viewModel)

Expand All @@ -620,7 +620,7 @@ internal class PaymentSheetActivityTest {
}

@Test
fun `successful payment should dismiss bottom sheet`() = runTest(testDispatcher) {
fun `successful payment should dismiss bottom sheet`() {
val viewModel = createViewModel()
val scenario = activityScenario(viewModel)

Expand Down

0 comments on commit 4b1032f

Please sign in to comment.