@@ -23,7 +23,11 @@ import com.duckduckgo.app.browser.senseofprotection.SenseOfProtectionExperiment
23
23
import com.duckduckgo.app.global.model.PrivacyShield.MALICIOUS
24
24
import com.duckduckgo.app.global.model.PrivacyShield.PROTECTED
25
25
import com.duckduckgo.app.global.model.PrivacyShield.UNPROTECTED
26
+ import com.duckduckgo.common.ui.experiments.visual.store.VisualDesignExperimentDataStore
27
+ import com.duckduckgo.common.ui.experiments.visual.store.VisualDesignExperimentDataStore.FeatureState
26
28
import com.duckduckgo.common.ui.store.AppTheme
29
+ import kotlinx.coroutines.flow.MutableStateFlow
30
+ import org.junit.Before
27
31
import org.junit.Test
28
32
import org.mockito.kotlin.mock
29
33
import org.mockito.kotlin.verify
@@ -32,13 +36,25 @@ import org.mockito.kotlin.whenever
32
36
class LottiePrivacyShieldAnimationHelperTest {
33
37
34
38
private val senseOfProtectionExperiment: SenseOfProtectionExperiment = mock()
39
+ private val visualDesignExperimentDataStore: VisualDesignExperimentDataStore = mock()
40
+ private val enabledVisualExperimentStateFlow = MutableStateFlow (FeatureState (isAvailable = true , isEnabled = true ))
41
+ private val disabledVisualExperimentStateFlow = MutableStateFlow (FeatureState (isAvailable = false , isEnabled = false ))
42
+
43
+ @Before
44
+ fun setup () {
45
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
46
+ disabledVisualExperimentStateFlow,
47
+ )
48
+ }
35
49
36
50
@Test
37
51
fun whenLightModeAndPrivacyShieldProtectedThenSetLightShieldAnimation () {
52
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
53
+
38
54
val holder: LottieAnimationView = mock()
39
55
val appTheme: AppTheme = mock()
40
56
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
41
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
57
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
42
58
43
59
testee.setAnimationView(holder, PROTECTED )
44
60
@@ -47,10 +63,12 @@ class LottiePrivacyShieldAnimationHelperTest {
47
63
48
64
@Test
49
65
fun whenDarkModeAndPrivacyShieldProtectedThenSetDarkShieldAnimation () {
66
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
67
+
50
68
val holder: LottieAnimationView = mock()
51
69
val appTheme: AppTheme = mock()
52
70
whenever(appTheme.isLightModeEnabled()).thenReturn(false )
53
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
71
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
54
72
55
73
testee.setAnimationView(holder, PROTECTED )
56
74
@@ -59,10 +77,12 @@ class LottiePrivacyShieldAnimationHelperTest {
59
77
60
78
@Test
61
79
fun whenLightModeAndPrivacyShieldUnProtectedThenUseLightAnimation () {
80
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
81
+
62
82
val holder: LottieAnimationView = mock()
63
83
val appTheme: AppTheme = mock()
64
84
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
65
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
85
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
66
86
67
87
testee.setAnimationView(holder, UNPROTECTED )
68
88
@@ -72,10 +92,12 @@ class LottiePrivacyShieldAnimationHelperTest {
72
92
73
93
@Test
74
94
fun whenDarkModeAndPrivacyShieldUnProtectedThenUseDarkAnimation () {
95
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
96
+
75
97
val holder: LottieAnimationView = mock()
76
98
val appTheme: AppTheme = mock()
77
99
whenever(appTheme.isLightModeEnabled()).thenReturn(false )
78
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
100
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
79
101
80
102
testee.setAnimationView(holder, UNPROTECTED )
81
103
@@ -85,10 +107,12 @@ class LottiePrivacyShieldAnimationHelperTest {
85
107
86
108
@Test
87
109
fun whenLightModeAndPrivacyShieldMaliciousThenUseLightAnimation () {
110
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
111
+
88
112
val holder: LottieAnimationView = mock()
89
113
val appTheme: AppTheme = mock()
90
114
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
91
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
115
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
92
116
93
117
testee.setAnimationView(holder, MALICIOUS )
94
118
@@ -98,10 +122,12 @@ class LottiePrivacyShieldAnimationHelperTest {
98
122
99
123
@Test
100
124
fun whenDarkModeAndPrivacyShieldMaliciousThenUseDarkAnimation () {
125
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
126
+
101
127
val holder: LottieAnimationView = mock()
102
128
val appTheme: AppTheme = mock()
103
129
whenever(appTheme.isLightModeEnabled()).thenReturn(false )
104
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
130
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
105
131
106
132
testee.setAnimationView(holder, MALICIOUS )
107
133
@@ -118,7 +144,7 @@ class LottiePrivacyShieldAnimationHelperTest {
118
144
val appTheme: AppTheme = mock()
119
145
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
120
146
121
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
147
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
122
148
123
149
testee.setAnimationView(holder, PROTECTED )
124
150
@@ -134,7 +160,7 @@ class LottiePrivacyShieldAnimationHelperTest {
134
160
val appTheme: AppTheme = mock()
135
161
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
136
162
137
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
163
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
138
164
139
165
testee.setAnimationView(holder, UNPROTECTED )
140
166
@@ -150,7 +176,7 @@ class LottiePrivacyShieldAnimationHelperTest {
150
176
val appTheme: AppTheme = mock()
151
177
whenever(appTheme.isLightModeEnabled()).thenReturn(false )
152
178
153
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
179
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
154
180
155
181
testee.setAnimationView(holder, PROTECTED )
156
182
@@ -166,7 +192,7 @@ class LottiePrivacyShieldAnimationHelperTest {
166
192
val appTheme: AppTheme = mock()
167
193
whenever(appTheme.isLightModeEnabled()).thenReturn(false )
168
194
169
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
195
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore )
170
196
171
197
testee.setAnimationView(holder, UNPROTECTED )
172
198
@@ -182,7 +208,102 @@ class LottiePrivacyShieldAnimationHelperTest {
182
208
val appTheme: AppTheme = mock()
183
209
whenever(appTheme.isLightModeEnabled()).thenReturn(true )
184
210
185
- val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment)
211
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
212
+
213
+ testee.setAnimationView(holder, PROTECTED )
214
+
215
+ verify(holder).setAnimation(R .raw.protected_shield)
216
+ }
217
+
218
+ @SuppressLint(" DenyListedApi" )
219
+ @Test
220
+ fun whenLightModeAndProtectedAndSelfEnabledAndShouldShowNewVisualDesignShieldThenUseExperimentAssets () {
221
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
222
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
223
+ enabledVisualExperimentStateFlow,
224
+ )
225
+
226
+ val holder: LottieAnimationView = mock()
227
+ val appTheme: AppTheme = mock()
228
+ whenever(appTheme.isLightModeEnabled()).thenReturn(true )
229
+
230
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
231
+
232
+ testee.setAnimationView(holder, PROTECTED )
233
+
234
+ verify(holder).setAnimation(R .raw.protected_shield_visual_updates)
235
+ }
236
+
237
+ @SuppressLint(" DenyListedApi" )
238
+ @Test
239
+ fun whenLightModeAndUnprotectedAndSelfEnabledAndShouldShowNewVisualDesignShieldThenUseExperimentAssets () {
240
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
241
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
242
+ enabledVisualExperimentStateFlow,
243
+ )
244
+
245
+ val holder: LottieAnimationView = mock()
246
+ val appTheme: AppTheme = mock()
247
+ whenever(appTheme.isLightModeEnabled()).thenReturn(true )
248
+
249
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
250
+
251
+ testee.setAnimationView(holder, UNPROTECTED )
252
+
253
+ verify(holder).setAnimation(R .raw.unprotected_shield_visual_updates)
254
+ }
255
+
256
+ @SuppressLint(" DenyListedApi" )
257
+ @Test
258
+ fun whenDarkModeAndProtectedAndSelfEnabledAndShouldShowNewVisualDesignShieldThenUseExperimentAssets () {
259
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
260
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
261
+ enabledVisualExperimentStateFlow,
262
+ )
263
+
264
+ val holder: LottieAnimationView = mock()
265
+ val appTheme: AppTheme = mock()
266
+ whenever(appTheme.isLightModeEnabled()).thenReturn(false )
267
+
268
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
269
+
270
+ testee.setAnimationView(holder, PROTECTED )
271
+
272
+ verify(holder).setAnimation(R .raw.dark_protected_shield_visual_updates)
273
+ }
274
+
275
+ @SuppressLint(" DenyListedApi" )
276
+ @Test
277
+ fun whenDarkModeAndUnprotectedAndSelfEnabledAndShouldShowNewVisualDesignShieldThenUseExperimentAssets () {
278
+ whenever(senseOfProtectionExperiment.shouldShowNewPrivacyShield()).thenReturn(false )
279
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
280
+ enabledVisualExperimentStateFlow,
281
+ )
282
+
283
+ val holder: LottieAnimationView = mock()
284
+ val appTheme: AppTheme = mock()
285
+ whenever(appTheme.isLightModeEnabled()).thenReturn(false )
286
+
287
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
288
+
289
+ testee.setAnimationView(holder, UNPROTECTED )
290
+
291
+ verify(holder).setAnimation(R .raw.dark_unprotected_shield_visual_updates)
292
+ }
293
+
294
+ @SuppressLint(" DenyListedApi" )
295
+ @Test
296
+ fun whenLightModeAndProtectedAndSelfEnabledAndShouldShowNotNewVisualDesignShieldThenUseNonExperimentAssets () {
297
+ whenever(senseOfProtectionExperiment.isUserEnrolledInAVariantAndExperimentEnabled()).thenReturn(false )
298
+ whenever(visualDesignExperimentDataStore.experimentState).thenReturn(
299
+ disabledVisualExperimentStateFlow,
300
+ )
301
+
302
+ val holder: LottieAnimationView = mock()
303
+ val appTheme: AppTheme = mock()
304
+ whenever(appTheme.isLightModeEnabled()).thenReturn(true )
305
+
306
+ val testee = LottiePrivacyShieldAnimationHelper (appTheme, senseOfProtectionExperiment, visualDesignExperimentDataStore)
186
307
187
308
testee.setAnimationView(holder, PROTECTED )
188
309
0 commit comments