diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt index d847635c9626..7bc0263630ad 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilder.kt @@ -29,6 +29,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringText import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.util.DateTimeUtils import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.SiteMonitoringFeatureConfig import java.util.GregorianCalendar import java.util.TimeZone import javax.inject.Inject @@ -39,7 +40,8 @@ class SiteListItemBuilder @Inject constructor( private val siteUtilsWrapper: SiteUtilsWrapper, private val buildConfigWrapper: BuildConfigWrapper, private val themeBrowserUtils: ThemeBrowserUtils, - private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, + private val siteMonitoringFeatureConfig: SiteMonitoringFeatureConfig ) { fun buildActivityLogItemIfAvailable(site: SiteModel, onClick: (ListItemAction) -> Unit): ListItem? { val isWpComOrJetpack = siteUtilsWrapper.isAccessedViaWPComRest( @@ -245,9 +247,13 @@ class SiteListItemBuilder @Inject constructor( } else null } + @Suppress("ComplexCondition") fun buildSiteMonitoringItemIfAvailable(site: SiteModel, onClick: (ListItemAction) -> Unit): MySiteCardAndItem? { - // todo: Add the feature flag wrapper once it is available - return if (buildConfigWrapper.isJetpackApp && site.isWPComAtomic && site.isAdmin) { + return if (buildConfigWrapper.isJetpackApp + && site.isWPComAtomic + && site.isAdmin + && siteMonitoringFeatureConfig.isEnabled() + ) { ListItem( R.drawable.gb_ic_tool, UiStringRes(R.string.site_monitoring), diff --git a/WordPress/src/main/java/org/wordpress/android/util/config/SiteMonitoringFeatureConfig.kt b/WordPress/src/main/java/org/wordpress/android/util/config/SiteMonitoringFeatureConfig.kt index 0a7789dda5e2..3102f90ad70a 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/config/SiteMonitoringFeatureConfig.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/config/SiteMonitoringFeatureConfig.kt @@ -2,14 +2,16 @@ package org.wordpress.android.util.config import org.wordpress.android.BuildConfig import org.wordpress.android.annotation.Feature +import javax.inject.Inject private const val SITE_MONITORING_FEATURE_REMOTE_FIELD = "site_monitoring" @Feature(SITE_MONITORING_FEATURE_REMOTE_FIELD, false) -class SiteMonitoringFeatureConfig( +class SiteMonitoringFeatureConfig @Inject constructor( appConfig: AppConfig ) : FeatureConfig( appConfig, BuildConfig.ENABLE_SITE_MONITORING, SITE_MONITORING_FEATURE_REMOTE_FIELD ) + diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt index 7d579919727b..d1bfd2e7eac7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/listitem/SiteListItemBuilderTest.kt @@ -29,6 +29,7 @@ import org.wordpress.android.ui.plugins.PluginUtilsWrapper import org.wordpress.android.ui.themes.ThemeBrowserUtils import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.SiteMonitoringFeatureConfig @RunWith(MockitoJUnitRunner::class) class SiteListItemBuilderTest { @@ -53,6 +54,9 @@ class SiteListItemBuilderTest { @Mock lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + @Mock + lateinit var siteMonitoringFeatureConfig: SiteMonitoringFeatureConfig + private lateinit var siteListItemBuilder: SiteListItemBuilder @Before @@ -63,7 +67,8 @@ class SiteListItemBuilderTest { siteUtilsWrapper, buildConfigWrapper, themeBrowserUtils, - jetpackFeatureRemovalPhaseHelper + jetpackFeatureRemovalPhaseHelper, + siteMonitoringFeatureConfig ) } @@ -417,8 +422,13 @@ class SiteListItemBuilderTest { /* SITE MONITORING */ @Test - fun `give jetpack app, when is atomic and admin, then site monitoring item is built`() { - setupSiteMonitoringItems() + fun `give jetpack app, when FF is true and site is atomic and admin, then site monitoring item is built`() { + setupSiteMonitoringItems( + isJetpackApp = true, + isSiteMonitoringFeatureFlagEnabled = true, + isAtomic = true, + isAdmin = true + ) val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) @@ -426,9 +436,12 @@ class SiteListItemBuilderTest { } @Test - fun `give jetpack app, when is not atomic, then site monitoring item is not built`() { + fun `give jetpack app, when FF is true and site is atomic and NOT admin, then site monitoring item is not built`() { setupSiteMonitoringItems( - isAtomic = false + isJetpackApp = true, + isSiteMonitoringFeatureFlagEnabled = true, + isAtomic = true, + isAdmin = false ) val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) @@ -437,9 +450,24 @@ class SiteListItemBuilderTest { } @Test - fun `give jetpack app, when is not admin, then site monitoring item is not built`() { + fun `give jetpack app, when FF is true and site is admin and NOT atomic, then site monitoring item is not built`() { setupSiteMonitoringItems( - isAdmin = false + isJetpackApp = true, + isSiteMonitoringFeatureFlagEnabled = true, + isAdmin = true + ) + + val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) + + assertThat(item).isNull() + } + + @Test + fun `give jetpack app, when FF is false and site is admin and atomic, then site monitoring item is not built`() { + setupSiteMonitoringItems( + isJetpackApp = true, + isAtomic = true, + isAdmin = true ) val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) @@ -448,9 +476,12 @@ class SiteListItemBuilderTest { } @Test - fun `give not jetpack app, when site monitoring item requested, then site monitoring item is not built`() { + fun `give not jetpack app, when FF is true and site is atomic and admin, then site monitoring item is not built`() { setupSiteMonitoringItems( - isJetpackApp = false + isJetpackApp = false, + isSiteMonitoringFeatureFlagEnabled = true, + isAtomic = true, + isAdmin = true ) val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION) @@ -459,11 +490,13 @@ class SiteListItemBuilderTest { } private fun setupSiteMonitoringItems( - isJetpackApp: Boolean = true, - isAtomic: Boolean = true, - isAdmin: Boolean = true + isJetpackApp: Boolean = false, + isSiteMonitoringFeatureFlagEnabled: Boolean = false, + isAtomic: Boolean = false, + isAdmin: Boolean = false ) { whenever(buildConfigWrapper.isJetpackApp).thenReturn(isJetpackApp) + whenever(siteMonitoringFeatureConfig.isEnabled()).thenReturn(isSiteMonitoringFeatureFlagEnabled) whenever(siteModel.isAdmin).thenReturn(isAdmin) whenever(siteModel.isWPComAtomic).thenReturn(isAtomic) }