Skip to content

Commit

Permalink
test that itemcardmaker actually displays content
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 27, 2024
1 parent cda77d9 commit 815acc0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ kotlin {
implementation(kotlin("test"))
implementation(libs.kotest.assertions.core)
implementation(libs.kotest.assertions.json)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
}
}
val desktopTest by getting{
Expand All @@ -71,13 +73,15 @@ kotlin {
implementation(libs.androidx.test.junit)
implementation(libs.androidx.test.runner)
implementation(libs.kotest.assertions.core)
implementation(libs.compose.ui.test)
}
}
val androidUnitTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.robolectric)
implementation(libs.androidx.test.core.ktx)
implementation(libs.compose.ui.test)
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions composeApp/src/desktopTest/kotlin/view/ItemCardMakerTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package view

import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.runComposeUiTest
import model.Item
import org.junit.Test

class ItemCardMakerTest {

@OptIn(ExperimentalTestApi::class)
@Test
fun testItemCardMakerIncludesContent() = runComposeUiTest {
val itemContent = "::ITEMS CONTENT::"
val item = Item(itemContent)
val parentItems = mutableListOf<Item>()
val parentItemsState = mutableStateOf(parentItems)
val selectedCard = mutableStateOf<Item?>(null)
val statusText = mutableStateOf("")

setContent {
ItemCardMaker(
item,
parentItems,
parentItemsState,
selectedCard,
statusText
).Compose()
}

onNodeWithText(itemContent)
.assertIsDisplayed()
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ androidx-test-runner = { group = "androidx.test", name = "runner", version.ref =
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-ui-test = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }
kotest-assertions-json = { module = "io.kotest:kotest-assertions-json", version.ref = "kotest" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
Expand Down

0 comments on commit 815acc0

Please sign in to comment.