Adds tests for selectedSpaceFlow and activeSpaceId

This commit is contained in:
ericdecanini 2022-07-21 09:39:12 +02:00
parent f770ae0653
commit 9a649b6093
1 changed files with 27 additions and 0 deletions

View File

@ -24,6 +24,8 @@ import im.vector.app.test.fakes.FakeUiStateRepository
import io.mockk.every import io.mockk.every
import io.mockk.justRun import io.mockk.justRun
import io.mockk.mockk import io.mockk.mockk
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Before import org.junit.Before
@ -113,4 +115,29 @@ internal class AppStateHandlerImplTest {
backstack.size shouldBe 0 backstack.size shouldBe 0
} }
@Test
fun `when setCurrentSpace, then space is emitted to selectedSpaceFlow`() = runTest {
appStateHandler.setCurrentSpace(spaceId, session)
val currentSpace = appStateHandler.getSelectedSpaceFlow().first().orNull()
currentSpace shouldBeEqualTo spaceSummary
}
@Test
fun `given current space exists, when getSafeActiveSpaceId, then return current space id`() {
appStateHandler.setCurrentSpace(spaceId, session)
val activeSpaceId = appStateHandler.getSafeActiveSpaceId()
activeSpaceId shouldBeEqualTo spaceId
}
@Test
fun `given current space doesn't exist, when getSafeActiveSpaceId, then return current null`() {
val activeSpaceId = appStateHandler.getSafeActiveSpaceId()
activeSpaceId shouldBe null
}
} }