Skip to content

Commit 12e7172

Browse files
committed
Update tests
1 parent 1c78f96 commit 12e7172

File tree

4 files changed

+186
-8
lines changed

4 files changed

+186
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2024 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only
5+
* Please see LICENSE in the repository root for full details.
6+
*/
7+
8+
package io.element.android.features.call.test
9+
10+
import io.element.android.features.call.api.CurrentCall
11+
import io.element.android.features.call.api.CurrentCallObserver
12+
import kotlinx.coroutines.flow.MutableStateFlow
13+
14+
class FakeCurrentCallObserver(
15+
initialValue: CurrentCall = CurrentCall.None,
16+
) : CurrentCallObserver {
17+
override val currentCall = MutableStateFlow(initialValue)
18+
19+
fun setCurrentCall(value: CurrentCall) {
20+
currentCall.value = value
21+
}
22+
}

features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.element.android.features.poll.api.actions.EndPollAction
2727
import io.element.android.features.poll.api.actions.SendPollResponseAction
2828
import io.element.android.features.poll.test.actions.FakeEndPollAction
2929
import io.element.android.features.poll.test.actions.FakeSendPollResponseAction
30+
import io.element.android.features.roomcall.api.aStandByCallState
3031
import io.element.android.libraries.matrix.api.core.EventId
3132
import io.element.android.libraries.matrix.api.core.UniqueId
3233
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
@@ -685,5 +686,6 @@ internal fun TestScope.createTimelinePresenter(
685686
timelineController = TimelineController(room),
686687
resolveVerifiedUserSendFailurePresenter = { aResolveVerifiedUserSendFailureState() },
687688
typingNotificationPresenter = { aTypingNotificationState() },
689+
roomCallStatePresenter = { aStandByCallState() },
688690
)
689691
}

features/roomcall/impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
testImplementation(libs.test.truth)
3232
testImplementation(libs.test.turbine)
3333
testImplementation(projects.libraries.matrix.test)
34+
testImplementation(projects.features.call.test)
3435
testImplementation(projects.tests.testutils)
3536
testImplementation(libs.androidx.compose.ui.test.junit)
3637
testReleaseImplementation(libs.androidx.compose.ui.test.manifest)

features/roomcall/impl/src/test/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenterTest.kt

Lines changed: 161 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
package io.element.android.features.roomcall.impl
99

1010
import com.google.common.truth.Truth.assertThat
11+
import io.element.android.features.call.api.CurrentCall
12+
import io.element.android.features.call.api.CurrentCallObserver
13+
import io.element.android.features.call.test.FakeCurrentCallObserver
1114
import io.element.android.features.roomcall.api.RoomCallState
1215
import io.element.android.libraries.matrix.api.room.MatrixRoom
1316
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
@@ -17,30 +20,180 @@ import kotlinx.coroutines.test.runTest
1720
import org.junit.Test
1821

