Fix test
This commit is contained in:
parent
a0da28b1ec
commit
747467deb9
2 changed files with 5 additions and 66 deletions
|
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
|
|
||||||
import app.cash.molecule.RecompositionClock
|
|
||||||
import app.cash.molecule.moleculeFlow
|
|
||||||
import app.cash.turbine.test
|
|
||||||
import com.google.common.truth.Truth
|
|
||||||
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
|
|
||||||
import io.element.android.libraries.matrix.test.timeline.FakeMatrixTimeline
|
|
||||||
import kotlinx.coroutines.test.runTest
|
|
||||||
import org.junit.Test
|
|
||||||
import java.lang.IllegalStateException
|
|
||||||
|
|
||||||
class RoomFlowPresenterTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `present - fetches room members`() = runTest {
|
|
||||||
val fakeTimeline = FakeMatrixTimeline()
|
|
||||||
val room = FakeMatrixRoom(matrixTimeline = fakeTimeline)
|
|
||||||
val presenter = RoomFlowPresenter(room)
|
|
||||||
|
|
||||||
Truth.assertThat(room.areMembersFetched).isFalse()
|
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
Truth.assertThat(room.areMembersFetched).isTrue()
|
|
||||||
cancelAndIgnoreRemainingEvents()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `present - recovers from error while fetching room members`() = runTest {
|
|
||||||
val fakeTimeline = FakeMatrixTimeline()
|
|
||||||
val room = FakeMatrixRoom(matrixTimeline = fakeTimeline).apply {
|
|
||||||
givenFetchMemberResult(Result.failure(IllegalStateException("Some error")))
|
|
||||||
}
|
|
||||||
val presenter = RoomFlowPresenter(room)
|
|
||||||
|
|
||||||
Truth.assertThat(room.areMembersFetched).isFalse()
|
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
Truth.assertThat(room.areMembersFetched).isFalse()
|
|
||||||
cancelAndIgnoreRemainingEvents()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -28,21 +28,22 @@ fun anAppNavigationState(
|
||||||
spaceId: SpaceId? = MAIN_SPACE,
|
spaceId: SpaceId? = MAIN_SPACE,
|
||||||
roomId: RoomId? = null,
|
roomId: RoomId? = null,
|
||||||
threadId: ThreadId? = null,
|
threadId: ThreadId? = null,
|
||||||
|
owner: String = "a-owner",
|
||||||
): AppNavigationState {
|
): AppNavigationState {
|
||||||
if (sessionId == null) {
|
if (sessionId == null) {
|
||||||
return AppNavigationState.Root
|
return AppNavigationState.Root
|
||||||
}
|
}
|
||||||
val session = AppNavigationState.Session(sessionId)
|
val session = AppNavigationState.Session(owner, sessionId)
|
||||||
if (spaceId == null) {
|
if (spaceId == null) {
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
val space = AppNavigationState.Space(spaceId, session)
|
val space = AppNavigationState.Space(owner, spaceId, session)
|
||||||
if (roomId == null) {
|
if (roomId == null) {
|
||||||
return space
|
return space
|
||||||
}
|
}
|
||||||
val room = AppNavigationState.Room(roomId, space)
|
val room = AppNavigationState.Room(owner, roomId, space)
|
||||||
if (threadId == null) {
|
if (threadId == null) {
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
return AppNavigationState.Thread(threadId, room)
|
return AppNavigationState.Thread(owner, threadId, room)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue