diff --git a/examples/todoapp/common/main/src/commonMain/kotlin/example/todo/common/main/store/TodoMainStoreProvider.kt b/examples/todoapp/common/main/src/commonMain/kotlin/example/todo/common/main/store/TodoMainStoreProvider.kt index 0036599e67..029c44320c 100644 --- a/examples/todoapp/common/main/src/commonMain/kotlin/example/todo/common/main/store/TodoMainStoreProvider.kt +++ b/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() + } } } diff --git a/examples/todoapp/common/main/src/commonTest/kotlin/example/todo/common/main/store/TodoMainStoreTest.kt b/examples/todoapp/common/main/src/commonTest/kotlin/example/todo/common/main/store/TodoMainStoreTest.kt index d716bad008..3d3b65ef2b 100644 --- a/examples/todoapp/common/main/src/commonTest/kotlin/example/todo/common/main/store/TodoMainStoreTest.kt +++ b/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) + } }