Skip to content

Commit 5603bad

Browse files
Introduce DaxCta interface (duckduckgo#680)
1 parent d5fc83d commit 5603bad

File tree

8 files changed

+157
-98
lines changed

8 files changed

+157
-98
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,20 +1445,11 @@ class BrowserTabViewModelTest {
14451445
}
14461446

14471447
@Test
1448-
fun whenRegisterDaxBubbleCtaShownThenFirePixel() {
1448+
fun whenRegisterDaxBubbleCtaDismissedThenRegisterInDatabase() {
14491449
val cta = DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore)
14501450
testee.ctaViewState.value = BrowserTabViewModel.CtaViewState(cta = cta)
14511451

1452-
testee.registerDaxBubbleCtaShown()
1453-
verify(mockPixel).fire(cta.shownPixel!!, cta.pixelShownParameters())
1454-
}
1455-
1456-
@Test
1457-
fun whenRegisterDaxBubbleCtaShownThenRegisterInDatabase() {
1458-
val cta = DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore)
1459-
testee.ctaViewState.value = BrowserTabViewModel.CtaViewState(cta = cta)
1460-
1461-
testee.registerDaxBubbleCtaShown()
1452+
testee.registerDaxBubbleCtaDismissed()
14621453
verify(mockDismissedCtaDao).insert(DismissedCta(cta.ctaId))
14631454
}
14641455

app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaTest.kt

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.junit.Assert.*
3030
import org.junit.Before
3131
import org.junit.Test
3232
import org.mockito.Mock
33-
import org.mockito.Mockito.mock
3433
import org.mockito.MockitoAnnotations
3534
import java.util.concurrent.TimeUnit
3635

@@ -146,6 +145,49 @@ class CtaTest {
146145
assertEquals(expectedValue, value[CTA_SHOWN])
147146
}
148147

148+
@Test
149+
fun whenAddCtaToHistoryThenReturnCorrectValue() {
150+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn(null)
151+
whenever(mockAppInstallStore.installTimestamp).thenReturn(System.currentTimeMillis())
152+
153+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
154+
val value = testee.addCtaToHistory("test")
155+
assertEquals("test:0", value)
156+
}
157+
158+
@Test
159+
fun whenAddCtaToHistoryOnDay3ThenReturnCorrectValue() {
160+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn(null)
161+
whenever(mockAppInstallStore.installTimestamp).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(3))
162+
163+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
164+
val value = testee.addCtaToHistory("test")
165+
assertEquals("test:3", value)
166+
}
167+
168+
@Test
169+
fun whenAddCtaToHistoryOnDay4ThenReturn3AsDayValue() {
170+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn(null)
171+
whenever(mockAppInstallStore.installTimestamp).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(4))
172+
173+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
174+
val value = testee.addCtaToHistory("test")
175+
assertEquals("test:3", value)
176+
}
177+
178+
@Test
179+
fun whenAddCtaToHistoryContainsHistoryThenConcatenateNewValue() {
180+
val ctaHistory = "s:0-t:1"
181+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn(ctaHistory)
182+
whenever(mockAppInstallStore.installTimestamp).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
183+
184+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
185+
val value = testee.addCtaToHistory("test")
186+
val expectedValue = "$ctaHistory-test:1"
187+
188+
assertEquals(expectedValue, value)
189+
}
190+
149191
@Test
150192
fun whenCtaIsBubbleTypeThenConcatenateJourneyStoredValueInPixel() {
151193
val existingJourney = "s:0-t:1"
@@ -158,6 +200,21 @@ class CtaTest {
158200
assertEquals(expectedValue, value[CTA_SHOWN])
159201
}
160202

203+
@Test
204+
fun whenCanSendPixelAndCtaNotPartOfHistoryThenReturnTrue() {
205+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn("s:0")
206+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
207+
assertTrue(testee.canSendShownPixel())
208+
}
209+
210+
@Test
211+
fun whenCanSendPixelAndCtaIsPartOfHistoryThenReturnFalse() {
212+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn("e:0")
213+
214+
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
215+
assertFalse(testee.canSendShownPixel())
216+
}
217+
161218
@Test
162219
fun whenCtaIsDialogTypeReturnCorrectCancelParameters() {
163220
val testee = DaxDialogCta.DaxSerpCta(mockOnboardingStore, mockAppInstallStore)
@@ -218,7 +275,7 @@ class CtaTest {
218275
}
219276

220277
@Test
221-
fun whenTwoMajorTrackersBlockedReturnThemWithMultipleString() {
278+
fun whenTwoMajorTrackersBlockedReturnThemWithZeroString() {
222279
val trackers = listOf(
223280
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
224281
TrackingEvent("other.com", "other.com", blocked = true, entity = TestEntity("Other", "Other", 9.0), categories = null)

app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,20 @@ class CtaViewModelTest {
149149
}
150150

151151
@Test
152-
fun whenCtaShownPixelIsFired() {
152+
fun whenCtaShownAndCtaIsDaxAndCanNotSendPixelThenPixelIsNotFired() {
153+
testee.onCtaShown(DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore))
154+
verify(mockPixel, never()).fire(eq(SURVEY_CTA_SHOWN), any())
155+
}
156+
157+
@Test
158+
fun whenCtaShownAndCtaIsDaxAndCanSendPixelThenPixelIsFired() {
159+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn("s:0")
160+
testee.onCtaShown(DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore))
161+
verify(mockPixel, never()).fire(eq(SURVEY_CTA_SHOWN), any())
162+
}
163+
164+
@Test
165+
fun whenCtaShownAndCtaIsNotDaxThenPixelIsFired() {
153166
testee.onCtaShown(HomePanelCta.Survey(Survey("abc", "http://example.com", 1, SCHEDULED)))
154167
verify(mockPixel).fire(eq(SURVEY_CTA_SHOWN), any())
155168
}
@@ -193,28 +206,16 @@ class CtaViewModelTest {
193206

194207
@Test
195208
fun whenRegisterDaxBubbleIntroCtaThenDatabaseNotified() {
196-
testee.registerDaxBubbleCtaShown(DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore))
209+
testee.registerDaxBubbleCtaDismissed(DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore))
197210
verify(mockDismissedCtaDao).insert(DismissedCta(CtaId.DAX_INTRO))
198211
}
199212

200-
@Test
201-
fun whenRegisterDaxBubbleIntroCtaThenPixelIsFired() {
202-
testee.registerDaxBubbleCtaShown(DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore))
203-
verify(mockPixel).fire(eq(ONBOARDING_DAX_CTA_SHOWN), any())
204-
}
205-
206213
@Test
207214
fun whenRegisterDaxBubbleEndCtaThenDatabaseNotified() {
208-
testee.registerDaxBubbleCtaShown(DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore))
215+
testee.registerDaxBubbleCtaDismissed(DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore))
209216
verify(mockDismissedCtaDao).insert(DismissedCta(CtaId.DAX_END))
210217
}
211218

