@@ -28,11 +28,7 @@ import androidx.work.testing.WorkManagerTestInitHelper
28
28
import com.duckduckgo.app.CoroutineTestRule
29
29
import com.duckduckgo.app.notification.NotificationScheduler.ClearDataNotificationWorker
30
30
import com.duckduckgo.app.notification.NotificationScheduler.PrivacyNotificationWorker
31
- import com.duckduckgo.app.notification.NotificationScheduler.UseOurAppNotificationWorker
32
31
import com.duckduckgo.app.notification.model.SchedulableNotification
33
- import com.duckduckgo.app.statistics.Variant
34
- import com.duckduckgo.app.statistics.VariantManager
35
- import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
36
32
import com.nhaarman.mockitokotlin2.mock
37
33
import com.nhaarman.mockitokotlin2.whenever
38
34
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -49,10 +45,8 @@ class AndroidNotificationSchedulerTest {
49
45
@get:Rule
50
46
var coroutinesTestRule = CoroutineTestRule ()
51
47
52
- private val variantManager: VariantManager = mock()
53
48
private val clearNotification: SchedulableNotification = mock()
54
49
private val privacyNotification: SchedulableNotification = mock()
55
- private val useOurAppNotification: SchedulableNotification = mock()
56
50
57
51
private val context = InstrumentationRegistry .getInstrumentation().targetContext
58
52
private lateinit var workManager: WorkManager
@@ -65,9 +59,7 @@ class AndroidNotificationSchedulerTest {
65
59
testee = NotificationScheduler (
66
60
workManager,
67
61
clearNotification,
68
- privacyNotification,
69
- useOurAppNotification,
70
- variantManager
62
+ privacyNotification
71
63
)
72
64
}
73
65
@@ -84,7 +76,6 @@ class AndroidNotificationSchedulerTest {
84
76
85
77
@Test
86
78
fun whenPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
87
- setDefaultVariant()
88
79
whenever(privacyNotification.canShow()).thenReturn(true )
89
80
whenever(clearNotification.canShow()).thenReturn(true )
90
81
testee.scheduleNextNotification()
@@ -94,7 +85,6 @@ class AndroidNotificationSchedulerTest {
94
85
95
86
@Test
96
87
fun whenPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
97
- setDefaultVariant()
98
88
whenever(privacyNotification.canShow()).thenReturn(true )
99
89
whenever(clearNotification.canShow()).thenReturn(false )
100
90
testee.scheduleNextNotification()
@@ -104,7 +94,6 @@ class AndroidNotificationSchedulerTest {
104
94
105
95
@Test
106
96
fun whenPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationIsScheduled () = runBlocking<Unit > {
107
- setDefaultVariant()
108
97
whenever(privacyNotification.canShow()).thenReturn(false )
109
98
whenever(clearNotification.canShow()).thenReturn(true )
110
99
testee.scheduleNextNotification()
@@ -114,135 +103,13 @@ class AndroidNotificationSchedulerTest {
114
103
115
104
@Test
116
105
fun whenPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled () = runBlocking<Unit > {
117
- setDefaultVariant()
118
106
whenever(privacyNotification.canShow()).thenReturn(false )
119
107
whenever(clearNotification.canShow()).thenReturn(false )
120
108
testee.scheduleNextNotification()
121
109
122
110
assertNoNotificationScheduled()
123
111
}
124
112
125
- @Test
126
- fun whenInAppUsageVariantAndUseOurAppNotificationCanShowThenNotificationScheduled () = runBlocking {
127
- givenNoInactiveUserNotifications()
128
- setInAppUsageVariant()
129
- whenever(useOurAppNotification.canShow()).thenReturn(true )
130
-
131
- testee.scheduleNextNotification()
132
-
133
- assertNotificationScheduled(UseOurAppNotificationWorker ::class .jvmName, NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
134
- }
135
-
136
- @Test
137
- fun whenInAppUsageVariantUseOurAppNotificationCannotShowThenNoNotificationScheduled () = runBlocking {
138
- givenNoInactiveUserNotifications()
139
- setInAppUsageVariant()
140
- whenever(useOurAppNotification.canShow()).thenReturn(false )
141
-
142
- testee.scheduleNextNotification()
143
-
144
- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
145
- }
146
-
147
- @Test
148
- fun whenInAppUsageSecondControlVariantThenNoNotificationScheduled () = runBlocking<Unit > {
149
- setInAppUsageSecondControlVariant()
150
- whenever(useOurAppNotification.canShow()).thenReturn(true )
151
-
152
- testee.scheduleNextNotification()
153
-
154
- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
155
- }
156
-
157
- @Test
158
- fun whenInAppUsageControlVariantThenNoNotificationScheduled () = runBlocking<Unit > {
159
- givenNoInactiveUserNotifications()
160
- setInAppUsageControlVariant()
161
- whenever(useOurAppNotification.canShow()).thenReturn(true )
162
-
163
- testee.scheduleNextNotification()
164
-
165
- assertNoNotificationScheduled(NotificationScheduler .USE_OUR_APP_WORK_REQUEST_TAG )
166
- }
167
-
168
- @Test
169
- fun whenInAppUsageControlVariantAndPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
170
- setInAppUsageControlVariant()
171
- whenever(privacyNotification.canShow()).thenReturn(true )
172
- whenever(clearNotification.canShow()).thenReturn(true )
173
- testee.scheduleNextNotification()
174
-
175
- assertNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
176
- }
177
-
178
- @Test
179
- fun whenInAppUsageControlVariantAndPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled () = runBlocking<Unit > {
180
- setInAppUsageControlVariant()
181
- whenever(privacyNotification.canShow()).thenReturn(true )
182
- whenever(clearNotification.canShow()).thenReturn(false )
183
- testee.scheduleNextNotification()
184
-
185
- assertNotificationScheduled(PrivacyNotificationWorker ::class .jvmName)
186
- }
187
-
188
- @Test
189
- fun whenInAppUsageControlVariantAndPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationScheduled () = runBlocking<Unit > {
190
- setInAppUsageControlVariant()
191
- whenever(privacyNotification.canShow()).thenReturn(false )
192
- whenever(clearNotification.canShow()).thenReturn(true )
193
- testee.scheduleNextNotification()
194
-
195
- assertNotificationScheduled(ClearDataNotificationWorker ::class .jvmName)
196
- }
197
-
198
- @Test
199
- fun whenInAppUsageControlVariantAndPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled () = runBlocking<Unit > {
200
- setDefaultVariant()
201
- whenever(privacyNotification.canShow()).thenReturn(false )
202
- whenever(clearNotification.canShow()).thenReturn(false )
203
- testee.scheduleNextNotification()
204
-
205
- assertNoNotificationScheduled()
206
- }
207
-
208
- private suspend fun givenNoInactiveUserNotifications () {
209
- whenever(privacyNotification.canShow()).thenReturn(false )
210
- whenever(clearNotification.canShow()).thenReturn(false )
211
- }
212
-
213
- private fun setInAppUsageVariant () {
214
- whenever(variantManager.getVariant()).thenReturn(
215
- Variant (
216
- " test" ,
217
- features = listOf (
218
- VariantManager .VariantFeature .InAppUsage ,
219
- VariantManager .VariantFeature .RemoveDay1AndDay3Notifications ,
220
- VariantManager .VariantFeature .KillOnboarding
221
- ),
222
- filterBy = { true })
223
- )
224
- }
225
-
226
- private fun setInAppUsageSecondControlVariant () {
227
- whenever(variantManager.getVariant()).thenReturn(
228
- Variant (
229
- " test" ,
230
- features = listOf (
231
- VariantManager .VariantFeature .RemoveDay1AndDay3Notifications ,
232
- VariantManager .VariantFeature .KillOnboarding
233
- ),
234
- filterBy = { true })
235
- )
236
- }
237
-
238
- private fun setInAppUsageControlVariant () {
239
- whenever(variantManager.getVariant()).thenReturn(Variant (" test" , features = emptyList(), filterBy = { true }))
240
- }
241
-
242
- private fun setDefaultVariant () {
243
- whenever(variantManager.getVariant()).thenReturn(DEFAULT_VARIANT )
244
- }
245
-
246
113
private fun assertNotificationScheduled (workerName : String , tag : String = NotificationScheduler .UNUSED_APP_WORK_REQUEST_TAG ) {
247
114
assertTrue(getScheduledWorkers(tag).any { it.tags.contains(workerName) })
248
115
}
0 commit comments