Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cttsai-stripe committed Feb 25, 2025
1 parent 6d577b1 commit 12bfcfc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ internal class CardFormViewTest {
assertThat(binding.postalCode.hasFocus()).isFalse()

binding.cardMultilineWidget.cvcEditText.append("3")
idleLooper()

assertThat(binding.postalCode.hasFocus()).isTrue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ internal class CardInputWidgetTest {

expiryDateEditText.append("12")
expiryDateEditText.append("79")
idleLooper()

assertThat(cardInputListener.expirationCompleteCalls)
.isEqualTo(1)
Expand Down Expand Up @@ -652,6 +653,9 @@ internal class CardInputWidgetTest {

expiryDateEditText.append("12")
expiryDateEditText.append("79")

idleLooper()

assertThat(cvcEditText.hasFocus())
.isTrue()

Expand All @@ -673,6 +677,7 @@ internal class CardInputWidgetTest {

expiryDateEditText.append("12")
expiryDateEditText.append("79")
idleLooper()
assertThat(cvcEditText.hasFocus())
.isTrue()

Expand Down Expand Up @@ -1178,7 +1183,7 @@ internal class CardInputWidgetTest {
updateCardNumberAndIdle(VISA_NO_SPACES)

setExpiryDate(12, 2079)
setCvcCode(CVC_VALUE_AMEX)
WaitForFocusAndSetCvcCode(CVC_VALUE_AMEX)
clear()

assertThat(cardNumberEditText.fieldText)
Expand All @@ -1203,8 +1208,8 @@ internal class CardInputWidgetTest {
postalCodeEnabled = true
setCardNumber(VISA_NO_SPACES)
setExpiryDate(12, 2079)
setCvcCode(CVC_VALUE_AMEX)
setPostalCode(POSTAL_CODE_VALUE)
WaitForFocusAndSetCvcCode(CVC_VALUE_AMEX)
WaitForFocusAndSetPostalCode(POSTAL_CODE_VALUE)
clear()

assertThat(cardNumberEditText.fieldText)
Expand All @@ -1220,6 +1225,7 @@ internal class CardInputWidgetTest {
.isEqualTo(
listOf(
CardInputListener.FocusField.Cvc,
CardInputListener.FocusField.ExpiryDate,
CardInputListener.FocusField.PostalCode,
CardInputListener.FocusField.CardNumber
)
Expand Down Expand Up @@ -1832,6 +1838,16 @@ internal class CardInputWidgetTest {
idleLooper()
}

private fun CardInputWidget.WaitForFocusAndSetCvcCode(cvcCode: String?) {
idleLooper()
setCvcCode(cvcCode)
}

private fun CardInputWidget.WaitForFocusAndSetPostalCode(postalCode: String?) {
idleLooper()
setPostalCode(postalCode)
}

private class FakeCardInputListener : CardInputListener {
val focusedFields = mutableListOf<CardInputListener.FocusField>()
var cardCompleteCalls = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,15 @@ internal class CardMultilineWidgetTest {

fullGroup.expiryDateEditText.append("12")
fullGroup.expiryDateEditText.append("50")
idleLooper()
verify(fullCardListener).onExpirationComplete()
verify(fullCardListener).onFocusChange(CardInputListener.FocusField.Cvc)
assertThat(fullGroup.cvcEditText.hasFocus())
.isTrue()

noZipGroup.expiryDateEditText.append("12")
noZipGroup.expiryDateEditText.append("50")
idleLooper()
verify(noZipCardListener).onExpirationComplete()
verify(noZipCardListener).onFocusChange(CardInputListener.FocusField.Cvc)
assertThat(noZipGroup.cvcEditText.hasFocus())
Expand All @@ -667,6 +669,7 @@ internal class CardMultilineWidgetTest {
fullGroup.expiryDateEditText.append("12")
fullGroup.expiryDateEditText.append("50")
fullGroup.cvcEditText.append(CVC_VALUE_COMMON)
idleLooper()
verify(fullCardListener).onCvcComplete()
verify(fullCardListener).onFocusChange(CardInputListener.FocusField.PostalCode)
assertThat(fullGroup.postalCodeEditText.hasFocus())
Expand All @@ -676,6 +679,7 @@ internal class CardMultilineWidgetTest {
noZipGroup.expiryDateEditText.append("12")
noZipGroup.expiryDateEditText.append("50")
noZipGroup.cvcEditText.append(CVC_VALUE_COMMON)
idleLooper()
verify(noZipCardListener).onCvcComplete()
verify(noZipCardListener, never()).onFocusChange(CardInputListener.FocusField.PostalCode)
assertThat(noZipGroup.cvcEditText.hasFocus())
Expand All @@ -689,6 +693,7 @@ internal class CardMultilineWidgetTest {
fun deleteWhenEmpty_fromExpiry_withPostalCode_shiftsToCardNumber() = runCardMultilineWidgetTest {
cardMultilineWidget.setCardInputListener(fullCardListener)
fullGroup.cardNumberEditText.setText(VISA_WITH_SPACES)
idleLooper()

assertThat(fullGroup.expiryDateEditText.hasFocus())
.isTrue()
Expand All @@ -709,6 +714,7 @@ internal class CardMultilineWidgetTest {
fun deleteWhenEmpty_fromExpiry_withoutPostalCode_shiftsToCardNumber() = runCardMultilineWidgetTest {
noZipCardMultilineWidget.setCardInputListener(noZipCardListener)
noZipGroup.cardNumberEditText.setText(VISA_WITH_SPACES)
idleLooper()

assertThat(noZipGroup.expiryDateEditText.hasFocus())
.isTrue()
Expand All @@ -730,6 +736,7 @@ internal class CardMultilineWidgetTest {

fullGroup.expiryDateEditText.append("12")
fullGroup.expiryDateEditText.append("50")
idleLooper()

assertThat(fullGroup.cvcEditText.hasFocus())
.isTrue()
Expand All @@ -743,6 +750,7 @@ internal class CardMultilineWidgetTest {

noZipGroup.expiryDateEditText.append("12")
noZipGroup.expiryDateEditText.append("50")
idleLooper()

assertThat(noZipGroup.cvcEditText.hasFocus())
.isTrue()
Expand Down

0 comments on commit 12bfcfc

Please sign in to comment.