Skip to content

Commit

Permalink
prevents copying item to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 13, 2024
1 parent 12a873e commit bc4b0e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
17 changes: 17 additions & 0 deletions composeApp/src/commonTest/kotlin/model/ItemWorkflowTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}
}

0 comments on commit bc4b0e4

Please sign in to comment.