diff --git a/composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt b/composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt index f2b21f7..07ac844 100644 --- a/composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt +++ b/composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt @@ -7,6 +7,8 @@ data class ItemWorkflow(val item: Item, val destination: Item, val actionType: A fun execute() { when(actionType) { ActionType.Copy -> { + if(destination.equals(item)) + return destination.add(item) } } diff --git a/composeApp/src/commonTest/kotlin/model/ItemWorkflowTest.kt b/composeApp/src/commonTest/kotlin/model/ItemWorkflowTest.kt index fce3d7b..6aa0ab0 100644 --- a/composeApp/src/commonTest/kotlin/model/ItemWorkflowTest.kt +++ b/composeApp/src/commonTest/kotlin/model/ItemWorkflowTest.kt @@ -1,5 +1,6 @@ package model +import io.kotest.matchers.collections.shouldBeEmpty import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf @@ -54,4 +55,20 @@ class ItemWorkflowTest { copyToParent.subItems.shouldContainExactly(child) item.subItems.shouldContainExactly(child) } + + @Test + fun `Cannot copy item to itself`() { + // Given + val item = Item("parent") + val child = Item("child") + item.add(child) + + val itemWorkflow = ItemWorkflow(child, child, ActionType.Copy) + + // When + itemWorkflow.execute() + + // Then + child.subItems.shouldBeEmpty() + } } \ No newline at end of file