/** * Set the CVC value for the card. Note that the maximum length is assumed to * be 3, unless the brand of the card has already been set (by setting the card number). * * @param cvcCode the CVC value to be set */ public void setCvcCode(String cvcCode) { mCvcNumberEditText.setText(cvcCode); }
@Override public void onDeleteEmpty() { String fieldText = backUpTarget.getText().toString(); if (fieldText.length() > 1) { backUpTarget.setText( fieldText.substring(0, fieldText.length() - 1)); } backUpTarget.requestFocus(); backUpTarget.setSelection(backUpTarget.length()); } }
/** * @param shippingInformation shippingInformation to populated into the widget input fields. */ public void populateShippingInfo(@Nullable ShippingInformation shippingInformation) { if (shippingInformation == null) { return; } Address address = shippingInformation.getAddress(); if (address != null) { mCityEditText.setText(address.getCity()); if (address.getCountry() != null && !address.getCountry().isEmpty()) { mCountryAutoCompleteTextView.setCountrySelected(address.getCountry()); } mAddressEditText.setText(address.getLine1()); mAddressEditText2.setText(address.getLine2()); mPostalCodeEditText.setText(address.getPostalCode()); mStateEditText.setText(address.getState()); } mNameEditText.setText(shippingInformation.getName()); mPhoneNumberEditText.setText(shippingInformation.getPhone()); }
@Test public void getShippingInfo_whenShippingInfoValid_returnsExpected() { mStateEditText.setText("CA"); mCityEditText.setText("San Francisco"); mAddressLine1EditText.setText("185 Berry St"); mAddressLine2EditText.setText("10th Floor"); mNameEditText.setText("Fake Name"); mPhoneEditText.setText("(123) 456 - 7890"); mPostalEditText.setText("12345"); mCountryAutoCompleteTextView.updateUIForCountryEntered(Locale.US.getDisplayCountry()); ShippingInformation inputShippingInfo = mShippingInfoWidget.getShippingInformation(); assertEquals(inputShippingInfo.toMap(), mShippingInfo.toMap()); }
/** * Clear all entered data and hide all error messages. */ public void clear() { mCardNumberEditText.setText(""); mExpiryDateEditText.setText(""); mCvcEditText.setText(""); mPostalCodeEditText.setText(""); mCardNumberEditText.setShouldShowError(false); mExpiryDateEditText.setShouldShowError(false); mCvcEditText.setShouldShowError(false); mPostalCodeEditText.setShouldShowError(false); updateBrand(Card.UNKNOWN); }
@Test public void shippingInfoWidget_addressSaved_validationTriggers() { mCountryAutoCompleteTextView.updateUIForCountryEntered(Locale.US.getDisplayCountry()); assertFalse(mShippingInfoWidget.validateAllFields()); mAddressLine1EditText.setText("123 Fake Address"); mNameEditText.setText("Fake Name"); mCityEditText.setText("Fake City"); mPostalEditText.setText("12345"); mStateEditText.setText("CA"); mPhoneEditText.setText("(123) 456 - 7890"); assertTrue(mShippingInfoWidget.validateAllFields()); mPostalEditText.setText(""); assertFalse(mShippingInfoWidget.validateAllFields()); mPostalEditText.setText("ABCDEF"); assertFalse(mShippingInfoWidget.validateAllFields()); mCountryAutoCompleteTextView.updateUIForCountryEntered(new Locale("", mNoPostalCodeCountry).getDisplayCountry()); assertTrue(mShippingInfoWidget.validateAllFields()); }
/** * Clear all text fields in the CardInputWidget. */ public void clear() { if (mCardNumberEditText.hasFocus() || mExpiryDateEditText.hasFocus() || mCvcNumberEditText.hasFocus() || this.hasFocus()) { mCardNumberEditText.requestFocus(); } mCvcNumberEditText.setText(""); mExpiryDateEditText.setText(""); mCardNumberEditText.setText(""); }
@Before public void setup() { MockitoAnnotations.initMocks(this); mActivityController = Robolectric.buildActivity(CardInputTestActivity.class) .create().start(); // Note that the CVC EditText is a StripeEditText mEditText = mActivityController.get().getCvcEditText(); mEditText.setText(""); mEditText.setDeleteEmptyListener(mDeleteEmptyListener); mEditText.setAfterTextChangedListener(mAfterTextChangedListener); }
@Test public void shippingInfoWidget_whenValidationFails_errorTextRenders() { mCountryAutoCompleteTextView.updateUIForCountryEntered(Locale.US.getDisplayCountry()); mShippingInfoWidget.validateAllFields(); assertTrue(mAddressLine1TextInputLayout.isErrorEnabled()); assertTrue(mCityTextInputLayout.isErrorEnabled()); assertTrue(mNameTextInputLayout.isErrorEnabled()); assertTrue(mPostalCodeTextInputLayout.isErrorEnabled()); assertTrue(mStateTextInputLayout.isErrorEnabled()); mAddressLine1EditText.setText("123 Fake Address"); mNameEditText.setText("Fake Name"); mCityEditText.setText("Fake City"); mPostalEditText.setText("12345"); mStateEditText.setText("CA"); mShippingInfoWidget.validateAllFields(); assertFalse(mAddressLine1TextInputLayout.isErrorEnabled()); assertFalse(mCityTextInputLayout.isErrorEnabled()); assertFalse(mNameTextInputLayout.isErrorEnabled()); assertFalse(mPostalCodeTextInputLayout.isErrorEnabled()); assertFalse(mStateTextInputLayout.isErrorEnabled()); mPostalEditText.setText(""); mShippingInfoWidget.validateAllFields(); assertTrue(mPostalCodeTextInputLayout.isErrorEnabled()); mCountryAutoCompleteTextView.updateUIForCountryEntered(new Locale("", mNoPostalCodeCountry).getDisplayCountry()); mShippingInfoWidget.validateAllFields(); assertFalse(mStateTextInputLayout.isErrorEnabled()); }