Skip to content

Commit

Permalink
[FX-780] Fix isValid initial value for PIN bug (#136)
Browse files Browse the repository at this point in the history
* Set `isValid = false` in INITIAL_PIN_ELEMENT_STATE

See details in this linear ticket:
https://linear.app/joinforage/issue/FX-780/fix-isvalid-default-state-in-android-sdk#comment-fdd01c3a

---------

Co-authored-by: dleis612 <[email protected]>
  • Loading branch information
devinmorgan and dleis612 authored Dec 5, 2023
1 parent c351e7a commit 80d3ebf
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal val INITIAL_PIN_ELEMENT_STATE = PinElementStateDto(
isFocused = false,
isBlurred = true,
isEmpty = true,
isValid = true,
isValid = false,
isComplete = false,
validationError = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ import org.junit.Test
class ElementStateManagerTest {

@Test
fun testGetState() {
fun testGetStatePIN() {
val manager = PinElementStateManager.forEmptyInput()
val state = manager.getState()
assertThat(state.isFocused).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isFocused)
assertThat(state.isBlurred).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isBlurred)
assertThat(state.isEmpty).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isEmpty)
assertThat(state.isValid).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isValid)
assertThat(state.isComplete).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isComplete)
assertThat(state.validationError).isEqualTo(INITIAL_PIN_ELEMENT_STATE.validationError)
}

@Test
fun testGetStatePAN() {
val manager = PanElementStateManager.forEmptyInput()
val state = manager.getState()
assertThat(state.isFocused).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isFocused)
Expand Down Expand Up @@ -58,7 +70,7 @@ class ElementStateManagerTest {
}

@Test
fun testChangeFocus() {
fun testChangeFocusPIN() {
val manager = PinElementStateManager.forEmptyInput()
var state = manager.getState()

Expand All @@ -82,4 +94,32 @@ class ElementStateManagerTest {
assertThat(state.isValid).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isValid)
assertThat(state.isComplete).isEqualTo(INITIAL_PIN_ELEMENT_STATE.isComplete)
}

@Test
fun testChangeFocusPAN() {
val manager = PanElementStateManager.forEmptyInput()
var state = manager.getState()

// focus

// only focus and blur should change
manager.changeFocus(true)
state = manager.getState()
assertThat(state.isFocused).isTrue
assertThat(state.isBlurred).isFalse
assertThat(state.isEmpty).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isEmpty)
assertThat(state.isValid).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isValid)
assertThat(state.isComplete).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isComplete)
assertThat(state.derivedCardInfo).isEqualTo(INITIAL_PAN_ELEMENT_STATE.derivedCardInfo)

// unfocus
manager.changeFocus(false)
state = manager.getState()
assertThat(state.isFocused).isFalse
assertThat(state.isBlurred).isTrue
assertThat(state.isEmpty).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isEmpty)
assertThat(state.isValid).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isValid)
assertThat(state.isComplete).isEqualTo(INITIAL_PAN_ELEMENT_STATE.isComplete)
assertThat(state.derivedCardInfo).isEqualTo(INITIAL_PAN_ELEMENT_STATE.derivedCardInfo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.joinforage.forage.android.core.element.state

import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class ElementStateTest {

@Test
fun testInitialPinElementState() {
assertThat(INITIAL_PIN_ELEMENT_STATE.isFocused).isFalse
assertThat(INITIAL_PIN_ELEMENT_STATE.isBlurred).isTrue
assertThat(INITIAL_PIN_ELEMENT_STATE.isEmpty).isTrue
assertThat(INITIAL_PIN_ELEMENT_STATE.isValid).isFalse
assertThat(INITIAL_PIN_ELEMENT_STATE.isComplete).isFalse
assertThat(INITIAL_PIN_ELEMENT_STATE.validationError).isNull()
}

@Test
fun testInitialPanElementState() {
assertThat(INITIAL_PAN_ELEMENT_STATE.isFocused).isFalse
assertThat(INITIAL_PAN_ELEMENT_STATE.isBlurred).isTrue
assertThat(INITIAL_PAN_ELEMENT_STATE.isEmpty).isTrue
assertThat(INITIAL_PAN_ELEMENT_STATE.isValid).isTrue
assertThat(INITIAL_PAN_ELEMENT_STATE.isComplete).isFalse
assertThat(INITIAL_PAN_ELEMENT_STATE.validationError).isNull()
assertThat(INITIAL_PAN_ELEMENT_STATE.derivedCardInfo).isEqualTo(DerivedCardInfoDto())
}
}

0 comments on commit 80d3ebf

Please sign in to comment.