diff --git a/sdk/src/main/java/co/omise/android/ui/ExpiryDateEditText.kt b/sdk/src/main/java/co/omise/android/ui/ExpiryDateEditText.kt index 60585e501..c3b8f719a 100644 --- a/sdk/src/main/java/co/omise/android/ui/ExpiryDateEditText.kt +++ b/sdk/src/main/java/co/omise/android/ui/ExpiryDateEditText.kt @@ -37,7 +37,7 @@ class ExpiryDateEditText : OmiseEditText { addTextChangedListener(textWatcher) disableOptions() filters = arrayOf(InputFilter.LengthFilter(MAX_CHARS)) - inputType = InputType.TYPE_CLASS_PHONE + inputType = InputType.TYPE_CLASS_NUMBER } override fun onSelectionChanged(selStart: Int, selEnd: Int) { @@ -70,8 +70,7 @@ class ExpiryDateEditText : OmiseEditText { beforeChangedText = s.toString() } - override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { - if (s == null || s.length > MAX_CHARS) return + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { // On deleting if (s.length < beforeChangedText.length) { diff --git a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt index 21f40a3af..e0d610116 100644 --- a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt +++ b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt @@ -102,7 +102,7 @@ class CreditCardActivityTest { fun form_validForm() { onView(withId(R.id.edit_card_number)).perform(typeText("4242424242424242")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), pressImeActionButton()) onView(withId(R.id.edit_card_number)).check(matches(withText("4242 4242 4242 4242"))) @@ -118,7 +118,7 @@ class CreditCardActivityTest { fun form_validBillingAddressForm() { onView(withId(R.id.edit_card_number)).perform(typeText("4242424242424242")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123")) onView(withId(R.id.edit_country)).perform(scrollTo(), click()) @@ -148,7 +148,7 @@ class CreditCardActivityTest { fun form_invalidForm() { onView(withId(R.id.edit_card_number)).perform(typeText("1234567890")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), pressImeActionButton()) onView(withId(R.id.edit_card_number)).check(matches(withText("1234 5678 90"))) @@ -298,7 +298,7 @@ class CreditCardActivityTest { whenever(mockClient.send(any(), any())).doAnswer {} onView(withId(R.id.edit_card_number)).perform(typeText("4242424242424242")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), closeSoftKeyboard()) onView(withId(R.id.button_submit)).perform(scrollTo(), click()) @@ -319,7 +319,7 @@ class CreditCardActivityTest { onView(withId(R.id.edit_card_number)).perform(typeText("4242424242424242")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), closeSoftKeyboard()) onView(withId(R.id.button_submit)).perform(scrollTo(), click()) @@ -346,7 +346,7 @@ class CreditCardActivityTest { onView(withId(R.id.edit_card_number)).perform(typeText("4242424242424242")) onView(withId(R.id.edit_card_name)).perform(typeText("John Doe")) - onView(withId(R.id.edit_expiry_date)).perform(typeText("1234")) + onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234")) onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), closeSoftKeyboard()) onView(withId(R.id.edit_country)).perform(scrollTo(), click()) onView(withId(R.id.country_list)) diff --git a/sdk/src/test/java/co/omise/android/ui/ExpiryDateEditTextTest.kt b/sdk/src/test/java/co/omise/android/ui/ExpiryDateEditTextTest.kt index 8c91df2ba..56696ce88 100644 --- a/sdk/src/test/java/co/omise/android/ui/ExpiryDateEditTextTest.kt +++ b/sdk/src/test/java/co/omise/android/ui/ExpiryDateEditTextTest.kt @@ -48,6 +48,15 @@ class ExpiryDateEditTextTest { assertEquals(Unit, editText.validate()) } + @Test + fun validate_ignoreSpecialCharactersInput() { + "*,.".forEach { editText.append(it.toString()) } + + assertEquals("", editText.text.toString()) + "1234".forEach { editText.append(it.toString()) } // 12/34 + assertEquals("12/34", editText.text.toString()) + } + @Test(expected = InputValidationException.EmptyInputException::class) fun validate_emptyValue() { "".forEach { editText.append(it.toString()) }