Skip to content

Commit

Permalink
Fix empty state for PIN
Browse files Browse the repository at this point in the history
  • Loading branch information
dleis612 committed Dec 3, 2023
1 parent bd5d961 commit 31900a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal val INITIAL_PIN_ELEMENT_STATE = ElementState<PinDetails>(
isFocused = false,
isBlurred = true,
isEmpty = true,
isValid = true,
isValid = false,
isComplete = false,
validationError = null,
details = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ 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)
// TODO: Compiler is very confused about accessing the state.details for the PIN
// This test fails because of it
assertThat(state.details).isEqualTo(INITIAL_PIN_ELEMENT_STATE.details)
}

@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 +73,7 @@ class ElementStateManagerTest {
}

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

Expand Down Expand Up @@ -90,4 +105,38 @@ class ElementStateManagerTest {
// is unique to PinDetails because it's an alias for `Nothing?`
assertThat(state.details as Any?).isEqualTo(INITIAL_PIN_ELEMENT_STATE.details)
}

@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)

// cast to Any? to avoid ambiguous overload issue that
// is unique to PinDetails because it's an alias for `Nothing?`
assertThat(state.details as Any?).isEqualTo(INITIAL_PAN_ELEMENT_STATE.details)

// 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)

// cast to Any? to avoid ambiguous overload issue that
// is unique to PinDetails because it's an alias for `Nothing?`
assertThat(state.details as Any?).isEqualTo(INITIAL_PAN_ELEMENT_STATE.details)
}
}

0 comments on commit 31900a8

Please sign in to comment.