@@ -9,6 +9,8 @@ package io.element.android.libraries.push.impl.push
9
9
10
10
import app.cash.turbine.test
11
11
import com.google.common.truth.Truth.assertThat
12
+ import io.element.android.libraries.featureflag.api.FeatureFlags
13
+ import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
12
14
import io.element.android.libraries.matrix.api.MatrixClient
13
15
import io.element.android.libraries.matrix.api.sync.SyncState
14
16
import io.element.android.libraries.matrix.test.A_ROOM_ID
@@ -21,6 +23,7 @@ import io.element.android.libraries.matrix.test.sync.FakeSyncService
21
23
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableCallEvent
22
24
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
23
25
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
26
+ import io.element.android.tests.testutils.lambda.assert
24
27
import io.element.android.tests.testutils.lambda.lambdaRecorder
25
28
import io.element.android.tests.testutils.testCoroutineDispatchers
26
29
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -57,13 +60,24 @@ class SyncOnNotifiableEventTest {
57
60
private val notifiableEvent = aNotifiableMessageEvent()
58
61
private val incomingCallNotifiableEvent = aNotifiableCallEvent()
59
62
63
+ @Test
64
+ fun `when feature flag is disabled, nothing happens` () = runTest {
65
+ val sut = createSyncOnNotifiableEvent(client = client, isSyncOnPushEnabled = false )
66
+
67
+ sut(listOf (notifiableEvent))
68
+
69
+ assert (startSyncLambda).isNeverCalled()
70
+ assert (stopSyncLambda).isNeverCalled()
71
+ assert (subscribeToSyncLambda).isNeverCalled()
72
+ }
73
+
60
74
@OptIn(ExperimentalCoroutinesApi ::class )
61
75
@Test
62
76
fun `when feature flag is enabled, a ringing call waits until the room is in 'in-call' state` () = runTest {
63
77
val appForegroundStateService = FakeAppForegroundStateService (
64
78
initialForegroundValue = false ,
65
79
)
66
- val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
80
+ val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true )
67
81
68
82
val unlocked = AtomicBoolean (false )
69
83
launch {
@@ -83,7 +97,7 @@ class SyncOnNotifiableEventTest {
83
97
val appForegroundStateService = FakeAppForegroundStateService (
84
98
initialForegroundValue = false ,
85
99
)
86
- val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
100
+ val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true )
87
101
88
102
val unlocked = AtomicBoolean (false )
89
103
launch {
@@ -102,7 +116,7 @@ class SyncOnNotifiableEventTest {
102
116
val appForegroundStateService = FakeAppForegroundStateService (
103
117
initialForegroundValue = false ,
104
118
)
105
- val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
119
+ val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true )
106
120
107
121
appForegroundStateService.isSyncingNotificationEvent.test {
108
122
syncService.emitSyncState(SyncState .Running )
@@ -124,7 +138,7 @@ class SyncOnNotifiableEventTest {
124
138
val appForegroundStateService = FakeAppForegroundStateService (
125
139
initialForegroundValue = false ,
126
140
)
127
- val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
141
+ val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true )
128
142
129
143
appForegroundStateService.isSyncingNotificationEvent.test {
130
144
launch { sut(listOf (notifiableEvent)) }
@@ -143,13 +157,20 @@ class SyncOnNotifiableEventTest {
143
157
144
158
private fun TestScope.createSyncOnNotifiableEvent (
145
159
client : MatrixClient = FakeMatrixClient (),
160
+ isSyncOnPushEnabled : Boolean = true,
146
161
appForegroundStateService : FakeAppForegroundStateService = FakeAppForegroundStateService (
147
162
initialForegroundValue = true,
148
163
),
149
164
): SyncOnNotifiableEvent {
165
+ val featureFlagService = FakeFeatureFlagService (
166
+ initialState = mapOf (
167
+ FeatureFlags .SyncOnPush .key to isSyncOnPushEnabled
168
+ )
169
+ )
150
170
val matrixClientProvider = FakeMatrixClientProvider { Result .success(client) }
151
171
return SyncOnNotifiableEvent (
152
172
matrixClientProvider = matrixClientProvider,
173
+ featureFlagService = featureFlagService,
153
174
appForegroundStateService = appForegroundStateService,
154
175
dispatchers = testCoroutineDispatchers(),
155
176
)
0 commit comments