Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ExpiryDateEditText error messages #3429

Merged
merged 4 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class ExpiryDateEditText @JvmOverloads constructor(
isDateValid = false
}

setErrorMessage(
resources.getString(
if (!expirationDate.isMonthValid) R.string.invalid_expiry_month else R.string.invalid_expiry_year
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
)
)
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
[email protected] = shouldShowError

formattedDate = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.view

import android.content.Context
import androidx.appcompat.view.ContextThemeWrapper
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
Expand All @@ -16,6 +17,7 @@ import kotlin.test.Test
*/
@RunWith(RobolectricTestRunner::class)
class ExpiryDateEditTextTest {
private val context: Context = ApplicationProvider.getApplicationContext<Context>()
private val expiryDateEditText = ExpiryDateEditText(
ContextThemeWrapper(
ApplicationProvider.getApplicationContext(),
Expand Down Expand Up @@ -185,6 +187,8 @@ class ExpiryDateEditTextTest {

assertThat(expiryDateEditText.shouldShowError)
.isTrue()
assertThat(expiryDateEditText.errorMessage)
.isEqualTo(context.getString(R.string.invalid_expiry_month))
assertThat(expiryDateEditText.text.toString())
.isEqualTo("14")
}
Expand All @@ -195,6 +199,8 @@ class ExpiryDateEditTextTest {

assertThat(expiryDateEditText.shouldShowError)
.isTrue()
assertThat(expiryDateEditText.errorMessage)
.isEqualTo(context.getString(R.string.invalid_expiry_month))
assertThat(expiryDateEditText.text.toString())
.isEqualTo("14/3")
}
Expand Down Expand Up @@ -226,6 +232,8 @@ class ExpiryDateEditTextTest {

assertThat(expiryDateEditText.shouldShowError)
.isTrue()
assertThat(expiryDateEditText.errorMessage)
.isEqualTo(context.getString(R.string.invalid_expiry_year))
assertThat(invocations)
.isEqualTo(0)
}
Expand All @@ -245,6 +253,8 @@ class ExpiryDateEditTextTest {
expiryDateEditText.append("12/12")
assertThat(expiryDateEditText.shouldShowError)
.isTrue()
assertThat(expiryDateEditText.errorMessage)
.isEqualTo(context.getString(R.string.invalid_expiry_year))

ViewTestUtils.sendDeleteKeyEvent(expiryDateEditText)
assertThat(expiryDateEditText.text.toString())
Expand All @@ -257,6 +267,17 @@ class ExpiryDateEditTextTest {
.isEqualTo(0)
}

@Test
fun inputCompleteDate_whenMonthInvalid_showsInvalidMonth() {
expiryDateEditText.append("15")
expiryDateEditText.append("50")

assertThat(expiryDateEditText.shouldShowError)
.isTrue()
assertThat(expiryDateEditText.errorMessage)
.isEqualTo(context.getString(R.string.invalid_expiry_month))
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
fun validatedDate_whenDataIsValid_returnsExpectedValues() {
// This test will be invalid if run after the year 2050. Please update the code.
Expand All @@ -278,7 +299,7 @@ class ExpiryDateEditTextTest {

@Test
fun validatedDate_whenDateIsValidFormatButExpired_returnsNull() {
// This test will be invalid if run after the year 2050. Please update the code.
// This test will be invalid if run after the year 2080. Please update the code.
assertThat(Calendar.getInstance().get(Calendar.YEAR) < 2080)
.isTrue()

Expand Down