Add unit test on SpaceState
This commit is contained in:
parent
b9638fb396
commit
145306230a
2 changed files with 49 additions and 1 deletions
|
|
@ -55,6 +55,7 @@ fun aSpaceState(
|
||||||
children: List<SpaceRoom> = emptyList(),
|
children: List<SpaceRoom> = emptyList(),
|
||||||
seenSpaceInvites: Set<RoomId> = emptySet(),
|
seenSpaceInvites: Set<RoomId> = emptySet(),
|
||||||
joiningRooms: Set<RoomId> = emptySet(),
|
joiningRooms: Set<RoomId> = emptySet(),
|
||||||
|
joinActions: Map<RoomId, AsyncAction<Unit>> = joiningRooms.associateWith { AsyncAction.Loading },
|
||||||
hideInvitesAvatar: Boolean = false,
|
hideInvitesAvatar: Boolean = false,
|
||||||
hasMoreToLoad: Boolean = false,
|
hasMoreToLoad: Boolean = false,
|
||||||
acceptDeclineInviteState: AcceptDeclineInviteState = anAcceptDeclineInviteState(),
|
acceptDeclineInviteState: AcceptDeclineInviteState = anAcceptDeclineInviteState(),
|
||||||
|
|
@ -64,7 +65,7 @@ fun aSpaceState(
|
||||||
seenSpaceInvites = seenSpaceInvites.toImmutableSet(),
|
seenSpaceInvites = seenSpaceInvites.toImmutableSet(),
|
||||||
hideInvitesAvatar = hideInvitesAvatar,
|
hideInvitesAvatar = hideInvitesAvatar,
|
||||||
hasMoreToLoad = hasMoreToLoad,
|
hasMoreToLoad = hasMoreToLoad,
|
||||||
joinActions = joiningRooms.associateWith { AsyncAction.Loading }.toImmutableMap(),
|
joinActions = joinActions.toImmutableMap(),
|
||||||
acceptDeclineInviteState = acceptDeclineInviteState,
|
acceptDeclineInviteState = acceptDeclineInviteState,
|
||||||
eventSink = {}
|
eventSink = {}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2025 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.space.impl.root
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.libraries.architecture.AsyncAction
|
||||||
|
import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID_2
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID_3
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class SpaceStateTest {
|
||||||
|
@Test
|
||||||
|
fun `test default state`() {
|
||||||
|
val state = aSpaceState()
|
||||||
|
assertThat(state.hasAnyFailure).isFalse()
|
||||||
|
assertThat(state.isJoining(A_ROOM_ID)).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test has failure`() {
|
||||||
|
val state = aSpaceState(
|
||||||
|
joinActions = mapOf(
|
||||||
|
A_ROOM_ID to AsyncAction.Uninitialized,
|
||||||
|
A_ROOM_ID_2 to AsyncAction.Failure(AN_EXCEPTION),
|
||||||
|
A_ROOM_ID_3 to AsyncAction.Success(Unit),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(state.hasAnyFailure).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test isJoining`() {
|
||||||
|
val state = aSpaceState(
|
||||||
|
joinActions = mapOf(
|
||||||
|
A_ROOM_ID to AsyncAction.Loading,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(state.isJoining(A_ROOM_ID)).isTrue()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue