@@ -1337,7 +1337,6 @@ class BrowserTabViewModelTest {
13371337
13381338 @Test
13391339 fun whenScheduledSurveyChangesAndInstalledDaysDontMatchThenCtaIsNull () {
1340- setCovidCtaShown()
13411340 testee.onSurveyChanged(Survey (" abc" , " http://example.com" , daysInstalled = 2 , status = Survey .Status .SCHEDULED ))
13421341 assertNull(testee.ctaViewState.value!! .cta)
13431342 }
@@ -1359,7 +1358,6 @@ class BrowserTabViewModelTest {
13591358
13601359 @Test
13611360 fun whenCtaRefreshedAndAutoAddSupportedAndWidgetAlreadyInstalledThenCtaIsNull () = coroutineRule.runBlocking {
1362- setCovidCtaShown()
13631361 whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(true )
13641362 whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(true )
13651363 whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true )
@@ -1376,7 +1374,6 @@ class BrowserTabViewModelTest {
13761374
13771375 @Test
13781376 fun whenCtaRefreshedAndOnlyStandardAddSupportedAndWidgetAlreadyInstalledThenCtaIsNull () = coroutineRule.runBlocking {
1379- setCovidCtaShown()
13801377 whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(true )
13811378 whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false )
13821379 whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true )
@@ -1386,7 +1383,6 @@ class BrowserTabViewModelTest {
13861383
13871384 @Test
13881385 fun whenCtaRefreshedAndStandardAddNotSupportedAndWidgetNotInstalledThenCtaIsNull () = coroutineRule.runBlocking {
1389- setCovidCtaShown()
13901386 whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(false )
13911387 whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false )
13921388 whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(false )
@@ -1396,7 +1392,6 @@ class BrowserTabViewModelTest {
13961392
13971393 @Test
13981394 fun whenCtaRefreshedAndStandardAddNotSupportedAndWidgetAlreadyInstalledThenCtaIsNull () = coroutineRule.runBlocking {
1399- setCovidCtaShown()
14001395 whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(false )
14011396 whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false )
14021397 whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true )
@@ -1443,45 +1438,41 @@ class BrowserTabViewModelTest {
14431438 @Test
14441439 fun whenUserClickedCtaButtonThenFirePixel () {
14451440 val cta = DaxBubbleCta .DaxIntroCta (mockOnboardingStore, mockAppInstallStore)
1446- testee.onUserClickCtaOkButton(cta)
1441+ setCta(cta)
1442+ testee.onUserClickCtaOkButton()
14471443 verify(mockPixel).fire(cta.okPixel!! , cta.pixelOkParameters())
14481444 }
14491445
14501446 @Test
14511447 fun whenUserClickedSurveyCtaButtonThenLaunchSurveyCommand () {
14521448 val cta = HomePanelCta .Survey (Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1453- testee.onUserClickCtaOkButton(cta)
1449+ setCta(cta)
1450+ testee.onUserClickCtaOkButton()
14541451 assertCommandIssued<Command .LaunchSurvey >()
14551452 }
14561453
14571454 @Test
14581455 fun whenUserClickedAddWidgetCtaButtonThenLaunchAddWidgetCommand () {
14591456 val cta = HomePanelCta .AddWidgetAuto
1460- testee.onUserClickCtaOkButton(cta)
1457+ setCta(cta)
1458+ testee.onUserClickCtaOkButton()
14611459 assertCommandIssued<Command .LaunchAddWidget >()
14621460 }
14631461
14641462 @Test
14651463 fun whenUserClickedLegacyAddWidgetCtaButtonThenLaunchLegacyAddWidgetCommand () {
14661464 val cta = HomePanelCta .AddWidgetInstructions
1467- testee.onUserClickCtaOkButton(cta)
1465+ setCta(cta)
1466+ testee.onUserClickCtaOkButton()
14681467 assertCommandIssued<Command .LaunchLegacyAddWidget >()
14691468 }
14701469
14711470 @Test
14721471 fun whenSurveyCtaDismissedAndNoOtherCtaPossibleCtaIsNull () = coroutineRule.runBlocking {
1473- givenShownCtas(CtaId .DAX_INTRO , CtaId .DAX_END , CtaId .COVID )
1474- testee.onSurveyChanged(Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1475- testee.onUserDismissedCta(testee.ctaViewState.value!! .cta!! )
1476- assertNull(testee.ctaViewState.value!! .cta)
1477- }
1478-
1479- @Test
1480- fun whenSurveyCtaDismissedAndWidgetNotCompatibleAndCovidCtaNotShownThenCtaIsCovid () = coroutineRule.runBlocking {
14811472 givenShownCtas(CtaId .DAX_INTRO , CtaId .DAX_END )
14821473 testee.onSurveyChanged(Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1483- testee.onUserDismissedCta(testee.ctaViewState.value !! .cta !! )
1484- assertEquals( HomeTopPanelCta . CovidCta (), testee.ctaViewState.value!! .cta)
1474+ testee.onUserDismissedCta()
1475+ assertNull( testee.ctaViewState.value!! .cta)
14851476 }
14861477
14871478 @Test
@@ -1491,46 +1482,68 @@ class BrowserTabViewModelTest {
14911482 whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(false )
14921483
14931484 testee.onSurveyChanged(Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1494- testee.onUserDismissedCta(testee.ctaViewState.value !! .cta !! )
1485+ testee.onUserDismissedCta()
14951486 assertEquals(HomePanelCta .AddWidgetAuto , testee.ctaViewState.value!! .cta)
14961487 }
14971488
14981489 @Test
14991490 fun whenUserDismissedCtaThenFirePixel () = coroutineRule.runBlocking {
15001491 val cta = HomePanelCta .Survey (Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1501- testee.onUserDismissedCta(cta)
1492+ setCta(cta)
1493+ testee.onUserDismissedCta()
15021494 verify(mockPixel).fire(cta.cancelPixel!! , cta.pixelCancelParameters())
15031495 }
15041496
1497+ @Test
1498+ fun whenUserClickedHideDaxDialogThenHideDaxDialogCommandSent () {
1499+ val cta = DaxDialogCta .DaxSerpCta (mockOnboardingStore, mockAppInstallStore)
1500+ setCta(cta)
1501+ testee.onUserHideDaxDialog()
1502+ val command = captureCommands().lastValue
1503+ assertTrue(command is Command .DaxCommand .HideDaxDialog )
1504+ }
1505+
1506+ @Test
1507+ fun whenUserDismissDaxTrackersBlockedDialogThenFinishTrackerAnimationCommandSent () {
1508+ val cta = DaxDialogCta .DaxTrackersBlockedCta (mockOnboardingStore, mockAppInstallStore, emptyList(), " " )
1509+ setCta(cta)
1510+ testee.onDaxDialogDismissed()
1511+ val command = captureCommands().lastValue
1512+ assertTrue(command is Command .DaxCommand .FinishTrackerAnimation )
1513+ }
1514+
1515+ @Test
1516+ fun whenUserDismissDifferentThanDaxTrackersBlockedDialogThenFinishTrackerAnimationCommandNotSent () {
1517+ val cta = DaxDialogCta .DaxSerpCta (mockOnboardingStore, mockAppInstallStore)
1518+ setCta(cta)
1519+ testee.onDaxDialogDismissed()
1520+ verify(mockCommandObserver, never()).onChanged(commandCaptor.capture())
1521+ }
1522+
15051523 @Test
15061524 fun whenUserDismissedCtaThenRegisterInDatabase () = coroutineRule.runBlocking {
15071525 val cta = HomePanelCta .AddWidgetAuto
1508- testee.onUserDismissedCta(cta)
1526+ setCta(cta)
1527+ testee.onUserDismissedCta()
15091528 verify(mockDismissedCtaDao).insert(DismissedCta (cta.ctaId))
15101529 }
15111530
15121531 @Test
15131532 fun whenUserDismissedSurveyCtaThenDoNotRegisterInDatabase () = coroutineRule.runBlocking {
15141533 val cta = HomePanelCta .Survey (Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1515- testee.onUserDismissedCta(cta)
1534+ setCta(cta)
1535+ testee.onUserDismissedCta()
15161536 verify(mockDismissedCtaDao, never()).insert(DismissedCta (cta.ctaId))
15171537 }
15181538
15191539 @Test
15201540 fun whenUserDismissedSurveyCtaThenCancelScheduledSurveys () = coroutineRule.runBlocking {
15211541 val cta = HomePanelCta .Survey (Survey (" abc" , " http://example.com" , daysInstalled = 1 , status = Survey .Status .SCHEDULED ))
1522- testee.onUserDismissedCta(cta)
1542+ setCta(cta)
1543+ testee.onUserDismissedCta()
15231544 verify(mockSurveyDao).cancelScheduledSurveys()
15241545 }
15251546
1526-
1527- @Test
1528- fun whenUserDismissedHomeTopPanelCtaThenReturnEmptyCta () {
1529- val cta = HomeTopPanelCta .CovidCta ()
1530- testee.onUserDismissedCta(cta)
1531- assertNull(testee.ctaViewState.value!! .cta)
1532- }
1533-
15341547 @Test
15351548 fun whenSurrogateDetectedThenSiteUpdated () {
15361549 givenOneActiveTabSelected()
@@ -1665,13 +1678,6 @@ class BrowserTabViewModelTest {
16651678 assertEquals(" surrogate.com" , brokenSiteFeedback.surrogates)
16661679 }
16671680
1668- @Test
1669- fun whenUserClickedTopCtaButtonAndCtaIsCovidCtaThenSubmitQuery () {
1670- val cta = HomeTopPanelCta .CovidCta ()
1671- testee.onUserClickTopCta(cta)
1672- assertEquals(cta.searchTerm, omnibarViewState().omnibarText)
1673- }
1674-
16751681 private inline fun <reified T : Command > assertCommandIssued (instanceAssertions : T .() -> Unit = {}) {
16761682 verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
16771683 val issuedCommand = commandCaptor.allValues.find { it is T }
@@ -1710,6 +1716,10 @@ class BrowserTabViewModelTest {
17101716 testee.browserViewState.value = browserViewState().copy(browserShowing = isBrowsing)
17111717 }
17121718
1719+ private fun setCta (cta : Cta ) {
1720+ testee.ctaViewState.value = ctaViewState().copy(cta = cta)
1721+ }
1722+
17131723 private fun loadUrl (url : String? , title : String? = null, isBrowserShowing : Boolean = true) {
17141724 setBrowserShowing(isBrowserShowing)
17151725 testee.navigationStateChanged(buildWebNavigation(originalUrl = url, currentUrl = url, title = title))
@@ -1721,10 +1731,6 @@ class BrowserTabViewModelTest {
17211731 testee.navigationStateChanged(buildWebNavigation(originalUrl = originalUrl, currentUrl = currentUrl))
17221732 }
17231733
1724- private fun setCovidCtaShown () {
1725- whenever(mockDismissedCtaDao.exists(CtaId .COVID )).thenReturn(true )
1726- }
1727-
17281734 private fun setupNavigation (
17291735 skipHome : Boolean = false,
17301736 isBrowsing : Boolean ,
@@ -1761,6 +1767,7 @@ class BrowserTabViewModelTest {
17611767 return nav
17621768 }
17631769
1770+ private fun ctaViewState () = testee.ctaViewState.value!!
17641771 private fun browserViewState () = testee.browserViewState.value!!
17651772 private fun omnibarViewState () = testee.omnibarViewState.value!!
17661773 private fun loadingViewState () = testee.loadingViewState.value!!
0 commit comments