|
1 | 1 | package com.squareup.workflow1.ui
|
2 | 2 |
|
| 3 | +import app.cash.turbine.test |
| 4 | +import com.google.common.truth.Truth.assertThat |
| 5 | +import kotlinx.coroutines.test.runTest |
3 | 6 | import org.junit.Test
|
4 | 7 | import kotlin.test.assertEquals
|
5 | 8 | import kotlin.test.assertNotEquals
|
6 | 9 |
|
7 | 10 | @OptIn(WorkflowUiExperimentalApi::class)
|
8 | 11 | internal class TextControllerTest {
|
9 | 12 |
|
| 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 | + |
10 | 40 | @Test fun `equals works with the same value`() {
|
11 | 41 | val controller1 = TextController(initialValue = "apple")
|
12 | 42 | val controller2 = TextController(initialValue = "apple")
|
|
0 commit comments