From b3edf8f46eb1cd7e927c65b80ad794da2c3961d8 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 15:53:18 +0530 Subject: [PATCH 01/21] + Adds: a ListItemActionHandler to handle the click on list item --- .../ui/mysite/cards/ListItemActionHandler.kt | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt new file mode 100644 index 000000000000..0313f2b83fb9 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt @@ -0,0 +1,87 @@ +package org.wordpress.android.ui.mysite.cards + +import androidx.lifecycle.MutableLiveData +import org.wordpress.android.R +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.ui.blaze.BlazeFeatureUtils +import org.wordpress.android.ui.blaze.BlazeFlowSource +import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource +import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper +import org.wordpress.android.ui.mysite.SelectedSiteRepository +import org.wordpress.android.ui.mysite.SiteNavigationAction +import org.wordpress.android.ui.mysite.items.listitem.ListItemAction +import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.ui.utils.UiString +import org.wordpress.android.viewmodel.Event +import javax.inject.Inject + +class ListItemActionHandler @Inject constructor( + private val selectedSiteRepository: SelectedSiteRepository, + private val accountStore: AccountStore, + private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, + private val blazeFeatureUtils: BlazeFeatureUtils +) { + private val _onNavigation = MutableLiveData>() + val onNavigation = _onNavigation + + private val _onSnackbarMessage = MutableLiveData>() + val onSnackbarMessage = _onSnackbarMessage + + fun handleAction(action: ListItemAction) { + selectedSiteRepository.getSelectedSite()?.let { selectedSite -> + val navigationAction = when (action) { + ListItemAction.ACTIVITY_LOG -> SiteNavigationAction.OpenActivityLog(selectedSite) + ListItemAction.BACKUP -> SiteNavigationAction.OpenBackup(selectedSite) + ListItemAction.SCAN -> SiteNavigationAction.OpenScan(selectedSite) + ListItemAction.PLAN -> SiteNavigationAction.OpenPlan(selectedSite) + ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) + ListItemAction.PAGES -> { + SiteNavigationAction.OpenPages(selectedSite) + } + + ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) + ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) + ListItemAction.SHARING -> { + SiteNavigationAction.OpenSharing(selectedSite) + } + + ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) + ListItemAction.ME -> SiteNavigationAction.OpenMeScreen + ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) + ListItemAction.THEMES -> SiteNavigationAction.OpenThemes(selectedSite) + ListItemAction.PLUGINS -> SiteNavigationAction.OpenPlugins(selectedSite) + ListItemAction.STATS -> getStatsNavigationActionForSite(selectedSite) + ListItemAction.MEDIA -> SiteNavigationAction.OpenMedia(selectedSite) + ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) + ListItemAction.BLAZE -> onBlazeMenuItemClick() + ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite) + } + _onNavigation.postValue(Event(navigationAction)) + } ?: _onSnackbarMessage.postValue( + Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded))) + ) + } + + private fun getStatsNavigationActionForSite(site: SiteModel): SiteNavigationAction = when { + // if we are in static posters phase - we don't want to show any connection/login messages + jetpackFeatureRemovalPhaseHelper.shouldShowStaticPage() -> + SiteNavigationAction.ShowJetpackRemovalStaticPostersView + + // If the user is not logged in and the site is already connected to Jetpack, ask to login. + !accountStore.hasAccessToken() && site.isJetpackConnected -> SiteNavigationAction.StartWPComLoginForJetpackStats + + // If it's a WordPress.com or Jetpack site, show the Stats screen. + site.isWPCom || site.isJetpackInstalled && site.isJetpackConnected -> SiteNavigationAction.OpenStats(site) + + // If it's a self-hosted site, ask to connect to Jetpack. + else -> SiteNavigationAction.ConnectJetpackForStats(site) + } + + private fun onBlazeMenuItemClick(): SiteNavigationAction { + if (blazeFeatureUtils.shouldShowBlazeCampaigns()) { + return SiteNavigationAction.OpenCampaignListingPage(CampaignListingPageSource.MENU_ITEM) + } + return SiteNavigationAction.OpenPromoteWithBlazeOverlay(BlazeFlowSource.MENU_ITEM) + } +} From 214f8f368e2bb3d5b790b2930e69763eb7478fff Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:10:17 +0530 Subject: [PATCH 02/21] + Adds: List action handler to handle the site items click --- .../ui/mysite/cards/ListItemActionHandler.kt | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt index 0313f2b83fb9..cc2055ce1234 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt @@ -1,66 +1,48 @@ package org.wordpress.android.ui.mysite.cards -import androidx.lifecycle.MutableLiveData -import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.ui.blaze.BlazeFeatureUtils import org.wordpress.android.ui.blaze.BlazeFlowSource import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper -import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction import org.wordpress.android.ui.mysite.items.listitem.ListItemAction -import org.wordpress.android.ui.pages.SnackbarMessageHolder -import org.wordpress.android.ui.utils.UiString -import org.wordpress.android.viewmodel.Event import javax.inject.Inject class ListItemActionHandler @Inject constructor( - private val selectedSiteRepository: SelectedSiteRepository, private val accountStore: AccountStore, private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, private val blazeFeatureUtils: BlazeFeatureUtils ) { - private val _onNavigation = MutableLiveData>() - val onNavigation = _onNavigation - - private val _onSnackbarMessage = MutableLiveData>() - val onSnackbarMessage = _onSnackbarMessage - - fun handleAction(action: ListItemAction) { - selectedSiteRepository.getSelectedSite()?.let { selectedSite -> - val navigationAction = when (action) { - ListItemAction.ACTIVITY_LOG -> SiteNavigationAction.OpenActivityLog(selectedSite) - ListItemAction.BACKUP -> SiteNavigationAction.OpenBackup(selectedSite) - ListItemAction.SCAN -> SiteNavigationAction.OpenScan(selectedSite) - ListItemAction.PLAN -> SiteNavigationAction.OpenPlan(selectedSite) - ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) - ListItemAction.PAGES -> { - SiteNavigationAction.OpenPages(selectedSite) - } - - ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) - ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) - ListItemAction.SHARING -> { - SiteNavigationAction.OpenSharing(selectedSite) - } + fun handleAction(action: ListItemAction, selectedSite: SiteModel): SiteNavigationAction { + return when (action) { + ListItemAction.ACTIVITY_LOG -> SiteNavigationAction.OpenActivityLog(selectedSite) + ListItemAction.BACKUP -> SiteNavigationAction.OpenBackup(selectedSite) + ListItemAction.SCAN -> SiteNavigationAction.OpenScan(selectedSite) + ListItemAction.PLAN -> SiteNavigationAction.OpenPlan(selectedSite) + ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) + ListItemAction.PAGES -> { + SiteNavigationAction.OpenPages(selectedSite) + } - ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) - ListItemAction.ME -> SiteNavigationAction.OpenMeScreen - ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) - ListItemAction.THEMES -> SiteNavigationAction.OpenThemes(selectedSite) - ListItemAction.PLUGINS -> SiteNavigationAction.OpenPlugins(selectedSite) - ListItemAction.STATS -> getStatsNavigationActionForSite(selectedSite) - ListItemAction.MEDIA -> SiteNavigationAction.OpenMedia(selectedSite) - ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) - ListItemAction.BLAZE -> onBlazeMenuItemClick() - ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite) + ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) + ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) + ListItemAction.SHARING -> { + SiteNavigationAction.OpenSharing(selectedSite) } - _onNavigation.postValue(Event(navigationAction)) - } ?: _onSnackbarMessage.postValue( - Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded))) - ) + + ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) + ListItemAction.ME -> SiteNavigationAction.OpenMeScreen + ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) + ListItemAction.THEMES -> SiteNavigationAction.OpenThemes(selectedSite) + ListItemAction.PLUGINS -> SiteNavigationAction.OpenPlugins(selectedSite) + ListItemAction.STATS -> getStatsNavigationActionForSite(selectedSite) + ListItemAction.MEDIA -> SiteNavigationAction.OpenMedia(selectedSite) + ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) + ListItemAction.BLAZE -> onBlazeMenuItemClick() + ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite) + } } private fun getStatsNavigationActionForSite(site: SiteModel): SiteNavigationAction = when { From b64dde3fac4266f3da6d7d02910926cc3bcd9409 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:10:54 +0530 Subject: [PATCH 03/21] + Adds: QuickLinksItemViewModelSlice + Adds: QuickLinksItemViewModelSlice to show the logic of active quick links --- .../QuickLinksItemViewModelSlice.kt | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt new file mode 100644 index 000000000000..a71be3f8e5f4 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt @@ -0,0 +1,175 @@ +package org.wordpress.android.ui.mysite.cards.quicklinksribbon + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import org.wordpress.android.R +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.modules.BG_THREAD +import org.wordpress.android.ui.blaze.BlazeFeatureUtils +import org.wordpress.android.ui.jetpack.JetpackCapabilitiesUseCase +import org.wordpress.android.ui.mysite.MySiteCardAndItem +import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams +import org.wordpress.android.ui.mysite.SelectedSiteRepository +import org.wordpress.android.ui.mysite.SiteNavigationAction +import org.wordpress.android.ui.mysite.cards.ListItemActionHandler +import org.wordpress.android.ui.mysite.items.listitem.ListItemAction +import org.wordpress.android.ui.mysite.items.listitem.SiteItemsBuilder +import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.ui.prefs.AppPrefsWrapper +import org.wordpress.android.ui.utils.ListItemInteraction +import org.wordpress.android.ui.utils.UiString +import org.wordpress.android.viewmodel.Event +import javax.inject.Inject +import javax.inject.Named + +class QuickLinksItemViewModelSlice @Inject constructor( + private val selectedSiteRepository: SelectedSiteRepository, + @param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, + private val siteItemsBuilder: SiteItemsBuilder, + private val jetpackCapabilitiesUseCase: JetpackCapabilitiesUseCase, + private val listItemActionHandler: ListItemActionHandler, + private val blazeFeatureUtils: BlazeFeatureUtils, + private val appPrefsWrapper: AppPrefsWrapper +) { + lateinit var scope: CoroutineScope + + fun initialization(scope: CoroutineScope) { + this.scope = scope + } + + private val _onNavigation = MutableLiveData>() + val navigation = _onNavigation + + private val _onSnackbarMessage = MutableLiveData>() + val onSnackbarMessage = _onSnackbarMessage + + private val _uiState = MutableLiveData() + val uiState: LiveData = _uiState + + fun start() { + val site = selectedSiteRepository.getSelectedSite()!! + buildQuickLinks(site) + } + + fun onResume() { + val site = selectedSiteRepository.getSelectedSite()!! + buildQuickLinks(site) + } + + fun onRefresh() { + val site = selectedSiteRepository.getSelectedSite()!! + buildQuickLinks(site) + } + + private fun buildQuickLinks(site: SiteModel) { + scope.launch { + _uiState.postValue( + convertToQuickLinkRibbonItem( + siteItemsBuilder.build( + MySiteCardAndItemBuilderParams.SiteItemsBuilderParams( + enableFocusPoints = true, + site = site, + activeTask = null, + onClick = this@QuickLinksItemViewModelSlice::onClick, + isBlazeEligible = isSiteBlazeEligible() + ) + ) + ) + ) + updateSiteItemsForJetpackCapabilities(site) + } + } + + private fun updateSiteItemsForJetpackCapabilities(site: SiteModel) { + scope.launch(bgDispatcher) { + jetpackCapabilitiesUseCase.getJetpackPurchasedProducts(site.siteId).collect { + _uiState.postValue( + convertToQuickLinkRibbonItem( + siteItemsBuilder.build( + MySiteCardAndItemBuilderParams.SiteItemsBuilderParams( + site = site, + enableFocusPoints = true, + activeTask = null, + onClick = this@QuickLinksItemViewModelSlice::onClick, + isBlazeEligible = isSiteBlazeEligible(), + backupAvailable = it.backup, + scanAvailable = (it.scan && !site.isWPCom && !site.isWPComAtomic) + ) + ) + ) + ) + } // end collect + } + } + + private fun convertToQuickLinkRibbonItem(listItems: List): + MySiteCardAndItem.Card.QuickLinkRibbon { + val siteId = selectedSiteRepository.getSelectedSite()!!.siteId + val activeListItems = listItems.filterIsInstance(MySiteCardAndItem.Item.ListItem::class.java) + .filter { isActiveQuickLink(it.listItemAction, siteId = siteId) } + val activeQuickLinks = activeListItems.map { listItem -> + MySiteCardAndItem.Card.QuickLinkRibbon.QuickLinkRibbonItem( + icon = listItem.primaryIcon, + label = (listItem.primaryText as UiString.UiStringRes), + onClick = listItem.onClick + ) + } + val moreQuickLink = MySiteCardAndItem.Card.QuickLinkRibbon.QuickLinkRibbonItem( + icon = R.drawable.ic_more_horiz_white_24dp, + label = UiString.UiStringRes(R.string.more), + onClick = ListItemInteraction.create( + ListItemAction.MORE, + this@QuickLinksItemViewModelSlice::onClick + ) + ) + return MySiteCardAndItem.Card.QuickLinkRibbon( + quickLinkRibbonItems = activeQuickLinks + moreQuickLink + ) + } + + private fun isSiteBlazeEligible() = + blazeFeatureUtils.isSiteBlazeEligible(selectedSiteRepository.getSelectedSite()!!) + + + private fun onClick(action: ListItemAction) { + selectedSiteRepository.getSelectedSite()?.let { selectedSite -> + // add the tracking logic here + _onNavigation.postValue(Event(listItemActionHandler.handleAction(action, selectedSite))) + }?: run { + _onSnackbarMessage.postValue( + Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded))) + ) + } + } + + fun onCleared() { + jetpackCapabilitiesUseCase.clear() + } + + private fun isActiveQuickLink(listItemAction: ListItemAction, siteId: Long): Boolean { + return when (listItemAction) { + in defaultShortcuts() -> { + appPrefsWrapper.getShouldShowDefaultQuickLink( + listItemAction.toString(), siteId + ) + } + + else -> { + appPrefsWrapper.getShouldShowSiteItemAsQuickLink( + listItemAction.toString(), siteId + ) + } + } + } + + private fun defaultShortcuts(): List { + return listOf( + ListItemAction.POSTS, + ListItemAction.PAGES, + ListItemAction.STATS + ) + } +} From 0a4ce6c6bf9ca3eab57b7bea9c4b187745b32daf Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:25:17 +0530 Subject: [PATCH 04/21] - Removes: redundantQuickLinkRibbonBuilder.kt --- .../QuickLinkRibbonBuilder.kt | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilder.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilder.kt deleted file mode 100644 index a7d4b0fd47d9..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilder.kt +++ /dev/null @@ -1,89 +0,0 @@ -package org.wordpress.android.ui.mysite.cards.quicklinksribbon - -import org.wordpress.android.R -import org.wordpress.android.fluxc.store.QuickStartStore -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartNewSiteTask -import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickLinkRibbon -import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickLinkRibbon.QuickLinkRibbonItem -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams -import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository -import org.wordpress.android.ui.utils.ListItemInteraction -import javax.inject.Inject - -class QuickLinkRibbonBuilder @Inject constructor( - val quickStartRepository: QuickStartRepository -) { - fun build(params: QuickLinkRibbonBuilderParams) = QuickLinkRibbon( - quickLinkRibbonItems = getQuickLinkRibbonItems(params), - showPagesFocusPoint = shouldShowPagesFocusPoint(params), - showStatsFocusPoint = shouldShowStatsFocusPoint(params), - showMediaFocusPoint = shouldShowMediaFocusPoint(params) - ) - - private fun getQuickLinkRibbonItems(params: QuickLinkRibbonBuilderParams): MutableList { - val items = mutableListOf() - items.apply { - add( - QuickLinkRibbonItem( - label = R.string.stats, - icon = R.drawable.ic_stats_alt_white_24dp, - onClick = ListItemInteraction.create(params.onStatsClick), - showFocusPoint = shouldShowStatsFocusPoint(params) - ) - ) - add( - QuickLinkRibbonItem( - label = R.string.posts, - icon = R.drawable.ic_posts_white_24dp, - onClick = ListItemInteraction.create(params.onPostsClick) - ) - ) - add( - QuickLinkRibbonItem( - label = R.string.media, - icon = R.drawable.ic_media_white_24dp, - onClick = ListItemInteraction.create(params.onMediaClick), - showFocusPoint = shouldShowMediaFocusPoint(params) - ) - ) - add( - QuickLinkRibbonItem( - label = R.string.more, - icon = R.drawable.ic_more_horiz_white_24dp, - onClick = ListItemInteraction.create(params.onMoreClick), - showFocusPoint = false - ) - ) - } - if (params.siteModel.isSelfHostedAdmin || params.siteModel.hasCapabilityEditPages) { - val pages = QuickLinkRibbonItem( - label = R.string.pages, - icon = R.drawable.ic_pages_white_24dp, - onClick = ListItemInteraction.create(params.onPagesClick), - showFocusPoint = shouldShowPagesFocusPoint(params) - ) - items.add(QUICK_LINK_PAGE_INDEX, pages) - } - return items - } - - private fun shouldShowPagesFocusPoint(params: QuickLinkRibbonBuilderParams): Boolean { - return params.activeTask == QuickStartNewSiteTask.REVIEW_PAGES - } - - private fun shouldShowStatsFocusPoint(params: QuickLinkRibbonBuilderParams): Boolean { - return params.activeTask == quickStartRepository.quickStartType.getTaskFromString( - QuickStartStore.QUICK_START_CHECK_STATS_LABEL - ) - } - - private fun shouldShowMediaFocusPoint(params: QuickLinkRibbonBuilderParams): Boolean { - return params.activeTask == quickStartRepository.quickStartType.getTaskFromString( - QuickStartStore.QUICK_START_UPLOAD_MEDIA_LABEL - ) - } - - companion object { - private const val QUICK_LINK_PAGE_INDEX = 2 - } -} From e7f2e0def0331fe3f76e4481eb9f62f25b451161 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:25:57 +0530 Subject: [PATCH 05/21] - Removes: QuickLinkRibbonBuilder from card builder --- .../org/wordpress/android/ui/mysite/cards/CardsBuilder.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/CardsBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/CardsBuilder.kt index 31ad8870e91d..725bdf80aae3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/CardsBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/CardsBuilder.kt @@ -5,18 +5,15 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistration import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DashboardCardsBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DomainRegistrationCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.JetpackInstallFullPluginCardBuilderParams -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickStartCardBuilderParams import org.wordpress.android.ui.mysite.cards.dashboard.CardsBuilder import org.wordpress.android.ui.mysite.cards.jpfullplugininstall.JetpackInstallFullPluginCardBuilder -import org.wordpress.android.ui.mysite.cards.quicklinksribbon.QuickLinkRibbonBuilder import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardBuilder import org.wordpress.android.ui.utils.ListItemInteraction import javax.inject.Inject class CardsBuilder @Inject constructor( private val quickStartCardBuilder: QuickStartCardBuilder, - private val quickLinkRibbonBuilder: QuickLinkRibbonBuilder, private val dashboardCardsBuilder: CardsBuilder, private val jetpackInstallFullPluginCardBuilder: JetpackInstallFullPluginCardBuilder, ) { @@ -25,14 +22,9 @@ class CardsBuilder @Inject constructor( domainRegistrationCardBuilderParams: DomainRegistrationCardBuilderParams, quickStartCardBuilderParams: QuickStartCardBuilderParams, dashboardCardsBuilderParams: DashboardCardsBuilderParams, - quickLinkRibbonBuilderParams: QuickLinkRibbonBuilderParams, jetpackInstallFullPluginCardBuilderParams: JetpackInstallFullPluginCardBuilderParams, - isMySiteTabsEnabled: Boolean ): List { val cards = mutableListOf() - if (isMySiteTabsEnabled) { - cards.add(quickLinkRibbonBuilder.build(quickLinkRibbonBuilderParams)) - } jetpackInstallFullPluginCardBuilder.build(jetpackInstallFullPluginCardBuilderParams)?.let { cards.add(it) } From 140e896903d35ea40f413a7485301dc5567b7594 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:26:59 +0530 Subject: [PATCH 06/21] =?UTF-8?q?=E2=86=91=20Updates:=20the=20viewholder?= =?UTF-8?q?=20to=20remove=20stats,pages=20and=20media=20focus=20points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quicklinksribbon/QuickLinkRibbonItemViewHolder.kt | 2 +- .../quicklinksribbon/QuickLinkRibbonViewHolder.kt | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonItemViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonItemViewHolder.kt index a2ce78562075..ede54d923fe3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonItemViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonItemViewHolder.kt @@ -11,7 +11,7 @@ class QuickLinkRibbonItemViewHolder( private val binding: QuickLinkRibbonItemBinding = parent.viewBinding(QuickLinkRibbonItemBinding::inflate) ) : RecyclerView.ViewHolder(binding.root) { fun onBind(item: QuickLinkRibbonItem) = with(binding) { - quickLinkItem.setText(item.label) + quickLinkItem.setText(item.label.stringRes) quickLinkItem.setIconResource(item.icon) quickLinkItem.setOnClickListener { item.onClick.click() } quickLinkItemQuickStartFocusPoint.setVisibleOrGone(item.showFocusPoint) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt index ed8c372e02e2..b27ba14367c5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt @@ -34,14 +34,8 @@ class QuickLinkRibbonViewHolder( } ) (quickLinkRibbonItemList.adapter as QuickLinkRibbonItemAdapter).update(quickLinkRibbon.quickLinkRibbonItems) - if (quickLinkRibbon.showStatsFocusPoint) { - quickLinkRibbonItemList.smoothScrollToPosition(0) - } - if (quickLinkRibbon.showPagesFocusPoint) { - quickLinkRibbonItemList.smoothScrollToPosition(2) - } - if (quickLinkRibbon.showMediaFocusPoint) { - quickLinkRibbonItemList.smoothScrollToPosition(quickLinkRibbon.quickLinkRibbonItems.size) + if (quickLinkRibbon.showMoreFocusPoint) { + quickLinkRibbonItemList.smoothScrollToPosition(quickLinkRibbonItemList.adapter!!.itemCount - 1) } } } From 15afb803bf86ef914584aeda1459bf9f9630ab61 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:28:09 +0530 Subject: [PATCH 07/21] =?UTF-8?q?=E2=86=91=20Updates:=20the=20SiteItemsVie?= =?UTF-8?q?wModelSlice=20to=20use=20list=20action=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../items/listitem/SiteItemsViewModelSlice.kt | 81 ++----------------- 1 file changed, 8 insertions(+), 73 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt index dd913244a215..016e9cc561f5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt @@ -15,7 +15,7 @@ import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction -import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository +import org.wordpress.android.ui.mysite.cards.ListItemActionHandler import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiString import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -28,12 +28,10 @@ private const val TYPE = "type" @Singleton @Suppress("LongParameterList") class SiteItemsViewModelSlice @Inject constructor( - private val quickStartRepository: QuickStartRepository, private val selectedSiteRepository: SelectedSiteRepository, private val analyticsTrackerWrapper: AnalyticsTrackerWrapper, - private val accountStore: AccountStore, - private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, private val blazeFeatureUtils: BlazeFeatureUtils, + private val listItemActionHandler: ListItemActionHandler ) { private val _onNavigation = MutableLiveData>() val onNavigation = _onNavigation @@ -66,77 +64,14 @@ class SiteItemsViewModelSlice @Inject constructor( AnalyticsTracker.Stat.MY_SITE_MENU_ITEM_TAPPED, mapOf(TYPE to action.trackingLabel) ) - val navigationAction = when (action) { - ListItemAction.ACTIVITY_LOG -> SiteNavigationAction.OpenActivityLog(selectedSite) - ListItemAction.BACKUP -> SiteNavigationAction.OpenBackup(selectedSite) - ListItemAction.SCAN -> SiteNavigationAction.OpenScan(selectedSite) - ListItemAction.PLAN -> SiteNavigationAction.OpenPlan(selectedSite) - ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) - ListItemAction.PAGES -> { - quickStartRepository.completeTask(QuickStartStore.QuickStartNewSiteTask.REVIEW_PAGES) - SiteNavigationAction.OpenPages(selectedSite) - } - ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) - ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) - ListItemAction.SHARING -> { - quickStartRepository.requestNextStepOfTask( - QuickStartStore.QuickStartNewSiteTask.ENABLE_POST_SHARING - ) - SiteNavigationAction.OpenSharing(selectedSite) - } - ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) - ListItemAction.ME -> SiteNavigationAction.OpenMeScreen - ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) - ListItemAction.THEMES -> SiteNavigationAction.OpenThemes(selectedSite) - ListItemAction.PLUGINS -> SiteNavigationAction.OpenPlugins(selectedSite) - ListItemAction.STATS -> { - quickStartRepository.completeTask( - quickStartRepository.quickStartType.getTaskFromString(QUICK_START_CHECK_STATS_LABEL) - ) - getStatsNavigationActionForSite(selectedSite) - } - - ListItemAction.MEDIA -> { - quickStartRepository.requestNextStepOfTask( - quickStartRepository.quickStartType.getTaskFromString(QUICK_START_UPLOAD_MEDIA_LABEL) - ) - SiteNavigationAction.OpenMedia(selectedSite) - } - - ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) - - ListItemAction.BLAZE -> onBlazeMenuItemClick() - ListItemAction.MORE -> TODO() - } - _onNavigation.postValue(Event(navigationAction)) - } ?: _onSnackbarMessage.postValue( - Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded))) - ) - } - - private fun getStatsNavigationActionForSite(site: SiteModel): SiteNavigationAction = when { - // if we are in static posters phase - we don't want to show any connection/login messages - jetpackFeatureRemovalPhaseHelper.shouldShowStaticPage() -> - SiteNavigationAction.ShowJetpackRemovalStaticPostersView - - // If the user is not logged in and the site is already connected to Jetpack, ask to login. - !accountStore.hasAccessToken() && site.isJetpackConnected -> SiteNavigationAction.StartWPComLoginForJetpackStats - - // If it's a WordPress.com or Jetpack site, show the Stats screen. - site.isWPCom || site.isJetpackInstalled && site.isJetpackConnected -> SiteNavigationAction.OpenStats(site) - - // If it's a self-hosted site, ask to connect to Jetpack. - else -> SiteNavigationAction.ConnectJetpackForStats(site) + _onNavigation.postValue(Event(listItemActionHandler.handleAction(action, selectedSite))) + }?: run { + _onSnackbarMessage.postValue( + Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded))) + ) + } } private fun isSiteBlazeEligible() = blazeFeatureUtils.isSiteBlazeEligible(selectedSiteRepository.getSelectedSite()!!) - - private fun onBlazeMenuItemClick(): SiteNavigationAction { - blazeFeatureUtils.trackEntryPointTapped(BlazeFlowSource.MENU_ITEM) - if (blazeFeatureUtils.shouldShowBlazeCampaigns()) { - return SiteNavigationAction.OpenCampaignListingPage(CampaignListingPageSource.MENU_ITEM) - } - return SiteNavigationAction.OpenPromoteWithBlazeOverlay(BlazeFlowSource.MENU_ITEM) - } } From f3b0d6b99f196c56e2adf94550215fc0912fb396 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:28:40 +0530 Subject: [PATCH 08/21] =?UTF-8?q?=E2=86=91=20Updates:=20the=20MenuViewMode?= =?UTF-8?q?l=20to=20use=20list=20action=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/ui/mysite/menu/MenuViewModel.kt | 68 ++++++++++++++++--- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuViewModel.kt index 37bfd25fe9fe..8712f34f8a14 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuViewModel.kt @@ -6,14 +6,18 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.modules.BG_THREAD +import org.wordpress.android.ui.blaze.BlazeFeatureUtils import org.wordpress.android.ui.jetpack.JetpackCapabilitiesUseCase import org.wordpress.android.ui.mysite.MySiteCardAndItem +import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction +import org.wordpress.android.ui.mysite.cards.ListItemActionHandler +import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository +import org.wordpress.android.ui.mysite.items.listitem.ListItemAction import org.wordpress.android.ui.mysite.items.listitem.SiteItemsBuilder -import org.wordpress.android.ui.mysite.items.listitem.SiteItemsViewModelSlice -import org.wordpress.android.util.merge import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ScopedViewModel import javax.inject.Inject @@ -25,14 +29,16 @@ data class MenuViewState( @HiltViewModel class MenuViewModel @Inject constructor( + private val quickStartRepository: QuickStartRepository, private val selectedSiteRepository: SelectedSiteRepository, @param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, private val siteItemsBuilder: SiteItemsBuilder, - private val siteItemsViewModelSlice: SiteItemsViewModelSlice, - private val jetpackCapabilitiesUseCase: JetpackCapabilitiesUseCase + private val jetpackCapabilitiesUseCase: JetpackCapabilitiesUseCase, + private val listItemActionHandler: ListItemActionHandler, + private val blazeFeatureUtils: BlazeFeatureUtils ) : ScopedViewModel(bgDispatcher) { private val _onNavigation = MutableLiveData>() - val navigation = merge(_onNavigation, siteItemsViewModelSlice.onNavigation) + val navigation = _onNavigation private val _uiState = MutableStateFlow(MenuViewState(items = emptyList())) @@ -46,12 +52,12 @@ class MenuViewModel @Inject constructor( private fun buildSiteMenu(site: SiteModel) { _uiState.value = MenuViewState( items = siteItemsBuilder.build( - siteItemsViewModelSlice.buildItems( - shouldEnableFocusPoints = true, + MySiteCardAndItemBuilderParams.SiteItemsBuilderParams( + enableFocusPoints = true, site = site, activeTask = null, - backupAvailable = false, - scanAvailable = false + onClick = this::onClick, + isBlazeEligible = isSiteBlazeEligible() ) ) ) @@ -63,10 +69,12 @@ class MenuViewModel @Inject constructor( jetpackCapabilitiesUseCase.getJetpackPurchasedProducts(site.siteId).collect { _uiState.value = MenuViewState( items = siteItemsBuilder.build( - siteItemsViewModelSlice.buildItems( - shouldEnableFocusPoints = true, + MySiteCardAndItemBuilderParams.SiteItemsBuilderParams( site = site, + enableFocusPoints = true, activeTask = null, + onClick = this@MenuViewModel::onClick, + isBlazeEligible = isSiteBlazeEligible(), backupAvailable = it.backup, scanAvailable = (it.scan && !site.isWPCom && !site.isWPComAtomic) ) @@ -76,6 +84,44 @@ class MenuViewModel @Inject constructor( } } + private fun isSiteBlazeEligible() = + blazeFeatureUtils.isSiteBlazeEligible(selectedSiteRepository.getSelectedSite()!!) + + + private fun onClick(action: ListItemAction) { + selectedSiteRepository.getSelectedSite()?.let { selectedSite -> + when(action){ + ListItemAction.PAGES -> { + quickStartRepository.completeTask(QuickStartStore.QuickStartNewSiteTask.REVIEW_PAGES) + } + ListItemAction.SHARING -> { + quickStartRepository.requestNextStepOfTask( + QuickStartStore.QuickStartNewSiteTask.ENABLE_POST_SHARING + ) + } + ListItemAction.STATS -> { + quickStartRepository.completeTask( + quickStartRepository.quickStartType.getTaskFromString( + QuickStartStore.QUICK_START_CHECK_STATS_LABEL + ) + ) + } + + ListItemAction.MEDIA -> { + quickStartRepository.requestNextStepOfTask( + quickStartRepository.quickStartType.getTaskFromString( + QuickStartStore.QUICK_START_UPLOAD_MEDIA_LABEL + ) + ) + } + + else -> {} + } + // add the tracking logic here + _onNavigation.postValue(Event(listItemActionHandler.handleAction(action, selectedSite))) + } + } + override fun onCleared() { jetpackCapabilitiesUseCase.clear() super.onCleared() From 953e61f6d91be49226efe23560c791f6834a3a6e Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:30:17 +0530 Subject: [PATCH 09/21] =?UTF-8?q?=E2=86=91=20Updates:=20the=20quick=20link?= =?UTF-8?q?=20ribbon=20to=20remove=20pages,stats=20and=20media=20QS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wordpress/android/ui/mysite/MySiteCardAndItem.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt index 23465715c5e1..52b9bc21204f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt @@ -85,16 +85,14 @@ sealed class MySiteCardAndItem(open val type: Type, open val activeQuickStartIte override val activeQuickStartItem: Boolean = false ) : MySiteCardAndItem(type, activeQuickStartItem) { data class QuickLinkRibbon( - val quickLinkRibbonItems: List, - val showPagesFocusPoint: Boolean = false, - val showStatsFocusPoint: Boolean = false, - val showMediaFocusPoint: Boolean = false + val quickLinkRibbonItems: List + val showMoreFocusPoint : Boolean = false ) : Card( QUICK_LINK_RIBBON, - activeQuickStartItem = showPagesFocusPoint || showStatsFocusPoint || showMediaFocusPoint + activeQuickStartItem = showMoreFocusPoint ) { data class QuickLinkRibbonItem( - @StringRes val label: Int, + val label: UiString.UiStringRes, @DrawableRes val icon: Int, val onClick: ListItemInteraction, val showFocusPoint: Boolean = false From f52c0f68f7a5c2c46cce3da47743da271a138722 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:31:10 +0530 Subject: [PATCH 10/21] + Adds: QuickLinkRibbonViewModelSlice to MySiteViewModel + Adds: QuickLinkRibbonViewModelSlice to MySiteViewModel --- .../android/ui/mysite/MySiteViewModel.kt | 87 +++++-------------- 1 file changed, 24 insertions(+), 63 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index 0b3be38f3a28..d01fba4f401d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -9,7 +9,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.distinctUntilChanged -import androidx.lifecycle.map import androidx.lifecycle.switchMap import androidx.lifecycle.viewModelScope import kotlinx.coroutines.CoroutineDispatcher @@ -28,8 +27,6 @@ import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.PostStore.OnPostUploaded -import org.wordpress.android.fluxc.store.QuickStartStore.Companion.QUICK_START_CHECK_STATS_LABEL -import org.wordpress.android.fluxc.store.QuickStartStore.Companion.QUICK_START_UPLOAD_MEDIA_LABEL import org.wordpress.android.fluxc.store.QuickStartStore.Companion.QUICK_START_VIEW_SITE_LABEL import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartNewSiteTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask @@ -56,7 +53,6 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DashboardC import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DomainRegistrationCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.InfoItemBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.JetpackInstallFullPluginCardBuilderParams -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickStartCardBuilderParams import org.wordpress.android.ui.mysite.MySiteUiState.PartialState import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.BlazeCardUpdate @@ -81,6 +77,7 @@ import org.wordpress.android.ui.mysite.cards.jpfullplugininstall.JetpackInstallF import org.wordpress.android.ui.mysite.cards.nocards.NoCardsMessageViewModelSlice import org.wordpress.android.ui.mysite.cards.personalize.PersonalizeCardBuilder import org.wordpress.android.ui.mysite.cards.personalize.PersonalizeCardViewModelSlice +import org.wordpress.android.ui.mysite.cards.quicklinksribbon.QuickLinksItemViewModelSlice import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardBuilder import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardType import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository @@ -172,7 +169,8 @@ class MySiteViewModel @Inject constructor( private val personalizeCardBuilder: PersonalizeCardBuilder, private val bloggingPromptCardViewModelSlice: BloggingPromptCardViewModelSlice, private val noCardsMessageViewModelSlice: NoCardsMessageViewModelSlice, - private val siteInfoHeaderCardViewModelSlice: SiteInfoHeaderCardViewModelSlice + private val siteInfoHeaderCardViewModelSlice: SiteInfoHeaderCardViewModelSlice, + private val quickLinksItemViewModelSlice: QuickLinksItemViewModelSlice ) : ScopedViewModel(mainDispatcher) { private val _onSnackbarMessage = MutableLiveData>() private val _onNavigation = MutableLiveData>() @@ -208,7 +206,8 @@ class MySiteViewModel @Inject constructor( quickStartRepository.onSnackbar, siteItemsViewModelSlice.onSnackbarMessage, bloggingPromptCardViewModelSlice.onSnackbarMessage, - siteInfoHeaderCardViewModelSlice.onSnackbarMessage + siteInfoHeaderCardViewModelSlice.onSnackbarMessage, + quickLinksItemViewModelSlice.onSnackbarMessage ) val onQuickStartMySitePrompts = quickStartRepository.onQuickStartMySitePrompts @@ -228,7 +227,8 @@ class MySiteViewModel @Inject constructor( siteItemsViewModelSlice.onNavigation, bloggingPromptCardViewModelSlice.onNavigation, personalizeCardViewModelSlice.onNavigation, - siteInfoHeaderCardViewModelSlice.onNavigation + siteInfoHeaderCardViewModelSlice.onNavigation, + quickLinksItemViewModelSlice.navigation ) val onMediaUpload = siteInfoHeaderCardViewModelSlice.onMediaUpload @@ -265,8 +265,8 @@ class MySiteViewModel @Inject constructor( result.filter { it.siteId == null || it.state.site != null }.mapSafe { it.state } } - val uiModel: LiveData = state.map { - with(it) { + val uiModel: LiveData = merge(state, quickLinksItemViewModelSlice.uiState) { cards, quickLinks -> + with(requireNotNull(cards)) { val state = if (site != null) { cardsUpdate?.checkAndShowSnackbarError() val state = buildSiteSelectedStateAndScroll( @@ -279,7 +279,8 @@ class MySiteViewModel @Inject constructor( scanAvailable, cardsUpdate, bloggingPromptsUpdate, - blazeCardUpdate + blazeCardUpdate, + quickLinks ) trackCardsAndItemsShownIfNeeded(state) @@ -287,7 +288,6 @@ class MySiteViewModel @Inject constructor( viewModelScope, state.dashboardCardsAndItems.filterIsInstance() ) - state } else { buildNoSiteState() @@ -314,6 +314,8 @@ class MySiteViewModel @Inject constructor( dispatcher.register(this) bloggingPromptCardViewModelSlice.initialize(viewModelScope, mySiteSourceManager) siteInfoHeaderCardViewModelSlice.initialize(viewModelScope) + quickLinksItemViewModelSlice.initialization(viewModelScope) + quickLinksItemViewModelSlice.start() } @Suppress("LongParameterList") @@ -327,7 +329,8 @@ class MySiteViewModel @Inject constructor( scanAvailable: Boolean, cardsUpdate: CardsUpdate?, bloggingPromptUpdate: BloggingPromptUpdate?, - blazeCardUpdate: BlazeCardUpdate? + blazeCardUpdate: BlazeCardUpdate?, + quickLinks: MySiteCardAndItem.Card.QuickLinkRibbon? = null ): SiteSelected { val siteItems = buildSiteSelectedState( site, @@ -338,7 +341,8 @@ class MySiteViewModel @Inject constructor( scanAvailable, cardsUpdate, bloggingPromptUpdate, - blazeCardUpdate + blazeCardUpdate, + quickLinks ) val siteInfo = siteInfoHeaderCardBuilder.buildSiteInfoCard( @@ -378,7 +382,7 @@ class MySiteViewModel @Inject constructor( else -> false } - @Suppress("LongParameterList","CyclomaticComplexMethod") + @Suppress("LongParameterList", "CyclomaticComplexMethod") private fun buildSiteSelectedState( site: SiteModel, activeTask: QuickStartTask?, @@ -388,7 +392,8 @@ class MySiteViewModel @Inject constructor( scanAvailable: Boolean, cardsUpdate: CardsUpdate?, bloggingPromptUpdate: BloggingPromptUpdate?, - blazeCardUpdate: BlazeCardUpdate? + blazeCardUpdate: BlazeCardUpdate?, + quickLinks: MySiteCardAndItem.Card.QuickLinkRibbon? ): Map> { val infoItem = mySiteInfoItemBuilder.build( InfoItemBuilderParams( @@ -452,17 +457,7 @@ class MySiteViewModel @Inject constructor( cardsUpdate?.cards?.firstOrNull { it is ActivityCardModel } as? ActivityCardModel ), ), - QuickLinkRibbonBuilderParams( - siteModel = site, - onPagesClick = this::onQuickLinkRibbonPagesClick, - onPostsClick = this::onQuickLinkRibbonPostsClick, - onMediaClick = this::onQuickLinkRibbonMediaClick, - onStatsClick = this::onQuickLinkRibbonStatsClick, - onMoreClick = this::onQuickLinkRibbonMoreClick, - activeTask = activeTask - ), - jetpackInstallFullPluginCardParams, - isMySiteTabsEnabled + jetpackInstallFullPluginCardParams ) val siteItems = siteItemsBuilder.build( @@ -495,6 +490,7 @@ class MySiteViewModel @Inject constructor( infoItem?.let { add(infoItem) } migrationSuccessCard?.let { add(migrationSuccessCard) } jetpackInstallFullPluginCard?.let { add(jetpackInstallFullPluginCard) } + quickLinks?.let { add(quickLinks) } addAll(cardsResult) noCardsMessage?.let { add(noCardsMessage) } personalizeCard?.let { add(personalizeCard) } @@ -639,43 +635,6 @@ class MySiteViewModel @Inject constructor( mySiteSourceManager.refreshQuickStart() } - private fun onQuickLinkRibbonStatsClick() { - val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) - analyticsTrackerWrapper.track(Stat.QUICK_LINK_RIBBON_STATS_TAPPED) - quickStartRepository.completeTask( - quickStartRepository.quickStartType.getTaskFromString(QUICK_START_CHECK_STATS_LABEL) - ) - _onNavigation.value = Event(getStatsNavigationActionForSite(selectedSite)) - } - - private fun onQuickLinkRibbonPagesClick() { - val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) - analyticsTrackerWrapper.track(Stat.QUICK_LINK_RIBBON_PAGES_TAPPED) - quickStartRepository.completeTask(QuickStartNewSiteTask.REVIEW_PAGES) - _onNavigation.value = Event(SiteNavigationAction.OpenPages(selectedSite)) - } - - private fun onQuickLinkRibbonPostsClick() { - val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) - analyticsTrackerWrapper.track(Stat.QUICK_LINK_RIBBON_POSTS_TAPPED) - _onNavigation.value = Event(SiteNavigationAction.OpenPosts(selectedSite)) - } - - private fun onQuickLinkRibbonMediaClick() { - val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) - analyticsTrackerWrapper.track(Stat.QUICK_LINK_RIBBON_MEDIA_TAPPED) - quickStartRepository.requestNextStepOfTask( - quickStartRepository.quickStartType.getTaskFromString(QUICK_START_UPLOAD_MEDIA_LABEL) - ) - _onNavigation.value = Event(SiteNavigationAction.OpenMedia(selectedSite)) - } - - private fun onQuickLinkRibbonMoreClick() { - val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) - analyticsTrackerWrapper.track(Stat.QUICK_LINK_RIBBON_MORE_TAPPED) - _onNavigation.value = Event(SiteNavigationAction.OpenMore(selectedSite)) - } - private fun domainRegistrationClick() { val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) analyticsTrackerWrapper.track(Stat.DOMAIN_CREDIT_REDEMPTION_TAPPED, selectedSite) @@ -685,6 +644,7 @@ class MySiteViewModel @Inject constructor( fun refresh(isPullToRefresh: Boolean = false) { if (isPullToRefresh) analyticsTrackerWrapper.track(Stat.MY_SITE_PULL_TO_REFRESH) mySiteSourceManager.refresh() + quickLinksItemViewModelSlice.onRefresh() } fun onResume(currentTab: MySiteTabType) { @@ -694,6 +654,7 @@ class MySiteViewModel @Inject constructor( checkAndShowQuickStartNotice() bloggingPromptCardViewModelSlice.onResume(currentTab) dashboardCardPlansUtils.onResume(currentTab, uiModel.value?.state as? SiteSelected) + quickLinksItemViewModelSlice.onResume() } private fun checkAndShowJetpackFullPluginInstallOnboarding() { From f39164c6cd246458872d8809398272071f7ff1ea Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 18:32:51 +0530 Subject: [PATCH 11/21] * Fixes: tests in CardBuilderTest --- .../ui/mysite/cards/CardsBuilderTest.kt | 49 +------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt index 10ebf314c70c..1e395bce6894 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt @@ -11,7 +11,6 @@ import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType import org.wordpress.android.ui.mysite.MySiteCardAndItem import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard @@ -28,11 +27,9 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DomainTran import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.JetpackInstallFullPluginCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.PagesCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.PostCardBuilderParams -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickStartCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.TodaysStatsCardBuilderParams import org.wordpress.android.ui.mysite.cards.jpfullplugininstall.JetpackInstallFullPluginCardBuilder -import org.wordpress.android.ui.mysite.cards.quicklinksribbon.QuickLinkRibbonBuilder import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardBuilder import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardType import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository.QuickStartCategory @@ -48,9 +45,6 @@ class CardsBuilderTest { @Mock lateinit var dashboardCardsBuilder: DashboardCardsBuilder - @Mock - lateinit var quickLinkRibbonBuilder: QuickLinkRibbonBuilder - @Mock lateinit var jetpackInstallFullPluginCardBuilder: JetpackInstallFullPluginCardBuilder @@ -70,7 +64,6 @@ class CardsBuilderTest { setUpCardsBuilder() setUpQuickStartCardBuilder() setUpDashboardCardsBuilder() - setUpQuickLinkRibbonBuilder() } /* DOMAIN REGISTRATION CARD */ @@ -113,21 +106,6 @@ class CardsBuilderTest { assertThat(cards).isNotNull } - /* QUICK LINK RIBBON */ - @Test - fun `given tabs disabled, when cards are built, then quick link ribbon not built`() { - val cards = buildCards(isMySiteTabsEnabled = false) - - assertThat(cards.findQuickLinkRibbon()).isNull() - } - - @Test - fun `given tabs enabled, when cards are built, then quick link ribbon built`() { - val cards = buildCards(isMySiteTabsEnabled = true) - - assertThat(cards.findQuickLinkRibbon()).isNotNull - } - private fun List.findQuickStartCard() = this.find { it is QuickStartCard } as QuickStartCard? private fun List.findDomainRegistrationCard() = @@ -138,11 +116,9 @@ class CardsBuilderTest { @Suppress("LongMethod") private fun buildCards( - activeTask: QuickStartTask? = null, isDomainCreditAvailable: Boolean = false, isEligibleForPlansCard: Boolean = false, isQuickStartInProgress: Boolean = false, - isMySiteTabsEnabled: Boolean = false, isEligibleForDomainTransferCard: Boolean = false, ): List { return cardsBuilder.build( @@ -187,21 +163,11 @@ class CardsBuilderTest { mock() ) ), - quickLinkRibbonBuilderParams = QuickLinkRibbonBuilderParams( - siteModel = mock(), - onPagesClick = mock(), - onPostsClick = mock(), - onMediaClick = mock(), - onStatsClick = mock(), - onMoreClick = mock(), - activeTask = activeTask - ), jetpackInstallFullPluginCardBuilderParams = JetpackInstallFullPluginCardBuilderParams( site = site, onLearnMoreClick = mock(), onHideMenuItemClick = mock(), - ), - isMySiteTabsEnabled + ) ) } @@ -217,16 +183,9 @@ class CardsBuilderTest { }.whenever(dashboardCardsBuilder).build(any()) } - private fun setUpQuickLinkRibbonBuilder() { - doAnswer { - initQuickLinkRibbon() - }.whenever(quickLinkRibbonBuilder).build(any()) - } - private fun setUpCardsBuilder() { cardsBuilder = CardsBuilder( quickStartCardBuilder, - quickLinkRibbonBuilder, dashboardCardsBuilder, jetpackInstallFullPluginCardBuilder, ) @@ -251,10 +210,4 @@ class CardsBuilderTest { ) private fun initDashboardCards() = mutableListOf() - - private fun initQuickLinkRibbon(): QuickLinkRibbon { - return QuickLinkRibbon( - quickLinkRibbonItems = mock() - ) - } } From 01377de786271d1ef4e551ca7baac1c39cb2bbaa Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 19:49:21 +0530 Subject: [PATCH 12/21] * Fixes: Detekt issues --- .../android/ui/mysite/MySiteViewModel.kt | 15 --------------- .../items/listitem/SiteItemsViewModelSlice.kt | 6 ------ .../android/ui/mysite/cards/CardsBuilderTest.kt | 4 ---- 3 files changed, 25 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index d01fba4f401d..435bec998deb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -712,21 +712,6 @@ class MySiteViewModel @Inject constructor( _onSnackbarMessage.postValue(Event(SnackbarMessageHolder(getEmailValidationMessage(email)))) } - private fun getStatsNavigationActionForSite(site: SiteModel): SiteNavigationAction = when { - // if we are in static posters phase - we don't want to show any connection/login messages - jetpackFeatureRemovalPhaseHelper.shouldShowStaticPage() -> - SiteNavigationAction.ShowJetpackRemovalStaticPostersView - - // If the user is not logged in and the site is already connected to Jetpack, ask to login. - !accountStore.hasAccessToken() && site.isJetpackConnected -> SiteNavigationAction.StartWPComLoginForJetpackStats - - // If it's a WordPress.com or Jetpack site, show the Stats screen. - site.isWPCom || site.isJetpackInstalled && site.isJetpackConnected -> SiteNavigationAction.OpenStats(site) - - // If it's a self-hosted site, ask to connect to Jetpack. - else -> SiteNavigationAction.ConnectJetpackForStats(site) - } - fun onAvatarPressed() { _onNavigation.value = Event(SiteNavigationAction.OpenMeScreen) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt index 016e9cc561f5..49f961c62540 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSlice.kt @@ -4,14 +4,8 @@ import androidx.lifecycle.MutableLiveData import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.QuickStartStore -import org.wordpress.android.fluxc.store.QuickStartStore.Companion.QUICK_START_CHECK_STATS_LABEL -import org.wordpress.android.fluxc.store.QuickStartStore.Companion.QUICK_START_UPLOAD_MEDIA_LABEL import org.wordpress.android.ui.blaze.BlazeFeatureUtils -import org.wordpress.android.ui.blaze.BlazeFlowSource -import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource -import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt index 1e395bce6894..d2d3e6d7f605 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/CardsBuilderTest.kt @@ -14,7 +14,6 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType import org.wordpress.android.ui.mysite.MySiteCardAndItem import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard -import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickLinkRibbon import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickStartCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickStartCard.QuickStartTaskTypeItem import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.ActivityCardBuilderParams @@ -111,9 +110,6 @@ class CardsBuilderTest { private fun List.findDomainRegistrationCard() = this.find { it is DomainRegistrationCard } as DomainRegistrationCard? - private fun List.findQuickLinkRibbon() = - this.find { it is QuickLinkRibbon } as QuickLinkRibbon? - @Suppress("LongMethod") private fun buildCards( isDomainCreditAvailable: Boolean = false, From 888de58518aefbacfeb7781a7aaeebfebe872df6 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 20:20:13 +0530 Subject: [PATCH 13/21] * Fixes: lint issues --- .../java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt index 52b9bc21204f..e874ee9cb8bb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteCardAndItem.kt @@ -85,7 +85,7 @@ sealed class MySiteCardAndItem(open val type: Type, open val activeQuickStartIte override val activeQuickStartItem: Boolean = false ) : MySiteCardAndItem(type, activeQuickStartItem) { data class QuickLinkRibbon( - val quickLinkRibbonItems: List + val quickLinkRibbonItems: List, val showMoreFocusPoint : Boolean = false ) : Card( QUICK_LINK_RIBBON, From 36c32948eb87629c7901e25c8e7b1d718e836412 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 20:59:26 +0530 Subject: [PATCH 14/21] - Removes: quick link ribbon builder test --- .../QuickLinkRibbonBuilderTest.kt | 137 ------------------ 1 file changed, 137 deletions(-) delete mode 100644 WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilderTest.kt diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilderTest.kt deleted file mode 100644 index 3f516f7c2d22..000000000000 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonBuilderTest.kt +++ /dev/null @@ -1,137 +0,0 @@ -package org.wordpress.android.ui.mysite.cards.quicklinksribbon - -import kotlinx.coroutines.ExperimentalCoroutinesApi -import org.assertj.core.api.Assertions.assertThat -import org.junit.Before -import org.junit.Test -import org.mockito.Mock -import org.mockito.kotlin.whenever -import org.wordpress.android.BaseUnitTest -import org.wordpress.android.R -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.QuickStartStore -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartExistingSiteTask -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartNewSiteTask -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask -import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickLinkRibbon -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams -import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository -import org.wordpress.android.ui.quickstart.QuickStartType -import org.wordpress.android.ui.utils.ListItemInteraction - -@ExperimentalCoroutinesApi -class QuickLinkRibbonBuilderTest : BaseUnitTest() { - @Mock - lateinit var siteModel: SiteModel - - @Mock - lateinit var quickStartRepository: QuickStartRepository - - @Mock - lateinit var quickStartType: QuickStartType - private lateinit var builder: QuickLinkRibbonBuilder - - private val onStatsClick: () -> Unit = {} - private val onPostsClick: () -> Unit = {} - private val onPagesClick: () -> Unit = {} - private val onMediaClick: () -> Unit = {} - private val onMoreClick: () -> Unit = {} - - @Before - fun setUp() { - whenever(quickStartRepository.quickStartType).thenReturn(quickStartType) - builder = QuickLinkRibbonBuilder(quickStartRepository) - } - - @Test - fun `given site does have capabilities, when ribbon is built, then pages item is not built`() { - val quickLinkRibbon = buildQuickLinkRibbon(showPages = false) - - assertThat(quickLinkRibbon.quickLinkRibbonItems.size).isEqualTo(4) - assertThat(quickLinkRibbon.quickLinkRibbonItems[0].label).isEqualTo(R.string.stats) - assertThat(quickLinkRibbon.quickLinkRibbonItems[1].label).isEqualTo(R.string.posts) - assertThat(quickLinkRibbon.quickLinkRibbonItems[2].label).isEqualTo(R.string.media) - assertThat(quickLinkRibbon.quickLinkRibbonItems[3].label).isEqualTo(R.string.more) - } - - /* ACTION CLICKS */ - @Test - fun `when card is built, then ribbon click are set on the card`() { - val quickLinkRibbon = buildQuickLinkRibbon() - - assertThat(quickLinkRibbon.quickLinkRibbonItems[0].onClick).isEqualTo(ListItemInteraction.create(onStatsClick)) - assertThat(quickLinkRibbon.quickLinkRibbonItems[1].onClick).isEqualTo(ListItemInteraction.create(onPostsClick)) - assertThat(quickLinkRibbon.quickLinkRibbonItems[2].onClick).isEqualTo(ListItemInteraction.create(onPagesClick)) - assertThat(quickLinkRibbon.quickLinkRibbonItems[3].onClick).isEqualTo(ListItemInteraction.create(onMediaClick)) - assertThat(quickLinkRibbon.quickLinkRibbonItems[4].onClick).isEqualTo(ListItemInteraction.create(onMoreClick)) - } - - /* FOCUS POINT*/ - @Test - fun `given new site QS + stats active task, when card is built, then stats focus point should be true`() { - val quickLinkRibbon = buildQuickLinkRibbon(showStatsFocusPoint = true, isNewSiteQuickStart = true) - - assertThat(quickLinkRibbon.quickLinkRibbonItems[0].showFocusPoint).isEqualTo(true) - assertThat(quickLinkRibbon.showStatsFocusPoint).isEqualTo(true) - } - - @Test - fun `given existing site QS + stats active task, when card is built, then stats focus point should be true`() { - val quickLinkRibbon = buildQuickLinkRibbon(showStatsFocusPoint = true, isNewSiteQuickStart = false) - - assertThat(quickLinkRibbon.quickLinkRibbonItems[0].showFocusPoint).isEqualTo(true) - assertThat(quickLinkRibbon.showStatsFocusPoint).isEqualTo(true) - } - - @Test - fun `given pages active task, when card is built, then pages focus point should be true`() { - val quickLinkRibbon = buildQuickLinkRibbon(showPagesFocusPoint = true) - - assertThat(quickLinkRibbon.quickLinkRibbonItems[2].showFocusPoint).isEqualTo(true) - assertThat(quickLinkRibbon.showPagesFocusPoint).isEqualTo(true) - } - - private fun buildQuickLinkRibbon( - showPages: Boolean = true, - showPagesFocusPoint: Boolean = false, - showStatsFocusPoint: Boolean = false, - isNewSiteQuickStart: Boolean = true - ): QuickLinkRibbon { - setShowPages(showPages) - val checkStatsTask = if (isNewSiteQuickStart) { - QuickStartNewSiteTask.CHECK_STATS - } else { - QuickStartExistingSiteTask.CHECK_STATS - } - whenever(quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL)) - .thenReturn(checkStatsTask) - - return builder.build( - QuickLinkRibbonBuilderParams( - siteModel, - onPagesClick, - onPostsClick, - onMediaClick, - onStatsClick, - onMoreClick, - setActiveTask(showPagesFocusPoint, showStatsFocusPoint, checkStatsTask) - ) - ) - } - - private fun setShowPages(showPages: Boolean) { - whenever(siteModel.isSelfHostedAdmin).thenReturn(showPages) - } - - private fun setActiveTask( - showPages: Boolean, - showStats: Boolean, - checkStatsTask: QuickStartTask - ): QuickStartTask? { - return when { - showPages -> QuickStartNewSiteTask.REVIEW_PAGES - showStats -> checkStatsTask - else -> null - } - } -} From 11fed00a3fad5e9a35d9176e59dd7bfd5073272f Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 21:00:00 +0530 Subject: [PATCH 15/21] - Removes: quick link ribbon builder tests and dependencies --- .../ui/mysite/MySiteCardAndItemTest.kt | 4 +- .../android/ui/mysite/MySiteViewModelTest.kt | 27 +++----------- .../listitem/SiteItemsViewModelSliceTest.kt | 37 +++---------------- 3 files changed, 15 insertions(+), 53 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteCardAndItemTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteCardAndItemTest.kt index ff8204a6ac9c..a0bce8771276 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteCardAndItemTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteCardAndItemTest.kt @@ -8,6 +8,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.Item.CategoryHeaderItem import org.wordpress.android.ui.mysite.MySiteCardAndItem.Item.ListItem import org.wordpress.android.ui.mysite.MySiteCardAndItem.SiteInfoHeaderCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.SiteInfoHeaderCard.IconState.Visible +import org.wordpress.android.ui.mysite.items.listitem.ListItemAction import org.wordpress.android.ui.utils.ListItemInteraction import org.wordpress.android.ui.utils.UiString.UiStringText @@ -96,6 +97,7 @@ class MySiteCardAndItemTest { secondaryIcon = null, secondaryText = null, showFocusPoint = showFocusPoint, - onClick = interaction + onClick = interaction, + listItemAction = ListItemAction.STATS, ) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt index 6ebfecf462a4..fa655631f25e 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt @@ -50,7 +50,6 @@ import org.wordpress.android.ui.jetpackplugininstall.fullplugin.GetShowJetpackFu import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.ErrorCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.JetpackFeatureCard -import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickLinkRibbon import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickStartCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.QuickStartCard.QuickStartTaskTypeItem import org.wordpress.android.ui.mysite.MySiteCardAndItem.Item.InfoItem @@ -62,7 +61,6 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.SiteInfoHeaderCard.Icon import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DashboardCardsBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DomainRegistrationCardBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.InfoItemBuilderParams -import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickLinkRibbonBuilderParams import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.QuickStartCardBuilderParams import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.BloggingPromptUpdate import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.CardsUpdate @@ -93,6 +91,7 @@ import org.wordpress.android.ui.mysite.cards.jpfullplugininstall.JetpackInstallF import org.wordpress.android.ui.mysite.cards.nocards.NoCardsMessageViewModelSlice import org.wordpress.android.ui.mysite.cards.personalize.PersonalizeCardBuilder import org.wordpress.android.ui.mysite.cards.personalize.PersonalizeCardViewModelSlice +import org.wordpress.android.ui.mysite.cards.quicklinksribbon.QuickLinksItemViewModelSlice import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardBuilder import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartCardType import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository @@ -281,6 +280,9 @@ class MySiteViewModelTest : BaseUnitTest() { @Mock lateinit var siteInfoHeaderCardViewModelSlice: SiteInfoHeaderCardViewModelSlice + @Mock + lateinit var quickLinksItemViewModelSlice: QuickLinksItemViewModelSlice + private lateinit var viewModel: MySiteViewModel private lateinit var uiModels: MutableList private lateinit var snackbars: MutableList @@ -477,7 +479,8 @@ class MySiteViewModelTest : BaseUnitTest() { personalizeCardBuilder, bloggingPromptCardViewModelSlice, noCardsMessageViewModelSlice, - siteInfoHeaderCardViewModelSlice + siteInfoHeaderCardViewModelSlice, + quickLinksItemViewModelSlice ) uiModels = mutableListOf() snackbars = mutableListOf() @@ -1600,7 +1603,6 @@ class MySiteViewModelTest : BaseUnitTest() { private fun setUpCardsBuilder() { doAnswer { - val quickLinkRibbon = initQuickLinkRibbon(it) val domainRegistrationCard = initDomainRegistrationCard(it) val quickStartCard = initQuickStartCard(it) val dashboardCards = initDashboardCards(it) @@ -1610,16 +1612,12 @@ class MySiteViewModelTest : BaseUnitTest() { ) listOfCards.addAll(dashboardCards) - if (mySiteDashboardTabsFeatureConfig.isEnabled()) - listOfCards.add(quickLinkRibbon) listOfCards }.whenever(cardsBuilder).build( domainRegistrationCardBuilderParams = any(), quickStartCardBuilderParams = any(), dashboardCardsBuilderParams = any(), - quickLinkRibbonBuilderParams = any(), jetpackInstallFullPluginCardBuilderParams = any(), - isMySiteTabsEnabled = any() ) doAnswer { @@ -1671,19 +1669,6 @@ class MySiteViewModelTest : BaseUnitTest() { ) } - private fun initQuickLinkRibbon(mockInvocation: InvocationOnMock): QuickLinkRibbon { - val params = (mockInvocation.arguments.filterIsInstance()).first() - quickLinkRibbonPagesClickAction = params.onPagesClick - quickLinkRibbonPostsClickAction = params.onPostsClick - quickLinkRibbonMediaClickAction = params.onMediaClick - quickLinkRibbonStatsClickAction = params.onStatsClick - return QuickLinkRibbon( - quickLinkRibbonItems = mock(), - showStatsFocusPoint = false, - showPagesFocusPoint = false - ) - } - private fun initDomainRegistrationCard(mockInvocation: InvocationOnMock) = DomainRegistrationCard( ListItemInteraction.create { (mockInvocation.arguments.filterIsInstance()).first() diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt index 2d567975346a..bf5d83ba7428 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt @@ -17,10 +17,9 @@ import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.ui.blaze.BlazeFeatureUtils import org.wordpress.android.ui.blaze.BlazeFlowSource import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource -import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction -import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository +import org.wordpress.android.ui.mysite.cards.ListItemActionHandler import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.quickstart.QuickStartType import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -29,9 +28,6 @@ import kotlin.test.assertEquals @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) class SiteItemsViewModelSliceTest : BaseUnitTest() { - @Mock - lateinit var quickStartRepository: QuickStartRepository - @Mock lateinit var selectedSiteRepository: SelectedSiteRepository @@ -39,13 +35,10 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper @Mock - lateinit var accountStore: AccountStore - - @Mock - lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + lateinit var blazeFeatureUtils: BlazeFeatureUtils @Mock - lateinit var blazeFeatureUtils: BlazeFeatureUtils + lateinit var listItemActionHandler: ListItemActionHandler private lateinit var siteItemsViewModelSlice: SiteItemsViewModelSlice @@ -65,12 +58,10 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { whenever(selectedSiteRepository.getSelectedSite()).thenReturn(site) siteItemsViewModelSlice = SiteItemsViewModelSlice( - quickStartRepository, selectedSiteRepository, analyticsTrackerWrapper, - accountStore, - jetpackFeatureRemovalPhaseHelper, - blazeFeatureUtils + blazeFeatureUtils, + listItemActionHandler ) @@ -122,7 +113,6 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { fun `pages item click emits OpenPages navigation event`() { invokeItemClickAction(action =ListItemAction.PAGES) - verify(quickStartRepository).completeTask(QuickStartStore.QuickStartNewSiteTask.REVIEW_PAGES) assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenPages(site)) } @@ -181,9 +171,7 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { @Test fun `stats item click emits OpenStats navigation event if site is WPCom and has access token`() { - whenever(accountStore.hasAccessToken()).thenReturn(true) site.setIsWPCom(true) - mockQuickStart() invokeItemClickAction(action= ListItemAction.STATS) @@ -191,12 +179,7 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { } @Test - fun `stats item click emits OpenStats navigation event if site is Jetpack and has access token`() { - whenever(accountStore.hasAccessToken()).thenReturn(true) - site.setIsJetpackConnected(true) - site.setIsJetpackInstalled(true) - mockQuickStart() - + fun `stats item click emits OpenStats navigation event if site is Jetpack and has access token`() { site.setIsJetpackInstalled(true) invokeItemClickAction(action= ListItemAction.STATS) assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenStats(site)) @@ -204,9 +187,6 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { @Test fun `given new site QS stats task, when stats item clicked, then CHECK_STATS task completed`() { - mockQuickStart() - whenever(quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL)) - .thenReturn(QuickStartStore.QuickStartNewSiteTask.CHECK_STATS) val builderParams = siteItemsViewModelSlice.buildItems( true, site, @@ -336,9 +316,4 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { val builderParams = siteItemsViewModelSlice.buildItems(enableFocusPoints, site) builderParams.onClick.invoke(action) } - - - private fun mockQuickStart() { - whenever(quickStartRepository.quickStartType).thenReturn(quickStartType) - } } From e1b4ea168bb3342781d98e0750cf4557e90a3947 Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 28 Sep 2023 21:39:15 +0530 Subject: [PATCH 16/21] =?UTF-8?q?=E2=86=92=20Moves:=20the=20tests=20of=20s?= =?UTF-8?q?ite=20navigation=20to=20ListItemActionHandlerTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/mysite/cards/ListItemActionHandler.kt | 10 +- .../mysite/cards/ListItemActionHandlerTest.kt | 197 ++++++++++++++++++ .../listitem/SiteItemsViewModelSliceTest.kt | 193 +---------------- 3 files changed, 200 insertions(+), 200 deletions(-) create mode 100644 WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt index cc2055ce1234..cf6c2a92f2d3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandler.kt @@ -22,16 +22,10 @@ class ListItemActionHandler @Inject constructor( ListItemAction.SCAN -> SiteNavigationAction.OpenScan(selectedSite) ListItemAction.PLAN -> SiteNavigationAction.OpenPlan(selectedSite) ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) - ListItemAction.PAGES -> { - SiteNavigationAction.OpenPages(selectedSite) - } - + ListItemAction.PAGES -> SiteNavigationAction.OpenPages(selectedSite) ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) - ListItemAction.SHARING -> { - SiteNavigationAction.OpenSharing(selectedSite) - } - + ListItemAction.SHARING -> SiteNavigationAction.OpenSharing(selectedSite) ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) ListItemAction.ME -> SiteNavigationAction.OpenMeScreen ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt new file mode 100644 index 000000000000..f8a3ac9e972a --- /dev/null +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt @@ -0,0 +1,197 @@ +package org.wordpress.android.ui.mysite.cards + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.whenever +import org.wordpress.android.BaseUnitTest +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.ui.blaze.BlazeFeatureUtils +import org.wordpress.android.ui.blaze.BlazeFlowSource +import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource +import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper +import org.wordpress.android.ui.mysite.SiteNavigationAction +import org.wordpress.android.ui.mysite.items.listitem.ListItemAction +import kotlin.test.assertEquals + + +@ExperimentalCoroutinesApi +@RunWith(MockitoJUnitRunner::class) +class ListItemActionHandlerTest: BaseUnitTest() { + @Mock + lateinit var accountStore: AccountStore + + @Mock + lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + + @Mock + lateinit var blazeFeatureUtils: BlazeFeatureUtils + + + private val site = SiteModel() + + private lateinit var listItemActionHandler: ListItemActionHandler + + @Before + fun setup() { + listItemActionHandler = ListItemActionHandler( + accountStore, + jetpackFeatureRemovalPhaseHelper, + blazeFeatureUtils + ) + } + + @Test + fun `activity item click emits OpenActivity navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.ACTIVITY_LOG) + + assertEquals(navigationAction,SiteNavigationAction.OpenActivityLog(site)) + } + + @Test + fun `scan item click emits OpenScan navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.SCAN) + + assertEquals(navigationAction,SiteNavigationAction.OpenScan(site)) + } + + @Test + fun `plan item click emits OpenPlan navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.PLAN) + + assertEquals(navigationAction,SiteNavigationAction.OpenPlan(site)) + } + + @Test + fun `posts item click emits OpenPosts navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.POSTS) + + assertEquals(navigationAction,SiteNavigationAction.OpenPosts(site)) + } + + @Test + fun `pages item click emits OpenPages navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.PAGES) + + assertEquals(navigationAction,SiteNavigationAction.OpenPages(site)) + } + + @Test + fun `admin item click emits OpenAdmin navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.ADMIN) + + assertEquals(navigationAction,SiteNavigationAction.OpenAdmin(site)) + } + + @Test + fun `sharing item click emits OpenSharing navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.SHARING) + + assertEquals(navigationAction,SiteNavigationAction.OpenSharing(site)) + } + + @Test + fun `site settings item click emits OpenSiteSettings navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.SITE_SETTINGS) + + assertEquals(navigationAction,SiteNavigationAction.OpenSiteSettings(site)) + } + + @Test + fun `themes item click emits OpenThemes navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.THEMES) + + assertEquals(navigationAction,SiteNavigationAction.OpenThemes(site)) + } + + @Test + fun `plugins item click emits OpenPlugins navigation event`() { + val navigationAction = invokeItemClickAction(action =ListItemAction.PLUGINS) + + assertEquals(navigationAction,SiteNavigationAction.OpenPlugins(site)) + } + + @Test + fun `media item click emits OpenMedia navigation event`() = test { + val navigationAction = invokeItemClickAction(action= ListItemAction.MEDIA) + + assertEquals(navigationAction,SiteNavigationAction.OpenMedia(site)) + } + + @Test + fun `comments item click emits OpenUnifiedComments navigation event`() { + val navigationAction = invokeItemClickAction(action= ListItemAction.COMMENTS) + + assertEquals(navigationAction,SiteNavigationAction.OpenUnifiedComments(site)) + } + + @Test + fun `stats item click emits OpenStats navigation event if site is WPCom and has access token`() { + site.setIsWPCom(true) + + val navigationAction = invokeItemClickAction(action= ListItemAction.STATS) + + assertEquals(navigationAction,SiteNavigationAction.OpenStats(site)) + } + + @Test + fun `stats item click emits OpenStats navigation event if site is Jetpack and has access token`() { + site.setIsJetpackConnected(true) + site.setIsWPCom(true) + whenever(accountStore.hasAccessToken()).thenReturn(true) + + val navigationAction = invokeItemClickAction(action= ListItemAction.STATS) + + assertEquals(navigationAction,SiteNavigationAction.OpenStats(site)) + } + + + @Test + fun `stats item click emits StartWPComLoginForJetpackStats if site is Jetpack and doesn't have access token`() { + site.setIsJetpackConnected(true) + + val navigationAction = invokeItemClickAction(action = ListItemAction.STATS) + + assertEquals(navigationAction, SiteNavigationAction.StartWPComLoginForJetpackStats) + } + + + @Test + fun `given campaigns enabled, when menu clicked, then navigated to campaign listing page`() { + // Given + whenever(blazeFeatureUtils.shouldShowBlazeCampaigns()).thenReturn(true) + + // When + val navigationAction = invokeItemClickAction(action = ListItemAction.BLAZE) + + + // Then + assertEquals( + SiteNavigationAction.OpenCampaignListingPage(CampaignListingPageSource.MENU_ITEM), + navigationAction + ) + } + + @Test + fun `given campaigns disabled, when menu clicked, then event is tracked`() { + // Given + whenever(blazeFeatureUtils.shouldShowBlazeCampaigns()).thenReturn(false) + + // When + val navigationAction = invokeItemClickAction(action = ListItemAction.BLAZE) + + // Then + assertEquals( + SiteNavigationAction.OpenPromoteWithBlazeOverlay(source = BlazeFlowSource.MENU_ITEM), + navigationAction + ) + } + + private fun invokeItemClickAction(action: ListItemAction, ): SiteNavigationAction { + return listItemActionHandler.handleAction(action, site) + } +} diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt index bf5d83ba7428..6957d19cd864 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteItemsViewModelSliceTest.kt @@ -12,18 +12,12 @@ import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.AccountStore -import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.ui.blaze.BlazeFeatureUtils -import org.wordpress.android.ui.blaze.BlazeFlowSource -import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.mysite.SiteNavigationAction import org.wordpress.android.ui.mysite.cards.ListItemActionHandler import org.wordpress.android.ui.pages.SnackbarMessageHolder -import org.wordpress.android.ui.quickstart.QuickStartType import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper -import kotlin.test.assertEquals @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) @@ -48,10 +42,6 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { private val site = SiteModel() - @Mock - lateinit var quickStartType: QuickStartType - - @Before fun setup() { whenever(blazeFeatureUtils.isSiteBlazeEligible(site)).thenReturn(false) @@ -81,163 +71,15 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { } } - @Test - fun `activity item click emits OpenActivity navigation event`() { - invokeItemClickAction(action =ListItemAction.ACTIVITY_LOG) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenActivityLog(site)) - } - - @Test - fun `scan item click emits OpenScan navigation event`() { - invokeItemClickAction(action =ListItemAction.SCAN) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenScan(site)) - } - - @Test - fun `plan item click emits OpenPlan navigation event`() { - invokeItemClickAction(action =ListItemAction.PLAN) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenPlan(site)) - } - - @Test - fun `posts item click emits OpenPosts navigation event`() { - invokeItemClickAction(action =ListItemAction.POSTS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenPosts(site)) - } - - @Test - fun `pages item click emits OpenPages navigation event`() { - invokeItemClickAction(action =ListItemAction.PAGES) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenPages(site)) - } - - @Test - fun `admin item click emits OpenAdmin navigation event`() { - invokeItemClickAction(action =ListItemAction.ADMIN) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenAdmin(site)) - } - - @Test - fun `sharing item click emits OpenSharing navigation event`() { - invokeItemClickAction(action =ListItemAction.SHARING) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenSharing(site)) - } - - @Test - fun `site settings item click emits OpenSiteSettings navigation event`() { - invokeItemClickAction(action =ListItemAction.SITE_SETTINGS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenSiteSettings(site)) - } - - @Test - fun `themes item click emits OpenThemes navigation event`() { - invokeItemClickAction(action =ListItemAction.THEMES) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenThemes(site)) - } - - @Test - fun `plugins item click emits OpenPlugins navigation event`() { - invokeItemClickAction(action =ListItemAction.PLUGINS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenPlugins(site)) - } - - @Test - fun `media item click emits OpenMedia navigation event`() = test { - mockQuickStart() - - invokeItemClickAction(action= ListItemAction.MEDIA) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenMedia(site)) - } - - @Test - fun `comments item click emits OpenUnifiedComments navigation event`() { - mockQuickStart() - - invokeItemClickAction(action= ListItemAction.COMMENTS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenUnifiedComments(site)) - } - - @Test - fun `stats item click emits OpenStats navigation event if site is WPCom and has access token`() { - site.setIsWPCom(true) - - invokeItemClickAction(action= ListItemAction.STATS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenStats(site)) - } - - @Test - fun `stats item click emits OpenStats navigation event if site is Jetpack and has access token`() { site.setIsJetpackInstalled(true) - invokeItemClickAction(action= ListItemAction.STATS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.OpenStats(site)) - } - - @Test - fun `given new site QS stats task, when stats item clicked, then CHECK_STATS task completed`() { - val builderParams = siteItemsViewModelSlice.buildItems( - true, - site, - QuickStartStore.QuickStartNewSiteTask.CHECK_STATS - ) - - builderParams.onClick.invoke(ListItemAction.STATS) - - verify(quickStartRepository).completeTask(QuickStartStore.QuickStartNewSiteTask.CHECK_STATS) - } - - @Test - fun `given existing site QS stats task, when stats item clicked, then CHECK_STATS task completed`() { - whenever(quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL)) - .thenReturn(QuickStartStore.QuickStartExistingSiteTask.CHECK_STATS) - val builderParams = siteItemsViewModelSlice.buildItems( - true, - site, - QuickStartStore.QuickStartExistingSiteTask.CHECK_STATS - ) - mockQuickStart() - - builderParams.onClick.invoke(ListItemAction.STATS) - - verify(quickStartRepository).completeTask(QuickStartStore.QuickStartExistingSiteTask.CHECK_STATS) - } - - @Test - fun `stats item click emits StartWPComLoginForJetpackStats if site is Jetpack and doesn't have access token`() { - whenever(accountStore.hasAccessToken()).thenReturn(false) - site.setIsJetpackConnected(true) - whenever(quickStartRepository.quickStartType).thenReturn(quickStartType) - whenever(quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL)) - .thenReturn(QuickStartStore.QuickStartExistingSiteTask.UNKNOWN) - - invokeItemClickAction(action = ListItemAction.STATS) - - assertThat(navigationActions).containsExactly(SiteNavigationAction.StartWPComLoginForJetpackStats) - } - @Test fun `stats item click emits ConnectJetpackForStats if neither Jetpack, nor WPCom and no access token`() { - whenever(accountStore.hasAccessToken()).thenReturn(false) site.setIsJetpackConnected(false) site.setIsWPCom(false) site.origin = SiteModel.ORIGIN_XMLRPC - mockQuickStart() invokeItemClickAction(action = ListItemAction.STATS) - assertThat(navigationActions).containsExactly(SiteNavigationAction.ConnectJetpackForStats(site)) + verify(listItemActionHandler).handleAction(ListItemAction.STATS, site) } @Test @@ -250,39 +92,6 @@ class SiteItemsViewModelSliceTest : BaseUnitTest() { ) } - @Test - fun `given campaigns enabled, when menu clicked, then navigated to campaign listing page`() { - // Given - whenever(blazeFeatureUtils.shouldShowBlazeCampaigns()).thenReturn(true) - - // When - invokeItemClickAction(action = ListItemAction.BLAZE) - - - // Then - verify(blazeFeatureUtils).trackEntryPointTapped(BlazeFlowSource.MENU_ITEM) - assertEquals( - SiteNavigationAction.OpenCampaignListingPage(CampaignListingPageSource.MENU_ITEM), - navigationActions.last() - ) - } - - @Test - fun `given campaigns disabled, when menu clicked, then event is tracked`() { - // Given - whenever(blazeFeatureUtils.shouldShowBlazeCampaigns()).thenReturn(false) - - // When - invokeItemClickAction(action = ListItemAction.BLAZE) - - // Then - verify(blazeFeatureUtils).trackEntryPointTapped(BlazeFlowSource.MENU_ITEM) - assertEquals( - SiteNavigationAction.OpenPromoteWithBlazeOverlay(source = BlazeFlowSource.MENU_ITEM), - navigationActions.last() - ) - } - @Test fun `given site blaze eligible, when isSiteBlazeEligible is called, then return true`() { // Given From 4d6af43e29ae80ce244ca02a1d684ef97b6be42a Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Thu, 28 Sep 2023 14:35:46 -0400 Subject: [PATCH 17/21] Fix detekt issue --- .../android/ui/mysite/cards/ListItemActionHandlerTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt index f8a3ac9e972a..0f7c4a007ec7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/ListItemActionHandlerTest.kt @@ -18,7 +18,6 @@ import org.wordpress.android.ui.mysite.SiteNavigationAction import org.wordpress.android.ui.mysite.items.listitem.ListItemAction import kotlin.test.assertEquals - @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) class ListItemActionHandlerTest: BaseUnitTest() { From 0d201bd2217ea97449a895955c8e8c1e8d8bd11b Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Thu, 28 Sep 2023 14:57:22 -0400 Subject: [PATCH 18/21] Refactor: replace git add . with a let to fix a crash on login with a user that has no sites --- .../cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt index a71be3f8e5f4..0eba683dd507 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt @@ -50,8 +50,9 @@ class QuickLinksItemViewModelSlice @Inject constructor( val uiState: LiveData = _uiState fun start() { - val site = selectedSiteRepository.getSelectedSite()!! - buildQuickLinks(site) + selectedSiteRepository.getSelectedSite()?.let { + buildQuickLinks(it) + } } fun onResume() { From 54c1c7700a050747fbcf35518429a98ef6a5802c Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Thu, 28 Sep 2023 15:57:50 -0400 Subject: [PATCH 19/21] Replace double bang with an explicity let check so to avoid crash when in a no sites situation --- .../quicklinksribbon/QuickLinksItemViewModelSlice.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt index 0eba683dd507..591064d2369e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinksItemViewModelSlice.kt @@ -56,13 +56,15 @@ class QuickLinksItemViewModelSlice @Inject constructor( } fun onResume() { - val site = selectedSiteRepository.getSelectedSite()!! - buildQuickLinks(site) + selectedSiteRepository.getSelectedSite()?.let { + buildQuickLinks(it) + } } fun onRefresh() { - val site = selectedSiteRepository.getSelectedSite()!! - buildQuickLinks(site) + selectedSiteRepository.getSelectedSite()?.let { + buildQuickLinks(it) + } } private fun buildQuickLinks(site: SiteModel) { From 5ac37d91a0e285e32a01f25b9f2b6db118a4235d Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Thu, 28 Sep 2023 16:48:18 -0400 Subject: [PATCH 20/21] Refactor: replace requireNotNull with a let check; because quickLinksItems can be null when we are in a no-site situation --- .../android/ui/mysite/MySiteViewModel.kt | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index 435bec998deb..eeb8ba447c05 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -266,40 +266,42 @@ class MySiteViewModel @Inject constructor( } val uiModel: LiveData = merge(state, quickLinksItemViewModelSlice.uiState) { cards, quickLinks -> - with(requireNotNull(cards)) { - val state = if (site != null) { - cardsUpdate?.checkAndShowSnackbarError() - val state = buildSiteSelectedStateAndScroll( - site, - showSiteIconProgressBar, - activeTask, - isDomainCreditAvailable, - quickStartCategories, - backupAvailable, - scanAvailable, - cardsUpdate, - bloggingPromptsUpdate, - blazeCardUpdate, - quickLinks - ) - trackCardsAndItemsShownIfNeeded(state) + cards?.let { nonNullCards -> + with(nonNullCards) { + val state = if (site != null) { + cardsUpdate?.checkAndShowSnackbarError() + val state = buildSiteSelectedStateAndScroll( + site, + showSiteIconProgressBar, + activeTask, + isDomainCreditAvailable, + quickStartCategories, + backupAvailable, + scanAvailable, + cardsUpdate, + bloggingPromptsUpdate, + blazeCardUpdate, + quickLinks + ) + trackCardsAndItemsShownIfNeeded(state) - bloggingPromptCardViewModelSlice.onDashboardCardsUpdated( - viewModelScope, - state.dashboardCardsAndItems.filterIsInstance() - ) - state - } else { - buildNoSiteState() - } + bloggingPromptCardViewModelSlice.onDashboardCardsUpdated( + viewModelScope, + state.dashboardCardsAndItems.filterIsInstance() + ) + state + } else { + buildNoSiteState() + } - bloggingPromptCardViewModelSlice.onSiteChanged(site?.id) + bloggingPromptCardViewModelSlice.onSiteChanged(site?.id) - dashboardCardPlansUtils.onSiteChanged(site?.id, state as? SiteSelected) + dashboardCardPlansUtils.onSiteChanged(site?.id, state as? SiteSelected) - domainTransferCardViewModel.onSiteChanged(site?.id, state as? SiteSelected) + domainTransferCardViewModel.onSiteChanged(site?.id, state as? SiteSelected) - UiModel(currentAvatarUrl.orEmpty(), state) + UiModel(currentAvatarUrl.orEmpty(), state) + } } } From 0c9f8c62ce43bea9e55f3010d2e1bd5eb448f231 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Thu, 28 Sep 2023 16:49:54 -0400 Subject: [PATCH 21/21] Refactor: update tests to support quickLinksViewModelSlice, remove quick link navigation tests, and general cleanup of unnecc stubbings. --- .../android/ui/mysite/MySiteViewModelTest.kt | 121 ++---------------- 1 file changed, 8 insertions(+), 113 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt index fa655631f25e..7ec6602ac0b6 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt @@ -38,7 +38,6 @@ import org.wordpress.android.fluxc.model.page.PageModel import org.wordpress.android.fluxc.model.page.PageStatus.PUBLISHED import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.PostStore -import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartNewSiteTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType @@ -381,11 +380,6 @@ class MySiteViewModelTest : BaseUnitTest() { ) ) - private var quickLinkRibbonStatsClickAction: (() -> Unit)? = null - private var quickLinkRibbonPagesClickAction: (() -> Unit)? = null - private var quickLinkRibbonPostsClickAction: (() -> Unit)? = null - private var quickLinkRibbonMediaClickAction: (() -> Unit)? = null - private val partialStates = listOf( isDomainCreditAvailable, jetpackCapabilities, @@ -414,8 +408,6 @@ class MySiteViewModelTest : BaseUnitTest() { whenever(selectedSiteRepository.siteSelected).thenReturn(onSiteSelected) whenever(quickStartRepository.activeTask).thenReturn(activeTask) whenever(quickStartRepository.quickStartType).thenReturn(quickStartType) - whenever(quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL)) - .thenReturn(QuickStartNewSiteTask.CHECK_STATS) whenever(jetpackBrandingUtils.getBrandingTextForScreen(any())).thenReturn(mock()) whenever(jetpackFeatureRemovalPhaseHelper.shouldShowDashboard()).thenReturn(true) whenever(blazeCardViewModelSlice.refresh).thenReturn(refresh) @@ -427,6 +419,7 @@ class MySiteViewModelTest : BaseUnitTest() { whenever(personalizeCardViewModelSlice.getBuilderParams()).thenReturn(mock()) whenever(personalizeCardBuilder.build(any())).thenReturn(mock()) whenever(bloggingPromptCardViewModelSlice.getBuilderParams(anyOrNull())).thenReturn(mock()) + whenever(quickLinksItemViewModelSlice.uiState).thenReturn(mock()) viewModel = MySiteViewModel( testDispatcher(), @@ -758,11 +751,7 @@ class MySiteViewModelTest : BaseUnitTest() { @Test fun `when quick start card item clicked, then quick start card item tapped is tracked`() { - initSelectedSite( - isMySiteTabsBuildConfigEnabled = true, - - isQuickStartInProgress = true - ) + initSelectedSite() requireNotNull(quickStartTaskTypeItemClickAction).invoke(QuickStartTaskType.CUSTOMIZE) @@ -1252,7 +1241,7 @@ class MySiteViewModelTest : BaseUnitTest() { @Test fun `given selected site with tabs disabled, when all cards and items, then qs card exists`() { - initSelectedSite(isMySiteDashboardTabsEnabled = false) + initSelectedSite() assertThat(getLastItems().filterIsInstance(QuickStartCard::class.java)).isNotEmpty } @@ -1279,10 +1268,7 @@ class MySiteViewModelTest : BaseUnitTest() { @Test fun `when dashboard cards items built, then qs card exists`() { // setUpSiteItemBuilder() - - initSelectedSite( - isMySiteTabsBuildConfigEnabled = true - ) + initSelectedSite() val items = (uiModels.last().state as SiteSelected).dashboardCardsAndItems @@ -1293,9 +1279,7 @@ class MySiteViewModelTest : BaseUnitTest() { fun `given site menu built, when dashboard cards items, then qs card not exists`() { // setUpSiteItemBuilder(shouldEnableFocusPoint = true) - initSelectedSite( - isMySiteTabsBuildConfigEnabled = true - ) + initSelectedSite() val items = (uiModels.last().state as SiteSelected).siteMenuCardsAndItems @@ -1318,9 +1302,7 @@ class MySiteViewModelTest : BaseUnitTest() { fun `given tabs enabled + dashboard default tab variant, when site menu cards + items, then qs card not exists`() { // setUpSiteItemBuilder() - initSelectedSite( - isMySiteTabsBuildConfigEnabled = true - ) + initSelectedSite() val items = (uiModels.last().state as SiteSelected).siteMenuCardsAndItems @@ -1347,91 +1329,6 @@ class MySiteViewModelTest : BaseUnitTest() { assertThat(items.filterIsInstance(DomainRegistrationCard::class.java)).isEmpty() } - @Test - fun `given site is WPCOM, when quick link ribbon stats click, then stats screen is shown`() { - whenever(accountStore.hasAccessToken()).thenReturn(true) - - site.setIsWPCom(true) - - initSelectedSite() - - requireNotNull(quickLinkRibbonStatsClickAction).invoke() - - assertThat(navigationActions).containsOnly(SiteNavigationAction.OpenStats(site)) - } - - @Test - fun `given site is Jetpack, when quick link ribbon stats click, then stats screen is shown`() { - whenever(accountStore.hasAccessToken()).thenReturn(true) - - site.setIsJetpackInstalled(true) - site.setIsJetpackConnected(true) - - initSelectedSite() - - requireNotNull(quickLinkRibbonStatsClickAction).invoke() - - verify(quickStartRepository).completeTask(QuickStartNewSiteTask.CHECK_STATS) - assertThat(navigationActions).containsOnly(SiteNavigationAction.OpenStats(site)) - } - - @Test - fun `given self-hosted site, when quick link ribbon stats click, then shows connect jetpack screen`() { - whenever(accountStore.hasAccessToken()).thenReturn(true) - - site.setIsJetpackInstalled(false) - site.setIsJetpackConnected(false) - - initSelectedSite(isSiteUsingWpComRestApi = false) - - requireNotNull(quickLinkRibbonStatsClickAction).invoke() - - assertThat(navigationActions).containsOnly(SiteNavigationAction.ConnectJetpackForStats(site)) - } - - @Test - fun `given user is not logged in jetpack site, when quick link ribbon stats click, then login screen is shown`() { - whenever(accountStore.hasAccessToken()).thenReturn(false) - - site.setIsJetpackInstalled(true) - site.setIsJetpackConnected(true) - - initSelectedSite() - - requireNotNull(quickLinkRibbonStatsClickAction).invoke() - - assertThat(navigationActions).containsOnly(SiteNavigationAction.StartWPComLoginForJetpackStats) - } - - @Test - fun `when quick link ribbon pages click, then pages screen is shown and completes REVIEW_PAGES task `() { - initSelectedSite() - - requireNotNull(quickLinkRibbonPagesClickAction).invoke() - - verify(quickStartRepository).completeTask(QuickStartNewSiteTask.REVIEW_PAGES) - assertThat(navigationActions).containsOnly(SiteNavigationAction.OpenPages(site)) - } - - @Test - fun `when quick link ribbon posts click, then posts screen is shown `() { - initSelectedSite() - - requireNotNull(quickLinkRibbonPostsClickAction).invoke() - - assertThat(navigationActions).containsOnly(SiteNavigationAction.OpenPosts(site)) - } - - @Test - fun `when quick link ribbon media click, then media screen is shown`() { - initSelectedSite() - - requireNotNull(quickLinkRibbonMediaClickAction).invoke() - - assertThat(navigationActions).containsOnly(SiteNavigationAction.OpenMedia(site)) - } - - /* JETPACK FEATURE CARD */ @Test fun `when feature card criteria is not met, then items does not contain feature card`() = test { @@ -1574,11 +1471,11 @@ class MySiteViewModelTest : BaseUnitTest() { @Suppress("LongParameterList") private fun initSelectedSite( - isMySiteTabsBuildConfigEnabled: Boolean = true, + // isMySiteTabsBuildConfigEnabled: Boolean = true, isQuickStartInProgress: Boolean = false, showStaleMessage: Boolean = false, isSiteUsingWpComRestApi: Boolean = true, - isMySiteDashboardTabsEnabled: Boolean = true, + // isMySiteDashboardTabsEnabled: Boolean = true, shouldShowJetpackBranding: Boolean = true ) { whenever( @@ -1587,8 +1484,6 @@ class MySiteViewModelTest : BaseUnitTest() { quickStartUpdate.value = QuickStartUpdate( categories = if (isQuickStartInProgress) listOf(quickStartCategory) else emptyList() ) - whenever(buildConfigWrapper.isMySiteTabsEnabled).thenReturn(isMySiteTabsBuildConfigEnabled) - whenever(mySiteDashboardTabsFeatureConfig.isEnabled()).thenReturn(isMySiteDashboardTabsEnabled) whenever(jetpackBrandingUtils.shouldShowJetpackBrandingInDashboard()).thenReturn(shouldShowJetpackBranding) if (isSiteUsingWpComRestApi) { site.setIsWPCom(true)