diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelper.kt index 7f43f60b04e0..7255a908245a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelper.kt @@ -1,17 +1,12 @@ package org.wordpress.android.ui.main.utils -import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper -import org.wordpress.android.ui.main.MainActionListItem import org.wordpress.android.ui.main.WPMainNavigationView.PageType -import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution import org.wordpress.android.ui.voicetocontent.VoiceToContentFeatureUtils import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.util.SiteUtilsWrapper -import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.config.ReaderFloatingButtonFeatureConfig -import java.util.Locale import javax.inject.Inject class MainCreateSheetHelper @Inject constructor( @@ -20,7 +15,6 @@ class MainCreateSheetHelper @Inject constructor( private val bloggingPromptsSettingsHelper: BloggingPromptsSettingsHelper, private val buildConfig: BuildConfigWrapper, private val siteUtils: SiteUtilsWrapper, - private val analyticsTracker: AnalyticsTrackerWrapper, ) { fun shouldShowFabForPage(page: PageType?): Boolean { val enabledForPage = page == PageType.MY_SITE || @@ -40,53 +34,4 @@ class MainCreateSheetHelper @Inject constructor( } suspend fun canCreatePromptAnswer(): Boolean = bloggingPromptsSettingsHelper.shouldShowPromptsFeature() - - // region Analytics - fun trackActionTapped(page: PageType, actionType: MainActionListItem.ActionType) { - val stat = when (page) { - PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_ACTION_TAPPED - PageType.READER -> Stat.READER_CREATE_SHEET_ACTION_TAPPED - else -> return - } - val properties = mapOf("action" to actionType.name.lowercase(Locale.ROOT)) - analyticsTracker.track(stat, properties) - } - - fun trackAnswerPromptActionTapped(page: PageType, attribution: BloggingPromptAttribution) { - val properties = mapOf("attribution" to attribution.value).filterValues { it.isNotBlank() } - val stat = when (page) { - PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_ANSWER_PROMPT_TAPPED - PageType.READER -> Stat.READER_CREATE_SHEET_ANSWER_PROMPT_TAPPED - else -> return - } - analyticsTracker.track(stat, properties) - } - - fun trackHelpPromptActionTapped(page: PageType) { - val stat = when (page) { - PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_PROMPT_HELP_TAPPED - PageType.READER -> Stat.READER_CREATE_SHEET_PROMPT_HELP_TAPPED - else -> return - } - analyticsTracker.track(stat) - } - - fun trackSheetShown(page: PageType) { - val stat = when (page) { - PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_SHOWN - PageType.READER -> Stat.READER_CREATE_SHEET_SHOWN - else -> return - } - analyticsTracker.track(stat) - } - - fun trackFabShown(page: PageType) { - val stat = when (page) { - PageType.MY_SITE -> Stat.MY_SITE_CREATE_FAB_SHOWN - PageType.READER -> Stat.READER_CREATE_FAB_SHOWN - else -> return - } - analyticsTracker.track(stat) - } - // endregion } diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModel.kt index 6abc737f3fdf..cb36800bbedd 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModel.kt @@ -30,6 +30,7 @@ import org.wordpress.android.ui.main.MainActionListItem.AnswerBloggingPromptActi import org.wordpress.android.ui.main.MainActionListItem.CreateAction import org.wordpress.android.ui.main.MainFabUiState import org.wordpress.android.ui.main.WPMainNavigationView.PageType +import org.wordpress.android.ui.main.analytics.MainCreateSheetTracker import org.wordpress.android.ui.main.utils.MainCreateSheetHelper import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution @@ -65,9 +66,10 @@ class WPMainActivityViewModel @Inject constructor( private val accountStore: AccountStore, private val siteStore: SiteStore, private val bloggingPromptsStore: BloggingPromptsStore, - @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val shouldAskPrivacyConsent: ShouldAskPrivacyConsent, private val mainCreateSheetHelper: MainCreateSheetHelper, + private val mainCreateSheetTracker: MainCreateSheetTracker, + @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, ) : ScopedViewModel(mainDispatcher) { private var isStarted = false @@ -236,11 +238,11 @@ class WPMainActivityViewModel @Inject constructor( } _mainActions.postValue(actionsList) - if (onFabClicked) trackCreateActionsSheetCard(actionsList) + if (onFabClicked) mainCreateSheetTracker.trackCreateActionsSheetCard(actionsList) } private fun onCreateActionClicked(actionType: ActionType, page: PageType) { - mainCreateSheetHelper.trackActionTapped(page, actionType) + mainCreateSheetTracker.trackActionTapped(page, actionType) _isBottomSheetShowing.postValue(Event(false)) _createAction.postValue(actionType) @@ -253,22 +255,16 @@ class WPMainActivityViewModel @Inject constructor( } private fun onAnswerPromptActionClicked(promptId: Int, attribution: BloggingPromptAttribution, page: PageType) { - mainCreateSheetHelper.trackAnswerPromptActionTapped(page, attribution) + mainCreateSheetTracker.trackAnswerPromptActionTapped(page, attribution) _isBottomSheetShowing.postValue(Event(false)) _createPostWithBloggingPrompt.postValue(promptId) } private fun onHelpPromptActionClicked(page: PageType) { - mainCreateSheetHelper.trackHelpPromptActionTapped(page) + mainCreateSheetTracker.trackHelpPromptActionTapped(page) _openBloggingPromptsOnboarding.call() } - private fun trackCreateActionsSheetCard(actions: List) { - if (actions.any { it is AnswerBloggingPromptAction }) { - analyticsTracker.track(Stat.BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED) - } - } - fun onFabClicked(site: SiteModel?, page: PageType) { appPrefsWrapper.setMainFabTooltipDisabled(true) @@ -284,7 +280,7 @@ class WPMainActivityViewModel @Inject constructor( // latest info. loadMainActions(site, page, onFabClicked = true) - mainCreateSheetHelper.trackSheetShown(page) + mainCreateSheetTracker.trackSheetShown(page) _isBottomSheetShowing.postValue(Event(true)) } } else { @@ -332,7 +328,7 @@ class WPMainActivityViewModel @Inject constructor( } private fun setMainFabUiState(isFabVisible: Boolean, site: SiteModel?, page: PageType?) { - if (isFabVisible && page != null) mainCreateSheetHelper.trackFabShown(page) + if (isFabVisible && page != null) mainCreateSheetTracker.trackFabShown(page) val newState = MainFabUiState( isFabVisible = isFabVisible, diff --git a/WordPress/src/test/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelperTest.kt index b54dda92261e..fe473441fcfd 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/main/utils/MainCreateSheetHelperTest.kt @@ -4,22 +4,14 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.mockito.Mock -import org.mockito.kotlin.argThat -import org.mockito.kotlin.eq -import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest -import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper -import org.wordpress.android.ui.main.MainActionListItem import org.wordpress.android.ui.main.WPMainNavigationView.PageType -import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution import org.wordpress.android.ui.voicetocontent.VoiceToContentFeatureUtils import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.util.SiteUtilsWrapper -import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.config.ReaderFloatingButtonFeatureConfig import kotlin.test.Test @@ -40,9 +32,6 @@ class MainCreateSheetHelperTest : BaseUnitTest() { @Mock private lateinit var siteUtils: SiteUtilsWrapper - @Mock - private lateinit var analyticsTracker: AnalyticsTrackerWrapper - private lateinit var helper: MainCreateSheetHelper @Before @@ -53,7 +42,6 @@ class MainCreateSheetHelperTest : BaseUnitTest() { bloggingPromptsSettingsHelper, buildConfig, siteUtils, - analyticsTracker, ) } @@ -125,6 +113,22 @@ class MainCreateSheetHelperTest : BaseUnitTest() { // Assert assertThat(result).isFalse() } + + @Test + fun `shouldShowFabForPage returns false for other pages`() { + PageType.entries + .filterNot { it == PageType.MY_SITE || it == PageType.READER } + .forEach { page -> + // Arrange + whenever(buildConfig.isCreateFabEnabled).thenReturn(true) + + // Act + val result = helper.shouldShowFabForPage(page) + + // Assert + assertThat(result).isFalse() + } + } // endregion // region canCreatePost @@ -253,227 +257,4 @@ class MainCreateSheetHelperTest : BaseUnitTest() { assertThat(result).isFalse() } // endregion - - // region trackActionTapped - @Test - fun `trackActionTapped tracks action tapped for my site page`() { - // Arrange - val page = PageType.MY_SITE - val actionType = MainActionListItem.ActionType.CREATE_NEW_POST - val expectedStat = Stat.MY_SITE_CREATE_SHEET_ACTION_TAPPED - - // Act - helper.trackActionTapped(page, actionType) - - // Assert - verify(analyticsTracker).track(eq(expectedStat), argThat> { - this["action"] == "create_new_post" - }) - } - - @Test - fun `trackActionTapped tracks action tapped for reader page`() { - // Arrange - val page = PageType.READER - val actionType = MainActionListItem.ActionType.CREATE_NEW_POST - val expectedStat = Stat.READER_CREATE_SHEET_ACTION_TAPPED - - // Act - helper.trackActionTapped(page, actionType) - - // Assert - verify(analyticsTracker).track(eq(expectedStat), argThat> { - this["action"] == "create_new_post" - }) - } - - @Test - fun `trackActionTapped does not track action tapped for other pages`() { - PageType.entries - .filterNot { it == PageType.MY_SITE || it == PageType.READER } - .forEach { page -> - // Arrange - val actionType = MainActionListItem.ActionType.CREATE_NEW_POST - - // Act - helper.trackActionTapped(page, actionType) - - // Assert - verifyNoInteractions(analyticsTracker) - } - } - // endregion - - // region trackAnswerPromptActionTapped - @Test - fun `trackAnswerPromptActionTapped tracks answer prompt action tapped for my site page`() { - // Arrange - val page = PageType.MY_SITE - val attribution = BloggingPromptAttribution.DAY_ONE - val expectedStat = Stat.MY_SITE_CREATE_SHEET_ANSWER_PROMPT_TAPPED - - // Act - helper.trackAnswerPromptActionTapped(page, attribution) - - // Assert - verify(analyticsTracker).track(eq(expectedStat), argThat> { - this["attribution"] == attribution.value - }) - } - - @Test - fun `trackAnswerPromptActionTapped tracks answer prompt action tapped for reader page`() { - // Arrange - val page = PageType.READER - val attribution = BloggingPromptAttribution.DAY_ONE - val expectedStat = Stat.READER_CREATE_SHEET_ANSWER_PROMPT_TAPPED - - // Act - helper.trackAnswerPromptActionTapped(page, attribution) - - // Assert - verify(analyticsTracker).track(eq(expectedStat), argThat> { - this["attribution"] == attribution.value - }) - } - - @Test - fun `trackAnswerPromptActionTapped does not track answer prompt action tapped for other pages`() { - PageType.entries - .filterNot { it == PageType.MY_SITE || it == PageType.READER } - .forEach { page -> - // Arrange - val attribution = BloggingPromptAttribution.DAY_ONE - - // Act - helper.trackAnswerPromptActionTapped(page, attribution) - - // Assert - verifyNoInteractions(analyticsTracker) - } - } - // endregion - - // region trackHelpPromptActionTapped - @Test - fun `trackHelpPromptActionTapped tracks help prompt action tapped for my site page`() { - // Arrange - val page = PageType.MY_SITE - val expectedStat = Stat.MY_SITE_CREATE_SHEET_PROMPT_HELP_TAPPED - - // Act - helper.trackHelpPromptActionTapped(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackHelpPromptActionTapped tracks help prompt action tapped for reader page`() { - // Arrange - val page = PageType.READER - val expectedStat = Stat.READER_CREATE_SHEET_PROMPT_HELP_TAPPED - - // Act - helper.trackHelpPromptActionTapped(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackHelpPromptActionTapped does not track help prompt action tapped for other pages`() { - PageType.entries - .filterNot { it == PageType.MY_SITE || it == PageType.READER } - .forEach { page -> - // Act - helper.trackHelpPromptActionTapped(page) - - // Assert - verifyNoInteractions(analyticsTracker) - } - } - // endregion - - // region trackSheetShown - @Test - fun `trackSheetShown tracks sheet shown for my site page`() { - // Arrange - val page = PageType.MY_SITE - val expectedStat = Stat.MY_SITE_CREATE_SHEET_SHOWN - - // Act - helper.trackSheetShown(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackSheetShown tracks sheet shown for reader page`() { - // Arrange - val page = PageType.READER - val expectedStat = Stat.READER_CREATE_SHEET_SHOWN - - // Act - helper.trackSheetShown(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackSheetShown does not track sheet shown for other pages`() { - PageType.entries - .filterNot { it == PageType.MY_SITE || it == PageType.READER } - .forEach { page -> - // Act - helper.trackSheetShown(page) - - // Assert - verifyNoInteractions(analyticsTracker) - } - } - // endregion - - // region trackFabShown - @Test - fun `trackFabShown tracks fab shown for my site page`() { - // Arrange - val page = PageType.MY_SITE - val expectedStat = Stat.MY_SITE_CREATE_FAB_SHOWN - - // Act - helper.trackFabShown(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackFabShown tracks fab shown for reader page`() { - // Arrange - val page = PageType.READER - val expectedStat = Stat.READER_CREATE_FAB_SHOWN - - // Act - helper.trackFabShown(page) - - // Assert - verify(analyticsTracker).track(expectedStat) - } - - @Test - fun `trackFabShown does not track fab shown for other pages`() { - PageType.entries - .filterNot { it == PageType.MY_SITE || it == PageType.READER } - .forEach { page -> - // Act - helper.trackFabShown(page) - - // Assert - verifyNoInteractions(analyticsTracker) - } - } - // endregion } diff --git a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModelTest.kt index a6c81d98b44c..f06d97206963 100644 --- a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModelTest.kt @@ -20,7 +20,6 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest -import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.analytics.AnalyticsTracker.Stat.FEATURE_ANNOUNCEMENT_SHOWN_ON_APP_UPGRADE import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.bloggingprompts.BloggingPromptModel @@ -38,12 +37,13 @@ import org.wordpress.android.fluxc.store.bloggingprompts.BloggingPromptsStore.Bl import org.wordpress.android.ui.main.MainActionListItem.ActionType.ANSWER_BLOGGING_PROMPT import org.wordpress.android.ui.main.MainActionListItem.ActionType.CREATE_NEW_PAGE import org.wordpress.android.ui.main.MainActionListItem.ActionType.CREATE_NEW_POST -import org.wordpress.android.ui.main.MainActionListItem.ActionType.CREATE_NEW_POST_FROM_AUDIO +import org.wordpress.android.ui.main.MainActionListItem.ActionType.CREATE_NEW_POST_FROM_AUDIO_AI import org.wordpress.android.ui.main.MainActionListItem.ActionType.NO_ACTION import org.wordpress.android.ui.main.MainActionListItem.AnswerBloggingPromptAction import org.wordpress.android.ui.main.MainActionListItem.CreateAction import org.wordpress.android.ui.main.MainFabUiState import org.wordpress.android.ui.main.WPMainNavigationView.PageType +import org.wordpress.android.ui.main.analytics.MainCreateSheetTracker import org.wordpress.android.ui.main.utils.MainCreateSheetHelper import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution @@ -111,6 +111,9 @@ class WPMainActivityViewModelTest : BaseUnitTest() { @Mock private lateinit var mainCreateSheetHelper: MainCreateSheetHelper + @Mock + private lateinit var mainCreateSheetTracker: MainCreateSheetTracker + private val featureAnnouncement = FeatureAnnouncement( "14.7", 2, @@ -169,9 +172,10 @@ class WPMainActivityViewModelTest : BaseUnitTest() { accountStore, siteStore, bloggingPromptsStore, - NoDelayCoroutineDispatcher(), shouldAskPrivacyConsent, mainCreateSheetHelper, + mainCreateSheetTracker, + NoDelayCoroutineDispatcher(), ) viewModel.onFeatureAnnouncementRequested.observeForever( onFeatureAnnouncementRequestedObserver @@ -643,7 +647,7 @@ class WPMainActivityViewModelTest : BaseUnitTest() { ANSWER_BLOGGING_PROMPT, NO_ACTION, CREATE_NEW_POST, - CREATE_NEW_POST_FROM_AUDIO, + CREATE_NEW_POST_FROM_AUDIO_AI, CREATE_NEW_PAGE ) @@ -694,7 +698,7 @@ class WPMainActivityViewModelTest : BaseUnitTest() { it.actionType == ANSWER_BLOGGING_PROMPT } as AnswerBloggingPromptAction action.onHelpAction?.invoke() - verify(mainCreateSheetHelper).trackHelpPromptActionTapped(any()) + verify(mainCreateSheetTracker).trackHelpPromptActionTapped(any()) } @Test @@ -709,14 +713,11 @@ class WPMainActivityViewModelTest : BaseUnitTest() { } @Test - @Suppress("MaxLineLength") - fun `Should track BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED when onFabClicked is called and actions contains AnswerBloggingPromptAction`() = - test { - whenever(mainCreateSheetHelper.canCreatePromptAnswer()).thenReturn(true) - startViewModelWithDefaultParameters() - viewModel.onFabClicked(initSite(), page = PageType.MY_SITE) - verify(analyticsTrackerWrapper).track(Stat.BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED) - } + fun `Should track card actions when onFabClicker is called`() { + startViewModelWithDefaultParameters() + viewModel.onFabClicked(initSite(), page = PageType.MY_SITE) + verify(mainCreateSheetTracker).trackCreateActionsSheetCard(any()) + } @Test fun `it asks for privacy consent at the start when it should`() = test {