From 9b9cc3ae2dcb6182354848f1f01d2ef12873a2ed Mon Sep 17 00:00:00 2001 From: Florian Schuster Date: Sun, 10 May 2020 22:27:16 +0200 Subject: [PATCH] Added distinct states test --- .../florianschuster/control/ImplementationTest.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/control-core/src/test/kotlin/at/florianschuster/control/ImplementationTest.kt b/control-core/src/test/kotlin/at/florianschuster/control/ImplementationTest.kt index a6fcbc4a..f6f03666 100644 --- a/control-core/src/test/kotlin/at/florianschuster/control/ImplementationTest.kt +++ b/control-core/src/test/kotlin/at/florianschuster/control/ImplementationTest.kt @@ -82,7 +82,7 @@ internal class ImplementationTest { } @Test - fun `synchronous controller builder`() { + fun `synchronous controller`() { val counterSut = testCoroutineScope.createSynchronousController( tag = "counter", initialState = 0, @@ -96,6 +96,19 @@ internal class ImplementationTest { assertEquals(6, counterSut.currentState) } + @Test + fun `only distinct states are emitted`() { + val sut = testCoroutineScope.createSynchronousController( + 0, + reducer = { _, previousState -> previousState } + ) + val testFlow = sut.state.testIn(testCoroutineScope) + sut.dispatch(Unit) + sut.dispatch(Unit) + sut.dispatch(Unit) + testFlow expect emissionCount(1) // no state changes + } + @Test fun `collector receives latest and following states`() { val sut = testCoroutineScope.counterController() // 0