1922
class RoomCallStatePresenterTest {
23+
@Test
24+
fun `present - initial state`() = runTest {
25+
val room = FakeMatrixRoom(
26+
canUserJoinCallResult = { Result.success(false) },
27+
)
28+
val presenter = createRoomCallStatePresenter(matrixRoom = room)
29+
presenter.test {
30+
val initialState = awaitItem()
31+
assertThat(initialState).isEqualTo(
32+
RoomCallState.StandBy(
33+
canStartCall = false,
34+
)
35+
)
36+
}
37+
}
38+
39+
@Test
40+
fun `present - initial state - user can join call`() = runTest {
41+
val room = FakeMatrixRoom(
42+
canUserJoinCallResult = { Result.success(true) },
43+
)
44+
val presenter = createRoomCallStatePresenter(matrixRoom = room)
45+
presenter.test {
46+
skipItems(1)
47+
val initialState = awaitItem()
48+
assertThat(initialState).isEqualTo(
49+
RoomCallState.StandBy(
50+
canStartCall = true,
51+
)
52+
)
53+
}
54+
}
55+
2056
@Test
2157
fun `present - call is disabled if user cannot join it even if there is an ongoing call`() = runTest {
2258
val room = FakeMatrixRoom(
2359
canUserJoinCallResult = { Result.success(false) },
24-
canUserSendMessageResult = { _, _ -> Result.success(true) },
25-
canRedactOwnResult = { Result.success(true) },
26-
canRedactOtherResult = { Result.success(true) },
27-
typingNoticeResult = { Result.success(Unit) },
28-
canUserPinUnpinResult = { Result.success(true) },
2960
).apply {
3061
givenRoomInfo(aRoomInfo(hasRoomCall = true))
3162
}
3263
val presenter = createRoomCallStatePresenter(matrixRoom = room)
3364
presenter.test {
34-
val initialState = awaitItem()
35-
assertThat(initialState).isEqualTo(RoomCallState.OnGoing(canJoinCall = false))
65+
skipItems(1)
66+
assertThat(awaitItem()).isEqualTo(
67+
RoomCallState.OnGoing(
68+
canJoinCall = false,
69+
isUserInTheCall = false,
70+
isUserLocallyInTheCall = false,
71+
)
72+
)
73+
}
74+
}
75+
76+
@Test
77+
fun `present - user has joined the call on another session`() = runTest {
78+
val room = FakeMatrixRoom(
79+
canUserJoinCallResult = { Result.success(true) },
80+
).apply {
81+
givenRoomInfo(
82+
aRoomInfo(
83+
hasRoomCall = true,
84+
activeRoomCallParticipants = listOf(sessionId),
85+
)
86+
)
87+
}
88+
val presenter = createRoomCallStatePresenter(matrixRoom = room)
89+
presenter.test {
90+
skipItems(1)
91+
assertThat(awaitItem()).isEqualTo(
92+
RoomCallState.OnGoing(
93+
canJoinCall = true,
94+
isUserInTheCall = true,
95+
isUserLocallyInTheCall = false,
96+
)
97+
)
98+
}
99+
}
100+
101+
@Test
102+
fun `present - user has joined the call locally`() = runTest {
103+
val room = FakeMatrixRoom(
104+
canUserJoinCallResult = { Result.success(true) },
105+
).apply {
106+
givenRoomInfo(
107+
aRoomInfo(
108+
hasRoomCall = true,
109+
activeRoomCallParticipants = listOf(sessionId),
110+
)
111+
)
112+
}
113+
val presenter = createRoomCallStatePresenter(
114+
matrixRoom = room,
115+
currentCallObserver = FakeCurrentCallObserver(initialValue = CurrentCall.RoomCall(room.roomId)),
116+
)
117+
presenter.test {
118+
skipItems(1)
119+
assertThat(awaitItem()).isEqualTo(
120+
RoomCallState.OnGoing(
121+
canJoinCall = true,
122+
isUserInTheCall = true,
123+
isUserLocallyInTheCall = true,
124+
)
125+
)
126+
}
127+
}
128+
129+
@Test
130+
fun `present - user leaves the call`() = runTest {
131+
val room = FakeMatrixRoom(
132+
canUserJoinCallResult = { Result.success(true) },
133+
).apply {
134+
givenRoomInfo(
135+
aRoomInfo(
136+
hasRoomCall = true,
137+
activeRoomCallParticipants = listOf(sessionId),
138+
)
139+
)
140+
}
141+
val currentCallObserver = FakeCurrentCallObserver(initialValue = CurrentCall.RoomCall(room.roomId))
142+
val presenter = createRoomCallStatePresenter(
143+
matrixRoom = room,
144+
currentCallObserver = currentCallObserver
145+
)
146+
presenter.test {
147+
skipItems(1)
148+
assertThat(awaitItem()).isEqualTo(
149+
RoomCallState.OnGoing(
150+
canJoinCall = true,
151+
isUserInTheCall = true,
152+
isUserLocallyInTheCall = true,
153+
)
154+
)
155+
currentCallObserver.setCurrentCall(CurrentCall.None)
156+
assertThat(awaitItem()).isEqualTo(
157+
RoomCallState.OnGoing(
158+
canJoinCall = true,
159+
isUserInTheCall = true,
160+
isUserLocallyInTheCall = false,
161+
)
162+
)
163+
room.givenRoomInfo(
164+
aRoomInfo(
165+
hasRoomCall = true,
166+
activeRoomCallParticipants = emptyList(),
167+
)
168+
)
169+
assertThat(awaitItem()).isEqualTo(
170+
RoomCallState.OnGoing(
171+
canJoinCall = true,
172+
isUserInTheCall = false,
173+
isUserLocallyInTheCall = false,
174+
)
175+
)
176+
room.givenRoomInfo(
177+
aRoomInfo(
178+
hasRoomCall = false,
179+
activeRoomCallParticipants = emptyList(),
180+
)
181+
)
182+
assertThat(awaitItem()).isEqualTo(
183+
RoomCallState.StandBy(
184+
canStartCall = true,
185+
)
186+
)
36187
}
37188
}
38189

39190
private fun createRoomCallStatePresenter(
40-
matrixRoom: MatrixRoom
191+
matrixRoom: MatrixRoom,
192+
currentCallObserver: CurrentCallObserver = FakeCurrentCallObserver(),
41193
): RoomCallStatePresenter {
42194
return RoomCallStatePresenter(
43195
room = matrixRoom,
196+
currentCallObserver = currentCallObserver,
44197
)
45198
}
46199
}

0 commit comments

Comments
 (0)