Skip to content

Commit

Permalink
Merge pull request #20044 from wordpress-mobile/issue/20043-connect-F…
Browse files Browse the repository at this point in the history
…F-to-site-monitoring-menu-option

Adds: Site monitoring FF to SiteListItemBuilder
  • Loading branch information
pantstamp authored Jan 26, 2024
2 parents bde787e + 343c352 commit 4ce17ff
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -53,6 +54,9 @@ class SiteListItemBuilderTest {
@Mock
lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper

@Mock
lateinit var siteMonitoringFeatureConfig: SiteMonitoringFeatureConfig

private lateinit var siteListItemBuilder: SiteListItemBuilder

@Before
Expand All @@ -63,7 +67,8 @@ class SiteListItemBuilderTest {
siteUtilsWrapper,
buildConfigWrapper,
themeBrowserUtils,
jetpackFeatureRemovalPhaseHelper
jetpackFeatureRemovalPhaseHelper,
siteMonitoringFeatureConfig
)
}

Expand Down Expand Up @@ -417,18 +422,26 @@ 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)

assertThat(item).isEqualTo(SITE_MONITORING_ITEM)
}

@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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 4ce17ff

Please sign in to comment.