Skip to content

Commit

Permalink
Add test to AddressElement
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed Nov 8, 2024
1 parent ce57c1a commit 43ad3ae
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,33 @@ class AddressElementTest {
assertThat(country()).isEqualTo("US")
}

@Test
fun `when phone number is required, should not be complete until fully entered`() = runTest {
val addressElement = AddressElement(
IdentifierSpec.Generic("address"),
mapOf(
IdentifierSpec.Country to "CA"
),
countryDropdownFieldController = countryDropdownFieldController,
addressType = AddressType.Normal(
phoneNumberState = PhoneNumberState.REQUIRED
),
sameAsShippingElement = null,
shippingValuesMap = null,
)

val phoneNumberController = addressElement.phoneNumberElement.controller

phoneNumberController.onRawValueChange("123")
assertThat(phoneNumberController.isComplete.value).isFalse()

phoneNumberController.onRawValueChange("123456")
assertThat(phoneNumberController.isComplete.value).isFalse()

phoneNumberController.onRawValueChange("1234567890")
assertThat(phoneNumberController.isComplete.value).isTrue()
}

private fun createAddressElement(initialValues: Map<IdentifierSpec, String>): AddressElement {
return AddressElement(
IdentifierSpec.Generic("address"),
Expand Down

0 comments on commit 43ad3ae

Please sign in to comment.