Skip to content

Commit 8d50789

Browse files
committed
Introduce runAndTestState extension on NotificationTroubleshootTest
1 parent 8434b50 commit 8d50789

File tree

13 files changed

+73
-144
lines changed

13 files changed

+73
-144
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ allprojects {
9393
// Fix compilation warning for annotations
9494
// See https://youtrack.jetbrains.com/issue/KT-73255/Change-defaulting-rule-for-annotations for more details
9595
freeCompilerArgs.add("-Xannotation-default-target=first-only")
96+
// Opt-in to context receivers
97+
freeCompilerArgs.add("-Xcontext-parameters")
9698
}
9799
}
98100
}

libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
package io.element.android.libraries.permissions.impl.troubleshoot
99

1010
import android.os.Build
11-
import app.cash.turbine.test
1211
import com.google.common.truth.Truth.assertThat
1312
import io.element.android.libraries.permissions.impl.action.FakePermissionActions
1413
import io.element.android.libraries.permissions.test.FakePermissionStateProvider
1514
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
1615
import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator
16+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1717
import io.element.android.services.toolbox.test.sdk.FakeBuildVersionSdkIntProvider
1818
import io.element.android.services.toolbox.test.strings.FakeStringProvider
1919
import kotlinx.coroutines.launch
@@ -29,10 +29,7 @@ class NotificationTroubleshootCheckPermissionTestTest {
2929
permissionActions = FakePermissionActions(),
3030
stringProvider = FakeStringProvider(),
3131
)
32-
launch {
33-
sut.run(this)
34-
}
35-
sut.state.test {
32+
sut.runAndTestState {
3633
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
3734
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
3835
val lastItem = awaitItem()
@@ -48,10 +45,7 @@ class NotificationTroubleshootCheckPermissionTestTest {
4845
permissionActions = FakePermissionActions(),
4946
stringProvider = FakeStringProvider(),
5047
)
51-
launch {
52-
sut.run(this)
53-
}
54-
sut.state.test {
48+
sut.runAndTestState {
5549
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
5650
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
5751
val lastItem = awaitItem()
@@ -75,16 +69,13 @@ class NotificationTroubleshootCheckPermissionTestTest {
7569
permissionActions = actions,
7670
stringProvider = FakeStringProvider(),
7771
)
78-
launch {
79-
sut.run(this)
80-
}
81-
sut.state.test {
72+
sut.runAndTestState {
8273
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
8374
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
8475
val lastItem = awaitItem()
8576
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true))
8677
// Quick fix
87-
launch {
78+
backgroundScope.launch {
8879
sut.quickFix(this, FakeNotificationTroubleshootNavigator())
8980
// Run the test again (IRL it will be done thanks to the resuming of the application)
9081
sut.run(this)
@@ -110,10 +101,7 @@ class NotificationTroubleshootCheckPermissionTestTest {
110101
permissionActions = actions,
111102
stringProvider = FakeStringProvider(),
112103
)
113-
launch {
114-
sut.run(this)
115-
}
116-
sut.state.test {
104+
sut.runAndTestState {
117105
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
118106
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
119107
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true))

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
package io.element.android.libraries.push.impl.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.push.test.FakeGetCurrentPushProvider
1312
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
13+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1414
import io.element.android.services.toolbox.test.strings.FakeStringProvider
15-
import kotlinx.coroutines.launch
1615
import kotlinx.coroutines.test.runTest
1716
import org.junit.Test
1817

@@ -23,10 +22,7 @@ class CurrentPushProviderTestTest {
2322
getCurrentPushProvider = FakeGetCurrentPushProvider("foo"),
2423
stringProvider = FakeStringProvider(),
2524
)
26-
launch {
27-
sut.run(this)
28-
}
29-
sut.state.test {
25+
sut.runAndTestState {
3026
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
3127
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
3228
val lastItem = awaitItem()
@@ -41,10 +37,7 @@ class CurrentPushProviderTestTest {
4137
getCurrentPushProvider = FakeGetCurrentPushProvider(null),
4238
stringProvider = FakeStringProvider(),
4339
)
44-
launch {
45-
sut.run(this)
46-
}
47-
sut.state.test {
40+
sut.runAndTestState {
4841
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
4942
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
5043
val lastItem = awaitItem()

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77

88
package io.element.android.libraries.push.impl.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.matrix.test.A_USER_ID
1312
import io.element.android.libraries.matrix.test.A_USER_ID_2
1413
import io.element.android.libraries.matrix.test.FakeMatrixClient
1514
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator
1615
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
16+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1717
import io.element.android.services.toolbox.test.strings.FakeStringProvider
1818
import io.element.android.tests.testutils.lambda.lambdaRecorder
1919
import kotlinx.collections.immutable.persistentListOf
2020
import kotlinx.coroutines.flow.MutableStateFlow
21-
import kotlinx.coroutines.launch
2221
import kotlinx.coroutines.test.runTest
2322
import org.junit.Test
2423

@@ -57,10 +56,7 @@ class IgnoredUsersTestTest {
5756
),
5857
stringProvider = FakeStringProvider(),
5958
)
60-
backgroundScope.launch {
61-
sut.run(this)
62-
}
63-
sut.state.test {
59+
sut.runAndTestState {
6460
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
6561
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
6662
val lastItem = awaitItem()
@@ -76,10 +72,7 @@ class IgnoredUsersTestTest {
7672
),
7773
stringProvider = FakeStringProvider(),
7874
)
79-
backgroundScope.launch {
80-
sut.run(this)
81-
}
82-
sut.state.test {
75+
sut.runAndTestState {
8376
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
8477
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
8578
val lastItem = awaitItem()

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
package io.element.android.libraries.push.impl.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator
1312
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer
1413
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
14+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1515
import io.element.android.services.toolbox.test.strings.FakeStringProvider
1616
import io.element.android.tests.testutils.lambda.lambdaRecorder
17-
import kotlinx.coroutines.launch
1817
import kotlinx.coroutines.test.runTest
1918
import org.junit.Test
2019

@@ -31,10 +30,7 @@ class NotificationTestTest {
3130
fun `test NotificationTest notification cannot be displayed`() = runTest {
3231
fakeNotificationDisplayer.displayDiagnosticNotificationResult = lambdaRecorder { _ -> false }
3332
val sut = createNotificationTest()
34-
launch {
35-
sut.run(this)
36-
}
37-
sut.state.test {
33+
sut.runAndTestState {
3834
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
3935
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
4036
assertThat(awaitItem().status).isInstanceOf(NotificationTroubleshootTestState.Status.Failure::class.java)
@@ -44,10 +40,7 @@ class NotificationTestTest {
4440
@Test
4541
fun `test NotificationTest user does not click on notification`() = runTest {
4642
val sut = createNotificationTest()
47-
launch {
48-
sut.run(this)
49-
}
50-
sut.state.test {
43+
sut.runAndTestState {
5144
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
5245
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
5346
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.WaitingForUser)
@@ -60,10 +53,7 @@ class NotificationTestTest {
6053
@Test
6154
fun `test NotificationTest user clicks on notification`() = runTest {
6255
val sut = createNotificationTest()
63-
launch {
64-
sut.run(this)
65-
}
66-
sut.state.test {
56+
sut.runAndTestState {
6757
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
6858
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
6959
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.WaitingForUser)

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package io.element.android.libraries.push.impl.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.matrix.test.AN_EXCEPTION
1312
import io.element.android.libraries.matrix.test.A_FAILURE_REASON
@@ -16,10 +15,10 @@ import io.element.android.libraries.push.test.FakePushService
1615
import io.element.android.libraries.pushproviders.test.FakePushProvider
1716
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
1817
import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator
18+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1919
import io.element.android.services.toolbox.test.strings.FakeStringProvider
2020
import io.element.android.services.toolbox.test.systemclock.FakeSystemClock
2121
import io.element.android.tests.testutils.lambda.lambdaRecorder
22-
import kotlinx.coroutines.launch
2322
import kotlinx.coroutines.test.runTest
2423
import org.junit.Test
2524

@@ -33,10 +32,7 @@ class PushLoopbackTestTest {
3332
clock = FakeSystemClock(),
3433
stringProvider = FakeStringProvider(),
3534
)
36-
launch {
37-
sut.run(this)
38-
}
39-
sut.state.test {
35+
sut.runAndTestState {
4036
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
4137
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
4238
val lastItem = awaitItem()
@@ -57,10 +53,7 @@ class PushLoopbackTestTest {
5753
clock = FakeSystemClock(),
5854
stringProvider = FakeStringProvider(),
5955
)
60-
launch {
61-
sut.run(this)
62-
}
63-
sut.state.test {
56+
sut.runAndTestState {
6457
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
6558
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
6659
val lastItem = awaitItem()
@@ -90,10 +83,7 @@ class PushLoopbackTestTest {
9083
clock = FakeSystemClock(),
9184
stringProvider = FakeStringProvider(),
9285
)
93-
launch {
94-
sut.run(this)
95-
}
96-
sut.state.test {
86+
sut.runAndTestState {
9787
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
9888
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
9989
val lastItem = awaitItem()
@@ -116,10 +106,7 @@ class PushLoopbackTestTest {
116106
clock = FakeSystemClock(),
117107
stringProvider = FakeStringProvider(),
118108
)
119-
launch {
120-
sut.run(this)
121-
}
122-
sut.state.test {
109+
sut.runAndTestState {
123110
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
124111
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
125112
val lastItem = awaitItem()
@@ -140,10 +127,7 @@ class PushLoopbackTestTest {
140127
clock = FakeSystemClock(),
141128
stringProvider = FakeStringProvider(),
142129
)
143-
launch {
144-
sut.run(this)
145-
}
146-
sut.state.test {
130+
sut.runAndTestState {
147131
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
148132
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
149133
val lastItem = awaitItem()
@@ -164,10 +148,7 @@ class PushLoopbackTestTest {
164148
clock = FakeSystemClock(),
165149
stringProvider = FakeStringProvider(),
166150
)
167-
launch {
168-
sut.run(this)
169-
}
170-
sut.state.test {
151+
sut.runAndTestState {
171152
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
172153
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
173154
val lastItem = awaitItem()

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
package io.element.android.libraries.push.impl.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.pushproviders.test.FakePushProvider
1312
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
13+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1414
import io.element.android.services.toolbox.test.strings.FakeStringProvider
15-
import kotlinx.coroutines.launch
1615
import kotlinx.coroutines.test.runTest
1716
import org.junit.Test
1817

@@ -23,10 +22,7 @@ class PushProvidersTestTest {
2322
pushProviders = emptySet(),
2423
stringProvider = FakeStringProvider(),
2524
)
26-
launch {
27-
sut.run(this)
28-
}
29-
sut.state.test {
25+
sut.runAndTestState {
3026
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
3127
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
3228
val lastItem = awaitItem()
@@ -45,10 +41,7 @@ class PushProvidersTestTest {
4541
),
4642
stringProvider = FakeStringProvider(),
4743
)
48-
launch {
49-
sut.run(this)
50-
}
51-
sut.state.test {
44+
sut.runAndTestState {
5245
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
5346
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
5447
val lastItem = awaitItem()

libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
package io.element.android.libraries.pushproviders.firebase.troubleshoot
99

10-
import app.cash.turbine.test
1110
import com.google.common.truth.Truth.assertThat
1211
import io.element.android.libraries.pushproviders.firebase.FakeIsPlayServiceAvailable
1312
import io.element.android.libraries.pushproviders.firebase.FirebaseConfig
1413
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
1514
import io.element.android.libraries.troubleshoot.api.test.TestFilterData
15+
import io.element.android.libraries.troubleshoot.test.runAndTestState
1616
import io.element.android.services.toolbox.test.strings.FakeStringProvider
17-
import kotlinx.coroutines.launch
1817
import kotlinx.coroutines.test.runTest
1918
import org.junit.Test
2019

@@ -25,10 +24,7 @@ class FirebaseAvailabilityTestTest {
2524
isPlayServiceAvailable = FakeIsPlayServiceAvailable(true),
2625
stringProvider = FakeStringProvider(),
2726
)
28-
launch {
29-
sut.run(this)
30-
}
31-
sut.state.test {
27+
sut.runAndTestState {
3228
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false))
3329
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
3430
val lastItem = awaitItem()
@@ -42,10 +38,7 @@ class FirebaseAvailabilityTestTest {
4238
isPlayServiceAvailable = FakeIsPlayServiceAvailable(false),
4339
stringProvider = FakeStringProvider(),
4440
)
45-
launch {
46-
sut.run(this)
47-
}
48-
sut.state.test {
41+
sut.runAndTestState {
4942
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false))
5043
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
5144
val lastItem = awaitItem()

0 commit comments

Comments
 (0)