mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 04:33:36 +00:00
Donations credit card formatting.
This commit is contained in:
committed by
Cody Henthorne
parent
16cbc971a5
commit
b8e16353ab
@@ -0,0 +1,39 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription.donate.card
|
||||
|
||||
import android.app.Application
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(ParameterizedRobolectricTestRunner::class)
|
||||
@Config(application = Application::class)
|
||||
class CreditCardExpirationTextWatcherBackspaceTest(
|
||||
private val beforeBackspace: String,
|
||||
private val textWatcherOutput: String
|
||||
) {
|
||||
|
||||
private val testSubject = CreditCardExpirationTextWatcher()
|
||||
|
||||
@Test
|
||||
fun getTextWatcherOutput() {
|
||||
val editable: Editable = SpannableStringBuilder(beforeBackspace.dropLast(1))
|
||||
testSubject.onTextChanged(null, 0, 0, 0)
|
||||
testSubject.afterTextChanged(editable)
|
||||
assertEquals(textWatcherOutput, editable.toString())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@ParameterizedRobolectricTestRunner.Parameters(name = "{index}: getTextWatcherOutput(..) = {0}, {1}")
|
||||
fun data(): Iterable<Array<Any>> = arrayListOf(
|
||||
arrayOf("12/23", "12/2"),
|
||||
arrayOf("12/2", "12/"),
|
||||
arrayOf("12/", "1"),
|
||||
arrayOf("1", "")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription.donate.card
|
||||
|
||||
import android.app.Application
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(ParameterizedRobolectricTestRunner::class)
|
||||
@Config(application = Application::class)
|
||||
class CreditCardExpirationTextWatcherTest(
|
||||
private val userInput: String,
|
||||
private val textWatcherOutput: String
|
||||
) {
|
||||
|
||||
private val testSubject = CreditCardExpirationTextWatcher()
|
||||
|
||||
@Test
|
||||
fun getTextWatcherOutput() {
|
||||
val editable: Editable = SpannableStringBuilder(userInput)
|
||||
testSubject.afterTextChanged(editable)
|
||||
assertEquals(textWatcherOutput, editable.toString())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@ParameterizedRobolectricTestRunner.Parameters(name = "{index}: getTextWatcherOutput(..) = {0}, {1}")
|
||||
fun data(): Iterable<Array<Any>> = arrayListOf(
|
||||
arrayOf("0", "0"),
|
||||
arrayOf("1", "1"),
|
||||
arrayOf("12", "12/"),
|
||||
arrayOf("02", "02/"),
|
||||
arrayOf("2", "02/"),
|
||||
arrayOf("12/", "12/"),
|
||||
arrayOf("12/1", "12/1"),
|
||||
arrayOf("15", "15")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription.donate.card
|
||||
|
||||
import android.app.Application
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(ParameterizedRobolectricTestRunner::class)
|
||||
@Config(application = Application::class)
|
||||
class CreditCardTextWatcherBackspaceTest(
|
||||
private val beforeBackspace: String,
|
||||
private val textWatcherOutput: String
|
||||
) {
|
||||
|
||||
private val testSubject = CreditCardTextWatcher()
|
||||
|
||||
@Test
|
||||
fun getTextWatcherOutput() {
|
||||
val editable: Editable = SpannableStringBuilder(beforeBackspace.dropLast(1))
|
||||
testSubject.onTextChanged(null, 0, 0, 0)
|
||||
testSubject.afterTextChanged(editable)
|
||||
assertEquals(textWatcherOutput, editable.toString())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@ParameterizedRobolectricTestRunner.Parameters(name = "{index}: getTextWatcherOutput(..) = {0}, {1}")
|
||||
fun data(): Iterable<Array<Any>> = arrayListOf(
|
||||
arrayOf("1234 ", "123"),
|
||||
arrayOf("1234 5", "1234 ")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription.donate.card
|
||||
|
||||
import android.app.Application
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(ParameterizedRobolectricTestRunner::class)
|
||||
@Config(application = Application::class)
|
||||
class CreditCardTextWatcherTest(
|
||||
private val userInput: String,
|
||||
private val textWatcherOutput: String
|
||||
) {
|
||||
|
||||
private val testSubject = CreditCardTextWatcher()
|
||||
|
||||
@Test
|
||||
fun getTextWatcherOutput() {
|
||||
val editable: Editable = SpannableStringBuilder(userInput)
|
||||
testSubject.afterTextChanged(editable)
|
||||
assertEquals(textWatcherOutput, editable.toString())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@ParameterizedRobolectricTestRunner.Parameters(name = "{index}: getTextWatcherOutput(..) = {0}, {1}")
|
||||
fun data(): Iterable<Array<Any>> = arrayListOf(
|
||||
// AMEX
|
||||
arrayOf("340", "340"),
|
||||
arrayOf("3400", "3400 "),
|
||||
arrayOf("34000", "3400 0"),
|
||||
arrayOf("3400000000", "3400 000000 "),
|
||||
arrayOf("34000000000", "3400 000000 0"),
|
||||
arrayOf("340000000000000", "3400 000000 00000"),
|
||||
// UNIONPAY
|
||||
arrayOf("620", "620"),
|
||||
arrayOf("6200", "6200 "),
|
||||
arrayOf("62000", "6200 0"),
|
||||
arrayOf("6200000000", "6200 0000 00"),
|
||||
arrayOf("6200000000000", "6200 0000 00000"),
|
||||
arrayOf("620000000000000", "6200 0000 0000 000"),
|
||||
arrayOf("6200000000000000", "6200 0000 0000 0000"),
|
||||
arrayOf("62000000000000000", "62000 00000 00000 00"),
|
||||
// OTHER
|
||||
arrayOf("550", "550"),
|
||||
arrayOf("5500", "5500 "),
|
||||
arrayOf("55000", "5500 0"),
|
||||
arrayOf("5500000000", "5500 0000 00"),
|
||||
arrayOf("55000000000", "5500 0000 000"),
|
||||
arrayOf("550000000000000", "5500 0000 0000 000"),
|
||||
arrayOf("5500000000000000", "5500 0000 0000 0000"),
|
||||
arrayOf("55000000000000000", "55000 00000 00000 00"),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user