212-
@Test
213-
fun whenRegisterDaxBubbleEndCtaThenPixelIsFired() {
214-
testee.registerDaxBubbleCtaShown(DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore))
215-
verify(mockPixel).fire(eq(ONBOARDING_DAX_CTA_SHOWN), any())
216-
}
217-
218219
@Test
219220
fun whenRefreshCtaOnHomeTabAndConceptTestFeatureActiveThenReturnDaxIntroCta() = runBlockingTest {
220221
setConceptTestFeature()

app/src/androidTest/java/com/duckduckgo/app/di/TestAppComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ interface TestAppComponent : AppComponent {
7777
interface Builder {
7878

7979
@BindsInstance
80-
fun application(application: Application): TestAppComponent.Builder
80+
fun application(application: Application): Builder
8181

8282
fun build(): TestAppComponent
8383
}

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {
432432
private fun navigate(url: String) {
433433
hideKeyboard()
434434
renderer.hideFindInPage()
435-
viewModel.registerDaxBubbleCtaShown()
435+
viewModel.registerDaxBubbleCtaDismissed()
436436
webView?.loadUrl(url)
437437
}
438438

@@ -1364,9 +1364,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {
13641364
is DaxDialogCta -> showDaxDialogCta(configuration)
13651365
}
13661366

1367-
if (configuration !is DaxBubbleCta) {
1368-
viewModel.onCtaShown()
1369-
}
1367+
viewModel.onCtaShown()
13701368
}
13711369

13721370
private fun showDaxDialogCta(configuration: DaxDialogCta) {

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ class BrowserTabViewModel(
887887
}
888888
}
889889

890-
fun registerDaxBubbleCtaShown() {
890+
fun registerDaxBubbleCtaDismissed() {
891891
val cta = ctaViewState.value?.cta ?: return
892-
ctaViewModel.registerDaxBubbleCtaShown(cta)
892+
ctaViewModel.registerDaxBubbleCtaDismissed(cta)
893893
}
894894

895895
fun onUserClickCtaOkButton() {

0 commit comments

Comments
 (0)