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 11, 2024
1 parent d4d7f50 commit 3b92d5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ class AddressElementExampleActivity : AppCompatActivity() {
Button(
onClick = {
val config = AddressLauncher.Configuration.Builder()
.additionalFields(
additionalFields = AddressLauncher.AdditionalFieldsConfiguration(
phone = AddressLauncher.AdditionalFieldsConfiguration
.FieldConfiguration.REQUIRED
)
)
// Provide your Google Places API key to enable autocomplete
.googlePlacesApiKey(Settings(context).googlePlacesApiKey)
.build()
Expand Down

0 comments on commit 3b92d5b

Please sign in to comment.