Skip to content

Commit

Permalink
PWN-8923 - striga. clean phone number when phone country is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardmaximovich committed Jun 21, 2023
1 parent 1710190 commit 348ff7f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface StrigaSignUpFirstStepContract {
fun onCountryOfBirthClicked()
fun saveChanges()
fun onSubmit()
fun onPhoneCountryCodeChanged(newCountry: CountryCode)
fun onPhoneCountryCodeChanged(newCountry: CountryCode, changedByUser: Boolean)
fun onPhoneNumberChanged(newPhone: String)
fun onPhoneCountryCodeClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class StrigaSignUpFirstStepFragment :
}
bundle.containsKey(RESULT_KEY_PHONE_COUNTRY_CODE) -> {
val countryCode = bundle.getParcelableCompat<CountryCode>(RESULT_KEY_PHONE_COUNTRY_CODE) ?: return
presenter.onPhoneCountryCodeChanged(countryCode)
presenter.onPhoneCountryCodeChanged(countryCode, changedByUser = true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class StrigaSignUpFirstStepPresenter(
}
}

override fun onPhoneCountryCodeChanged(newCountry: CountryCode) {
override fun onPhoneCountryCodeChanged(newCountry: CountryCode, changedByUser: Boolean) {
phoneCountryCode = newCountry
view?.showPhoneCountryCode(phoneCountryCode)

Expand All @@ -103,6 +103,10 @@ class StrigaSignUpFirstStepPresenter(
countryCodeRepository = countryRepository
)
)

if (changedByUser) {
view?.updateSignupField(StrigaSignupDataType.PHONE_NUMBER, "")
}
}

override fun onPhoneNumberChanged(newPhone: String) {
Expand Down Expand Up @@ -156,7 +160,7 @@ class StrigaSignUpFirstStepPresenter(
cachedPhoneNumber = signupData[StrigaSignupDataType.PHONE_NUMBER]?.value
)

onPhoneCountryCodeChanged(phoneNumberWithCode.phoneCode)
onPhoneCountryCodeChanged(phoneNumberWithCode.phoneCode, false)

// Using the updated phoneCode and selectedPhoneNumber
view?.setupPhoneCountryCodePicker(
Expand All @@ -180,7 +184,7 @@ class StrigaSignUpFirstStepPresenter(

signupData[StrigaSignupDataType.PHONE_CODE_WITH_PLUS]?.value?.let {
val phoneCountryCode = countryRepository.findCountryCodeByPhoneCode(it)
phoneCountryCode?.let(::onPhoneCountryCodeChanged)
phoneCountryCode?.let { countryCode -> onPhoneCountryCodeChanged(countryCode, false) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ class StrigaSignupFirstStepPresenterTest {
presenter.attach(view)
interactor.setPhoneValidator(PhoneNumberInputValidator("90", countryCodeRepository))
presenter.onPhoneCountryCodeChanged(
CountryCode("tr", "tur", "90", "Turkey", ",")
CountryCode("tr", "tur", "90", "Turkey", ","),
true
)
presenter.onPhoneNumberChanged("5556667788")
presenter.onFieldChanged(StrigaSignupDataType.PHONE_CODE_WITH_PLUS, "+90")
Expand Down Expand Up @@ -396,7 +397,7 @@ class StrigaSignupFirstStepPresenterTest {
verify(exactly = 1) { view.showPhoneCountryCodePicker(TurkeyCountry) }

advanceUntilIdle()
presenter.onPhoneCountryCodeChanged(TurkeyCountry)
presenter.onPhoneCountryCodeChanged(TurkeyCountry, true)
verify { view.showPhoneCountryCode(TurkeyCountry) }

presenter.detach()
Expand Down

0 comments on commit 348ff7f

Please sign in to comment.