diff --git a/app/src/test/java/gq/kirmanak/mealient/extensions/FlowExtensionsKtTest.kt b/app/src/test/java/gq/kirmanak/mealient/extensions/FlowExtensionsKtTest.kt new file mode 100644 index 0000000..58f9101 --- /dev/null +++ b/app/src/test/java/gq/kirmanak/mealient/extensions/FlowExtensionsKtTest.kt @@ -0,0 +1,42 @@ +package gq.kirmanak.mealient.extensions + +import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.test.runTest +import org.junit.Test + +@OptIn(ExperimentalCoroutinesApi::class) +class FlowExtensionsKtTest { + + @Test + fun `when flow has an update then valueUpdatesOnly sends updated value`() = runTest { + val flow = flowOf(1, 2) + assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2)) + } + + @Test + fun `when flow has repeated values then valueUpdatesOnly sends updated value`() = runTest { + val flow = flowOf(1, 1, 1, 2) + assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2)) + } + + @Test + fun `when flow has one value then valueUpdatesOnly is empty`() = runTest { + val flow = flowOf(1) + assertThat(flow.valueUpdatesOnly().toList()).isEmpty() + } + + @Test + fun `when flow has two updates then valueUpdatesOnly sends both`() = runTest { + val flow = flowOf(1, 2, 1) + assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2, 1)) + } + + @Test + fun `when flow has three updates then valueUpdatesOnly sends all`() = runTest { + val flow = flowOf(1, 2, 1, 3) + assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2, 1, 3)) + } +} \ No newline at end of file