Skip to content

Commit

Permalink
Merge pull request #1225 from square/joshwilliams/text-controller-tes…
Browse files Browse the repository at this point in the history
…t-coverage

Improves `TextController` test coverage
  • Loading branch information
rjrjr authored Oct 29, 2024
2 parents ce389b6 + 9e4c7f1 commit b91ad6c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions workflow-ui/core-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
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

@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")
Expand Down

0 comments on commit b91ad6c

Please sign in to comment.