@@ -36,18 +36,21 @@ import io.element.android.libraries.matrix.test.A_SESSION_ID
36
36
import io.element.android.libraries.matrix.test.FakeMatrixClient
37
37
import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
38
38
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
39
+ import io.element.android.libraries.matrix.test.sync.FakeSyncService
39
40
import io.element.android.libraries.matrix.test.widget.FakeMatrixWidgetDriver
40
41
import io.element.android.libraries.network.useragent.UserAgentProvider
41
42
import io.element.android.services.analytics.api.ScreenTracker
42
43
import io.element.android.services.analytics.test.FakeScreenTracker
43
44
import io.element.android.services.toolbox.api.systemclock.SystemClock
44
45
import io.element.android.tests.testutils.WarmUpRule
45
46
import io.element.android.tests.testutils.consumeItemsUntilTimeout
47
+ import io.element.android.tests.testutils.lambda.assert
46
48
import io.element.android.tests.testutils.lambda.lambdaRecorder
47
49
import io.element.android.tests.testutils.lambda.value
48
50
import io.element.android.tests.testutils.testCoroutineDispatchers
49
51
import kotlinx.coroutines.ExperimentalCoroutinesApi
50
52
import kotlinx.coroutines.cancelAndJoin
53
+ import kotlinx.coroutines.flow.MutableStateFlow
51
54
import kotlinx.coroutines.launch
52
55
import kotlinx.coroutines.sync.Mutex
53
56
import kotlinx.coroutines.test.TestScope
@@ -86,8 +89,9 @@ class CallScreenPresenterTest {
86
89
@Test
87
90
fun `present - with CallType RoomCall sets call as active, loads URL, runs WidgetDriver and notifies the other clients a call started` () = runTest {
88
91
val sendCallNotificationIfNeededLambda = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
92
+ val syncService = FakeSyncService (MutableStateFlow (SyncState .Running ))
89
93
val fakeRoom = FakeMatrixRoom (sendCallNotificationIfNeededResult = sendCallNotificationIfNeededLambda)
90
- val client = FakeMatrixClient ().apply {
94
+ val client = FakeMatrixClient (syncService = syncService ).apply {
91
95
givenGetRoomResult(A_ROOM_ID , fakeRoom)
92
96
}
93
97
val widgetDriver = FakeMatrixWidgetDriver ()
@@ -216,7 +220,12 @@ class CallScreenPresenterTest {
216
220
fun `present - automatically starts the Matrix client sync when on RoomCall` () = runTest {
217
221
val navigator = FakeCallScreenNavigator ()
218
222
val widgetDriver = FakeMatrixWidgetDriver ()
219
- val matrixClient = FakeMatrixClient ()
223
+ val syncStateFlow = MutableStateFlow (SyncState .Idle )
224
+ val startSyncLambda = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
225
+ val syncService = FakeSyncService (syncStateFlow = syncStateFlow).apply {
226
+ this .startSyncLambda = startSyncLambda
227
+ }
228
+ val matrixClient = FakeMatrixClient (syncService = syncService)
220
229
val presenter = createCallScreenPresenter(
221
230
callType = CallType .RoomCall (A_SESSION_ID , A_ROOM_ID ),
222
231
widgetDriver = widgetDriver,
@@ -230,7 +239,7 @@ class CallScreenPresenterTest {
230
239
}.test {
231
240
consumeItemsUntilTimeout()
232
241
233
- assertThat(matrixClient.syncService().syncState.value).isEqualTo( SyncState . Running )
242
+ assert (startSyncLambda).isCalledOnce( )
234
243
235
244
cancelAndIgnoreRemainingEvents()
236
245
}
@@ -240,7 +249,12 @@ class CallScreenPresenterTest {
240
249
fun `present - automatically stops the Matrix client sync on dispose` () = runTest {
241
250
val navigator = FakeCallScreenNavigator ()
242
251
val widgetDriver = FakeMatrixWidgetDriver ()
243
- val matrixClient = FakeMatrixClient ()
252
+ val syncStateFlow = MutableStateFlow (SyncState .Running )
253
+ val stopSyncLambda = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
254
+ val syncService = FakeSyncService (syncStateFlow = syncStateFlow).apply {
255
+ this .stopSyncLambda = stopSyncLambda
256
+ }
257
+ val matrixClient = FakeMatrixClient (syncService = syncService)
244
258
val presenter = createCallScreenPresenter(
245
259
callType = CallType .RoomCall (A_SESSION_ID , A_ROOM_ID ),
246
260
widgetDriver = widgetDriver,
@@ -262,7 +276,7 @@ class CallScreenPresenterTest {
262
276
263
277
job.cancelAndJoin()
264
278
265
- assertThat(matrixClient.syncService().syncState.value).isEqualTo( SyncState . Terminated )
279
+ assert (stopSyncLambda).isCalledOnce( )
266
280
}
267
281
268
282
private fun TestScope.createCallScreenPresenter (
0 commit comments