Await room: add tests on LoadingRoomStateFlowFactory
This commit is contained in:
parent
1907745b1f
commit
f780e71026
1 changed files with 79 additions and 0 deletions
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.appnav.room
|
||||||
|
|
||||||
|
import app.cash.turbine.test
|
||||||
|
import com.google.common.truth.Truth
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomSummaryDataSource
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
|
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
|
||||||
|
import io.element.android.libraries.matrix.test.room.FakeRoomSummaryDataSource
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class LoadingRoomStateFlowFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `flow should emit Loading and then Loaded when there is a room in cache`() = runTest {
|
||||||
|
val room = FakeMatrixRoom(sessionId= A_SESSION_ID, roomId = A_ROOM_ID)
|
||||||
|
val matrixClient = FakeMatrixClient(A_SESSION_ID).apply {
|
||||||
|
givenGetRoomResult(A_ROOM_ID, room)
|
||||||
|
}
|
||||||
|
val flowFactory = LoadingRoomStateFlowFactory(matrixClient)
|
||||||
|
flowFactory
|
||||||
|
.create(this, A_ROOM_ID)
|
||||||
|
.test {
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Loading)
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Loaded(room))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `flow should emit Loading and then Loaded when there is a room in cache after SS is loaded`() = runTest {
|
||||||
|
val room = FakeMatrixRoom(sessionId= A_SESSION_ID, roomId = A_ROOM_ID)
|
||||||
|
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||||
|
val matrixClient = FakeMatrixClient(A_SESSION_ID, roomSummaryDataSource = roomSummaryDataSource)
|
||||||
|
val flowFactory = LoadingRoomStateFlowFactory(matrixClient)
|
||||||
|
flowFactory
|
||||||
|
.create(this, A_ROOM_ID)
|
||||||
|
.test {
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Loading)
|
||||||
|
matrixClient.givenGetRoomResult(A_ROOM_ID, room)
|
||||||
|
roomSummaryDataSource.postLoadingState(RoomSummaryDataSource.LoadingState.Loaded(1))
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Loaded(room))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `flow should emit Loading and then Error when there is no room in cache after SS is loaded`() = runTest {
|
||||||
|
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||||
|
val matrixClient = FakeMatrixClient(A_SESSION_ID, roomSummaryDataSource = roomSummaryDataSource)
|
||||||
|
val flowFactory = LoadingRoomStateFlowFactory(matrixClient)
|
||||||
|
flowFactory
|
||||||
|
.create(this, A_ROOM_ID)
|
||||||
|
.test {
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Loading)
|
||||||
|
roomSummaryDataSource.postLoadingState(RoomSummaryDataSource.LoadingState.Loaded(1))
|
||||||
|
Truth.assertThat(awaitItem()).isEqualTo(LoadingRoomState.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue