Skip to content

Commit

Permalink
fix: handle revealing january expiration month as a single digit (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleon15 authored Feb 1, 2024
1 parent 68fe042 commit bf61540
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ class CardExpirationDateElement @JvmOverloads constructor(
monthRef: ElementValueReference,
yearRef: ElementValueReference
) {
val month = monthRef.getValue().toIntString()
var month = monthRef.getValue().toIntString()
val year = yearRef.getValue().toIntString()

// unique edge case not handled by beforeTextChanged since users can enter 10, 11 or 12
if (month == "1") month = "01"

setText("${month}${year?.takeLast(2)}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ class CardExpirationDateElementTests {
expectThat(cardExpirationDateElement.getText()).isEqualTo("08/30")
}

@Test
fun `can set value references for january as a single digit`() {
val monthRef = ElementValueReference { "1" }
val yearRef = ElementValueReference { "2030" }
cardExpirationDateElement.setValueRef(monthRef, yearRef)

expectThat(cardExpirationDateElement.getText()).isEqualTo("01/30")
}

@Test
fun `can set value references for both month and year as doubles`() {
val monthRef = ElementValueReference { "8.0" }
Expand Down

0 comments on commit bf61540

Please sign in to comment.