diff --git a/forage-android/src/main/java/com/joinforage/forage/android/core/element/state/ElementState.kt b/forage-android/src/main/java/com/joinforage/forage/android/core/element/state/ElementState.kt index ce4158df..e6efe05a 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/core/element/state/ElementState.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/core/element/state/ElementState.kt @@ -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 ) diff --git a/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateManagerTest.kt b/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateManagerTest.kt index 628ece96..0f8677b9 100644 --- a/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateManagerTest.kt +++ b/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateManagerTest.kt @@ -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) @@ -58,7 +70,7 @@ class ElementStateManagerTest { } @Test - fun testChangeFocus() { + fun testChangeFocusPIN() { val manager = PinElementStateManager.forEmptyInput() var state = manager.getState() @@ -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) + } } diff --git a/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateTest.kt b/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateTest.kt new file mode 100644 index 00000000..f230678d --- /dev/null +++ b/forage-android/src/test/java/com/joinforage/forage/android/core/element/state/ElementStateTest.kt @@ -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()) + } +}