Skip to content

Commit

Permalink
Merge pull request #20242 from wordpress-mobile/Stats-Traffic-Remove-…
Browse files Browse the repository at this point in the history
…Today-card

Stats traffic remove today card
  • Loading branch information
ravishanker authored Feb 22, 2024
2 parents bf356dd + cc8d3ca commit efa163c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class StatsModule {
managementNewsCardUseCase: ManagementNewsCardUseCase,
actionCardGrowUseCase: ActionCardGrowUseCase,
actionCardReminderUseCase: ActionCardReminderUseCase,
actionCardScheduleUseCase: ActionCardScheduleUseCase
actionCardScheduleUseCase: ActionCardScheduleUseCase,
trafficTabFeatureConfig: StatsTrafficTabFeatureConfig
): List<@JvmSuppressWildcards BaseStatsUseCase<*, *>> {
val useCases = mutableListOf<BaseStatsUseCase<*, *>>()
if (BuildConfig.IS_JETPACK_APP) {
Expand All @@ -140,11 +141,15 @@ class StatsModule {
} else {
useCases.add(followerTotalsUseCase)
}

if (!trafficTabFeatureConfig.isEnabled()) {
useCases.add(todayStatsUseCase)
}

useCases.addAll(
listOf(
allTimeStatsUseCase,
latestPostSummaryUseCase,
todayStatsUseCase,
followersUseCaseFactory.build(BLOCK),
commentsUseCase,
mostPopularInsightsUseCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.managemen

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import org.wordpress.android.BuildConfig
import org.wordpress.android.R
import org.wordpress.android.fluxc.store.StatsStore.InsightType
import org.wordpress.android.fluxc.store.StatsStore.InsightType.ACTION_GROW
Expand Down Expand Up @@ -33,6 +32,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem.InsightModel.Status.ADDED
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem.InsightModel.Status.REMOVED
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig
import javax.inject.Inject
import javax.inject.Named

Expand All @@ -47,18 +47,21 @@ private val ACTIVITY_INSIGHTS = mutableListOf(
private val GENERAL_INSIGHTS = mutableListOf(
ALL_TIME_STATS,
MOST_POPULAR_DAY_AND_HOUR,
ANNUAL_SITE_STATS,
TODAY_STATS
ANNUAL_SITE_STATS
)

class InsightsManagementMapper @Inject constructor(
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val trafficTabFeatureConfig: StatsTrafficTabFeatureConfig
) {
suspend fun buildUIModel(addedTypes: Set<InsightType>, onClick: (InsightType) -> Unit) =
withContext(bgDispatcher) {
val insightListItems = mutableListOf<InsightListItem>()
insightListItems += Header(R.string.stats_insights_management_general)
if (BuildConfig.IS_JETPACK_APP && !GENERAL_INSIGHTS.contains(VIEWS_AND_VISITORS)) {
if (!trafficTabFeatureConfig.isEnabled() && !GENERAL_INSIGHTS.contains(TODAY_STATS)) {
GENERAL_INSIGHTS.add(TODAY_STATS)
}
if (!GENERAL_INSIGHTS.contains(VIEWS_AND_VISITORS)) {
GENERAL_INSIGHTS.add(0, VIEWS_AND_VISITORS)
}
insightListItems += GENERAL_INSIGHTS.map { type ->
Expand All @@ -70,7 +73,7 @@ class InsightsManagementMapper @Inject constructor(
}
insightListItems += Header(R.string.stats_insights_management_activity)

if (BuildConfig.IS_JETPACK_APP && ACTIVITY_INSIGHTS.contains(FOLLOWER_TOTALS)) {
if (ACTIVITY_INSIGHTS.contains(FOLLOWER_TOTALS)) {
// Replace FOLLOWER_TOTALS with Stats revamp v2 total insights
val followerTotalsIndex = ACTIVITY_INSIGHTS.indexOf(FOLLOWER_TOTALS)
ACTIVITY_INSIGHTS.remove(FOLLOWER_TOTALS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@ 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.wordpress.android.BaseUnitTest
import org.wordpress.android.R
import org.wordpress.android.fluxc.store.StatsStore.InsightType
import org.wordpress.android.fluxc.store.StatsStore.InsightType.ALL_TIME_STATS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.ANNUAL_SITE_STATS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.FOLLOWERS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.FOLLOWER_TOTALS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.LATEST_POST_SUMMARY
import org.wordpress.android.fluxc.store.StatsStore.InsightType.MOST_POPULAR_DAY_AND_HOUR
import org.wordpress.android.fluxc.store.StatsStore.InsightType.POSTING_ACTIVITY
import org.wordpress.android.fluxc.store.StatsStore.InsightType.PUBLICIZE
import org.wordpress.android.fluxc.store.StatsStore.InsightType.TAGS_AND_CATEGORIES
import org.wordpress.android.fluxc.store.StatsStore.InsightType.TODAY_STATS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.TOTAL_COMMENTS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.TOTAL_FOLLOWERS
import org.wordpress.android.fluxc.store.StatsStore.InsightType.TOTAL_LIKES
import org.wordpress.android.fluxc.store.StatsStore.InsightType.VIEWS_AND_VISITORS
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem.Header
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem.InsightModel
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightListItem.InsightModel.Status
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig

@ExperimentalCoroutinesApi
class InsightsManagementMapperTest : BaseUnitTest() {
@Mock
private lateinit var trafficTabFeatureConfig: StatsTrafficTabFeatureConfig

private lateinit var insightsManagementMapper: InsightsManagementMapper
private val insightTypeCount = 10 // POSTS_AND_PAGES_INSIGHTS.size + ACTIVITY_INSIGHTS.size + GENERAL_INSIGHTS.size
private var insightTypeCount = 13 // POSTS_AND_PAGES_INSIGHTS.size + ACTIVITY_INSIGHTS.size + GENERAL_INSIGHTS.size
private val sectionsCount = 3

@Before
fun setUp() {
insightsManagementMapper = InsightsManagementMapper(
testDispatcher()
testDispatcher(),
trafficTabFeatureConfig
)
}

Expand All @@ -46,18 +55,21 @@ class InsightsManagementMapperTest : BaseUnitTest() {
// Then
assertThat(result).hasSize(insightTypeCount + sectionsCount)
assertHeader(result[0], R.string.stats_insights_management_general)
assertInsight(result[1], ALL_TIME_STATS, true)
assertInsight(result[2], MOST_POPULAR_DAY_AND_HOUR, true)
assertInsight(result[3], ANNUAL_SITE_STATS, true)
assertInsight(result[4], TODAY_STATS, true)
assertHeader(result[5], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[6], LATEST_POST_SUMMARY, true)
assertInsight(result[7], POSTING_ACTIVITY, true)
assertInsight(result[8], TAGS_AND_CATEGORIES, true)
assertHeader(result[9], R.string.stats_insights_management_activity)
assertInsight(result[10], FOLLOWERS, true)
assertInsight(result[11], FOLLOWER_TOTALS, true)
assertInsight(result[12], PUBLICIZE, true)
assertInsight(result[1], VIEWS_AND_VISITORS, true)
assertInsight(result[2], ALL_TIME_STATS, true)
assertInsight(result[3], MOST_POPULAR_DAY_AND_HOUR, true)
assertInsight(result[4], ANNUAL_SITE_STATS, true)
assertInsight(result[5], TODAY_STATS, true)
assertHeader(result[6], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[7], LATEST_POST_SUMMARY, true)
assertInsight(result[8], POSTING_ACTIVITY, true)
assertInsight(result[9], TAGS_AND_CATEGORIES, true)
assertHeader(result[10], R.string.stats_insights_management_activity)
assertInsight(result[11], FOLLOWERS, true)
assertInsight(result[12], TOTAL_LIKES, true)
assertInsight(result[13], TOTAL_COMMENTS, true)
assertInsight(result[14], TOTAL_FOLLOWERS, true)
assertInsight(result[15], PUBLICIZE, true)
}

@Test
Expand All @@ -71,18 +83,21 @@ class InsightsManagementMapperTest : BaseUnitTest() {
// Then
assertThat(result).hasSize(insightTypeCount + sectionsCount)
assertHeader(result[0], R.string.stats_insights_management_general)
assertInsight(result[1], ALL_TIME_STATS, true)
assertInsight(result[2], MOST_POPULAR_DAY_AND_HOUR, false)
assertInsight(result[3], ANNUAL_SITE_STATS, false)
assertInsight(result[4], TODAY_STATS, false)
assertHeader(result[5], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[6], LATEST_POST_SUMMARY, false)
assertInsight(result[7], POSTING_ACTIVITY, false)
assertInsight(result[8], TAGS_AND_CATEGORIES, false)
assertHeader(result[9], R.string.stats_insights_management_activity)
assertInsight(result[10], FOLLOWERS, false)
assertInsight(result[11], FOLLOWER_TOTALS, false)
assertInsight(result[12], PUBLICIZE, true)
assertInsight(result[1], VIEWS_AND_VISITORS, false)
assertInsight(result[2], ALL_TIME_STATS, true)
assertInsight(result[3], MOST_POPULAR_DAY_AND_HOUR, false)
assertInsight(result[4], ANNUAL_SITE_STATS, false)
assertInsight(result[5], TODAY_STATS, false)
assertHeader(result[6], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[7], LATEST_POST_SUMMARY, false)
assertInsight(result[8], POSTING_ACTIVITY, false)
assertInsight(result[9], TAGS_AND_CATEGORIES, false)
assertHeader(result[10], R.string.stats_insights_management_activity)
assertInsight(result[11], FOLLOWERS, false)
assertInsight(result[12], TOTAL_LIKES, false)
assertInsight(result[13], TOTAL_COMMENTS, false)
assertInsight(result[14], TOTAL_FOLLOWERS, false)
assertInsight(result[15], PUBLICIZE, true)
}

@Test
Expand All @@ -93,18 +108,21 @@ class InsightsManagementMapperTest : BaseUnitTest() {
// Then
assertThat(result).hasSize(insightTypeCount + sectionsCount)
assertHeader(result[0], R.string.stats_insights_management_general)
assertInsight(result[1], ALL_TIME_STATS, false)
assertInsight(result[2], MOST_POPULAR_DAY_AND_HOUR, false)
assertInsight(result[3], ANNUAL_SITE_STATS, false)
assertInsight(result[4], TODAY_STATS, false)
assertHeader(result[5], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[6], LATEST_POST_SUMMARY, false)
assertInsight(result[7], POSTING_ACTIVITY, false)
assertInsight(result[8], TAGS_AND_CATEGORIES, false)
assertHeader(result[9], R.string.stats_insights_management_activity)
assertInsight(result[10], FOLLOWERS, false)
assertInsight(result[11], FOLLOWER_TOTALS, false)
assertInsight(result[12], PUBLICIZE, false)
assertInsight(result[1], VIEWS_AND_VISITORS, false)
assertInsight(result[2], ALL_TIME_STATS, false)
assertInsight(result[3], MOST_POPULAR_DAY_AND_HOUR, false)
assertInsight(result[4], ANNUAL_SITE_STATS, false)
assertInsight(result[5], TODAY_STATS, false)
assertHeader(result[6], R.string.stats_insights_management_posts_and_pages)
assertInsight(result[7], LATEST_POST_SUMMARY, false)
assertInsight(result[8], POSTING_ACTIVITY, false)
assertInsight(result[9], TAGS_AND_CATEGORIES, false)
assertHeader(result[10], R.string.stats_insights_management_activity)
assertInsight(result[11], FOLLOWERS, false)
assertInsight(result[12], TOTAL_LIKES, false)
assertInsight(result[13], TOTAL_COMMENTS, false)
assertInsight(result[14], TOTAL_FOLLOWERS, false)
assertInsight(result[15], PUBLICIZE, false)
}

private fun assertHeader(item: InsightListItem, text: Int) {
Expand Down

0 comments on commit efa163c

Please sign in to comment.