fix(gift): 이름 입력 필터를 보정한다
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift
|
||||
|
||||
import android.app.Application
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class GiftSendInputFiltersTest {
|
||||
|
||||
@Test
|
||||
fun `이름 필터는 한글 조합 문자와 composing span을 보존한다`() {
|
||||
val marker = Any()
|
||||
val composing = SpannableString("ㄱ").apply {
|
||||
setSpan(marker, 0, length, Spanned.SPAN_COMPOSING)
|
||||
}
|
||||
|
||||
val unchanged = GiftSendInputFilters.senderName().filter(composing, 0, composing.length, EMPTY, 0, 0)
|
||||
|
||||
assertNull(unchanged)
|
||||
|
||||
val mixed = SpannableString("ㄱ1").apply {
|
||||
setSpan(marker, 0, 1, Spanned.SPAN_COMPOSING)
|
||||
}
|
||||
val filtered = GiftSendInputFilters.senderName().filter(mixed, 0, mixed.length, EMPTY, 0, 0)
|
||||
assertEquals("ㄱ", filtered.toString())
|
||||
assertTrue(filtered is Spanned)
|
||||
assertEquals(0, (filtered as Spanned).getSpanStart(marker))
|
||||
assertEquals(1, filtered.getSpanEnd(marker))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `이름 필터는 한글과 영문 외 문자를 제거한다`() {
|
||||
val filtered = GiftSendInputFilters.senderName().filter("홍Gil1 동!", 0, 8, EMPTY, 0, 0)
|
||||
|
||||
assertEquals("홍Gil동", filtered.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `휴대폰 필터는 ASCII 숫자 외 문자를 제거한다`() {
|
||||
val filtered = GiftSendInputFilters.phoneNumber().filter("011-가2", 0, 6, EMPTY, 0, 0)
|
||||
|
||||
assertEquals("012", filtered.toString())
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val EMPTY = SpannableString("")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user