Skip to content

Commit b91ad6c

Browse files
authored
Merge pull request #1225 from square/joshwilliams/text-controller-test-coverage
Improves `TextController` test coverage
2 parents ce389b6 + 9e4c7f1 commit b91ad6c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

workflow-ui/core-common/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ dependencies {
1111
testImplementation(libs.junit)
1212
testImplementation(libs.kotlin.test.core)
1313
testImplementation(libs.kotlin.test.jdk)
14+
testImplementation(libs.kotlinx.coroutines.test)
1415
testImplementation(libs.truth)
16+
testImplementation(libs.turbine)
1517
}

workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/TextControllerTest.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
package com.squareup.workflow1.ui
22

3+
import app.cash.turbine.test
4+
import com.google.common.truth.Truth.assertThat
5+
import kotlinx.coroutines.test.runTest
36
import org.junit.Test
47
import kotlin.test.assertEquals
58
import kotlin.test.assertNotEquals
69

710
@OptIn(WorkflowUiExperimentalApi::class)
811
internal class TextControllerTest {
912

13+
@Test fun `does not emit initial value`() = runTest {
14+
val controller = TextController()
15+
controller.onTextChanged.test {
16+
expectNoEvents()
17+
}
18+
}
19+
20+
@Test fun `emits value when text changes`() = runTest {
21+
val controller = TextController()
22+
controller.onTextChanged.test {
23+
controller.textValue = "apple"
24+
assertThat(awaitItem()).isEqualTo("apple")
25+
controller.textValue = "orange"
26+
assertThat(awaitItem()).isEqualTo("orange")
27+
}
28+
}
29+
30+
@Test fun `does not emit twice with the same value`() = runTest {
31+
val controller = TextController()
32+
controller.onTextChanged.test {
33+
controller.textValue = "apple"
34+
assertThat(awaitItem()).isEqualTo("apple")
35+
controller.textValue = "apple"
36+
expectNoEvents()
37+
}
38+
}
39+
1040
@Test fun `equals works with the same value`() {
1141
val controller1 = TextController(initialValue = "apple")
1242
val controller2 = TextController(initialValue = "apple")

0 commit comments

Comments
 (0)