Skip to content

Commit

Permalink
copy workflow puts item in destination without removing from original…
Browse files Browse the repository at this point in the history
… parent
  • Loading branch information
vextorspace committed Jul 13, 2024
1 parent 64c6cc4 commit 12a873e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
12 changes: 8 additions & 4 deletions composeApp/src/commonMain/kotlin/model/ItemWorkflow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package model
import kotlinx.serialization.Serializable

@Serializable
data class ItemWorkflow(val destination: Item, val actionType: ActionType = ActionType.Copy) {



data class ItemWorkflow(val item: Item, val destination: Item, val actionType: ActionType = ActionType.Copy) {
fun execute() {
when(actionType) {
ActionType.Copy -> {
destination.add(item)
}
}
}
}
27 changes: 24 additions & 3 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.shouldContainExactly
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import kotlin.test.Test
Expand All @@ -9,11 +10,12 @@ class ItemWorkflowTest {
@Test
fun `ItemWorkflow contains destination item`() {
// Given
val item = Item()
val destinationItem = Item()
val itemWorkflow = ItemWorkflow(destinationItem)
val itemWorkflow = ItemWorkflow(item, destinationItem)

// When
val destination = itemWorkflow.destination
val destination = itemWorkflow.item

// Then
destination.shouldBeInstanceOf<Item>()
Expand All @@ -22,8 +24,9 @@ class ItemWorkflowTest {
@Test
fun `ItemWorkflow contains actionType defaults to Copy`() {
// Given
val item = Item()
val destinationItem = Item()
val itemWorkflow = ItemWorkflow(destinationItem)
val itemWorkflow = ItemWorkflow(item, destinationItem)

// When
val actionType = itemWorkflow.actionType
Expand All @@ -33,4 +36,22 @@ class ItemWorkflowTest {

actionType.shouldBe(ActionType.Copy)
}

@Test
fun `When executing the copy action on an ItemWorkflow it should put a copy of the item in the destination`() {
// Given
val item = Item("parent")
val child = Item("child")
val copyToParent = Item("copy to parent")
item.add(child)

val itemWorkflow = ItemWorkflow(child, copyToParent, ActionType.Copy)

// When
itemWorkflow.execute()

// Then
copyToParent.subItems.shouldContainExactly(child)
item.subItems.shouldContainExactly(child)
}
}

0 comments on commit 12a873e

Please sign in to comment.