Skip to content

Commit

Permalink
Restrict change to keyboard type
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasNaouchi committed Nov 7, 2023
1 parent 44abe91 commit a9738bb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 31 deletions.
15 changes: 0 additions & 15 deletions sdk/src/main/java/co/omise/android/ui/ExpiryDateEditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import android.util.AttributeSet
import co.omise.android.extensions.disableOptions
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.regex.Matcher
import java.util.regex.Pattern

/**
* ExpiryDateEditText is a custom EditText for credit card expiration date field. This EditText
Expand Down Expand Up @@ -73,9 +71,6 @@ class ExpiryDateEditText : OmiseEditText {
}

override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.length > MAX_CHARS || containsNonNumericOrSeparator(s)) {
return
}

// On deleting
if (s.length < beforeChangedText.length) {
Expand All @@ -94,16 +89,6 @@ class ExpiryDateEditText : OmiseEditText {
}
}

private fun containsNonNumericOrSeparator(input: CharSequence): Boolean {
// Define a regular expression pattern to match non-numeric characters and DATE_SEPARATOR
val pattern: Pattern = Pattern.compile("[^0-9" + Pattern.quote(DATE_SEPARATOR) + "]")

// Use a Matcher to find any non-numeric characters in the string
val matcher: Matcher = pattern.matcher(input)

return matcher.find()
}

private fun setExpiryDateText(dateString: String) {
removeTextChangedListener(textWatcher)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import co.omise.android.R
import co.omise.android.models.Source
import org.hamcrest.CoreMatchers.not
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
Expand Down Expand Up @@ -63,7 +62,6 @@ class TrueMoneyFormFragmentTest {
onView(withId(R.id.button_submit)).check(matches(not(isEnabled())))
}

@Ignore("Flaky test, it fails when run instrumented test on coverage workflow")
@Test
fun disableForm_disableFormWhenRequestSent() {
onView(withId(R.id.edit_phone_number)).perform(typeText("0812345678"), closeSoftKeyboard())
Expand Down
14 changes: 0 additions & 14 deletions sdk/src/test/java/co/omise/android/ui/ExpiryDateEditTextTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ class ExpiryDateEditTextTest {
assertEquals("12/34", editText.text.toString())
}

@Test
fun inputLengthExceedsMaxChars() {
val s = "123456" // 6 characters, assuming MAX_CHARS is 5
s.forEach { editText.append(it.toString()) }
assertEquals("12/34", editText.text.toString()) // assuming that exceeding chars will not be appended
}

@Test
fun inputContainsNonNumericOrSeparator() {
val s = "12ab" // 'ab' are non-numeric characters
s.forEach { editText.append(it.toString()) }
assertEquals("12/", editText.text.toString()) // assuming that non-numeric characters are not appended
}

@Test(expected = InputValidationException.EmptyInputException::class)
fun validate_emptyValue() {
"".forEach { editText.append(it.toString()) }
Expand Down

0 comments on commit a9738bb

Please sign in to comment.