Browse Source

Prevent empty items added

pull/10/head
Arkadii Ivanov 4 years ago
parent
commit
9993c56656
  1. 2
      examples/todoapp/common/main/src/commonMain/kotlin/example/todo/common/main/store/TodoMainStoreProvider.kt
  2. 9
      examples/todoapp/common/main/src/commonTest/kotlin/example/todo/common/main/store/TodoMainStoreTest.kt

2
examples/todoapp/common/main/src/commonMain/kotlin/example/todo/common/main/store/TodoMainStoreProvider.kt

@ -62,10 +62,12 @@ internal class TodoMainStoreProvider(
}
private fun addItem(state: State) {
if (state.text.isNotEmpty()) {
dispatch(Result.TextChanged(text = ""))
database.add(text = state.text).subscribeScoped()
}
}
}
private object ReducerImpl : Reducer<State, Result> {
override fun State.reduce(result: Result): State =

9
examples/todoapp/common/main/src/commonTest/kotlin/example/todo/common/main/store/TodoMainStoreTest.kt

@ -122,4 +122,13 @@ class TodoMainStoreTest {
assertEquals("", store.state.text)
}
@Test
fun GIVEN_no_text_entered_WHEN_Intent_AddItem_THEN_item_not_added() {
val store = provider.provide()
store.accept(Intent.AddItem)
assertEquals(0, store.state.items.size)
}
}

Loading…
Cancel
Save