Browse Source

Prevent empty items added

pull/10/head
Arkadii Ivanov 4 years ago
parent
commit
9993c56656
  1. 6
      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

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

@ -62,8 +62,10 @@ internal class TodoMainStoreProvider(
}
private fun addItem(state: State) {
dispatch(Result.TextChanged(text = ""))
database.add(text = state.text).subscribeScoped()
if (state.text.isNotEmpty()) {
dispatch(Result.TextChanged(text = ""))
database.add(text = state.text).subscribeScoped()
}
}
}

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