/
JetpackAppMigrationFlowUtilsTest.kt
150 lines (131 loc) · 6.32 KB
/
JetpackAppMigrationFlowUtilsTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package org.wordpress.android.ui.utils
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.config.JetpackMigrationFlowFeatureConfig
import org.wordpress.android.util.publicdata.AppStatus
import org.wordpress.android.util.publicdata.WordPressPublicData
import org.wordpress.android.viewmodel.ContextProvider
@RunWith(MockitoJUnitRunner::class)
class JetpackAppMigrationFlowUtilsTest {
private val buildConfigWrapper: BuildConfigWrapper = mock()
private val jetpackMigrationFlowFeatureConfig: JetpackMigrationFlowFeatureConfig = mock()
private val contextProvider: ContextProvider = mock()
private val appPrefsWrapper: AppPrefsWrapper = mock()
private val accountStore: AccountStore = mock()
private val appStatus: AppStatus = mock()
private val wordPressPublicData: WordPressPublicData = mock()
private val contentMigrationAnalyticsTracker: ContentMigrationAnalyticsTracker = mock()
private val jetpackAppMigrationFlowUtils = JetpackAppMigrationFlowUtils(
buildConfigWrapper,
jetpackMigrationFlowFeatureConfig,
contextProvider,
appPrefsWrapper,
accountStore,
appStatus,
wordPressPublicData,
contentMigrationAnalyticsTracker,
)
@Before
fun setUp() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(jetpackMigrationFlowFeatureConfig.isEnabled()).thenReturn(true)
whenever(appPrefsWrapper.isJetpackMigrationEligible()).thenReturn(true)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(wordPressPublicData.currentPackageId()).thenReturn("package")
whenever(appStatus.isAppInstalled(any())).thenReturn(true)
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn("21.3")
}
@Test
fun `When all conditions are met the migration flow should be shown`() {
val expected = true
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When not in the Jetpack app the migration flow should not be shown`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When the jetpackMigrationFlow is not enabled the Jetpack app the migration flow should not be shown`() {
whenever(jetpackMigrationFlowFeatureConfig.isEnabled()).thenReturn(false)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When the jetpackMigrationFlow is not eligible the Jetpack app the migration flow should not be shown`() {
whenever(appPrefsWrapper.isJetpackMigrationEligible()).thenReturn(false)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When user is logged in and migration was in progress the Jetpack app the migration flow should be shown`() {
whenever(accountStore.hasAccessToken()).thenReturn(true)
whenever(appPrefsWrapper.isJetpackMigrationInProgress()).thenReturn(true)
val expected = true
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `If the user is logged in the Jetpack app the migration flow should not be shown`() {
whenever(accountStore.hasAccessToken()).thenReturn(true)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When the WordPress app is not installed the Jetpack app the migration flow should not be shown`() {
whenever(appStatus.isAppInstalled(any())).thenReturn(false)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When the WordPress app is not compatible the Jetpack app the migration flow should not be shown`() {
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn("21.2")
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
verify(contentMigrationAnalyticsTracker).trackWordPressAppDetected(false)
}
@Test
fun `When the WordPress app version is null the Jetpack app the migration flow should not be shown`() {
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn(null)
val expected = false
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
Assert.assertEquals(expected, actual)
}
@Test
fun `When the WordPress app is installed and compatible detection should be tracked true`() {
jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
verify(contentMigrationAnalyticsTracker).trackWordPressAppDetected(true)
}
@Test
fun `When the WordPress app is installed and not compatible detection should be tracked as false`() {
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn("21.2")
jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
verify(contentMigrationAnalyticsTracker).trackWordPressAppDetected(false)
}
@Test
fun `When the WordPress app is not detected detection should not be tracked`() {
whenever(appStatus.isAppInstalled(any())).thenReturn(false)
jetpackAppMigrationFlowUtils.shouldShowMigrationFlow()
verify(contentMigrationAnalyticsTracker, never()).trackWordPressAppDetected(any())
}
}