diff --git a/workflow-ui/core-common/build.gradle.kts b/workflow-ui/core-common/build.gradle.kts index 811df65fb..6e559e19b 100644 --- a/workflow-ui/core-common/build.gradle.kts +++ b/workflow-ui/core-common/build.gradle.kts @@ -11,5 +11,7 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.kotlin.test.core) testImplementation(libs.kotlin.test.jdk) + testImplementation(libs.kotlinx.coroutines.test) testImplementation(libs.truth) + testImplementation(libs.turbine) } diff --git a/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/TextControllerTest.kt b/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/TextControllerTest.kt index 6c077d945..4fcb2ea06 100644 --- a/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/TextControllerTest.kt +++ b/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/TextControllerTest.kt @@ -1,5 +1,8 @@ package com.squareup.workflow1.ui +import app.cash.turbine.test +import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.test.runTest import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -7,6 +10,33 @@ import kotlin.test.assertNotEquals @OptIn(WorkflowUiExperimentalApi::class) internal class TextControllerTest { + @Test fun `does not emit initial value`() = runTest { + val controller = TextController() + controller.onTextChanged.test { + expectNoEvents() + } + } + + @Test fun `emits value when text changes`() = runTest { + val controller = TextController() + controller.onTextChanged.test { + controller.textValue = "apple" + assertThat(awaitItem()).isEqualTo("apple") + controller.textValue = "orange" + assertThat(awaitItem()).isEqualTo("orange") + } + } + + @Test fun `does not emit twice with the same value`() = runTest { + val controller = TextController() + controller.onTextChanged.test { + controller.textValue = "apple" + assertThat(awaitItem()).isEqualTo("apple") + controller.textValue = "apple" + expectNoEvents() + } + } + @Test fun `equals works with the same value`() { val controller1 = TextController(initialValue = "apple") val controller2 = TextController(initialValue = "apple")