Skip to content

Commit

Permalink
Merge pull request #20751 from wordpress-mobile/add-total-subscribers…
Browse files Browse the repository at this point in the history
…-value-to-subscribers-detail

Add total subscribers count to subscribers detail
  • Loading branch information
irfano authored May 2, 2024
2 parents 48d45c7 + d6a4513 commit 1fd4c50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title
import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory
import org.wordpress.android.ui.stats.refresh.lists.sections.subscribers.usecases.SubscribersUseCase.SubscribersUiState
import org.wordpress.android.ui.stats.refresh.utils.ContentDescriptionHelper
import org.wordpress.android.ui.stats.refresh.utils.MILLION
import org.wordpress.android.ui.stats.refresh.utils.StatsSinceLabelFormatter
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.StatsUtils
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import javax.inject.Inject
Expand All @@ -37,6 +39,7 @@ class SubscribersUseCase @Inject constructor(
private val followersStore: FollowersStore,
private val statsSiteProvider: StatsSiteProvider,
private val statsSinceLabelFormatter: StatsSinceLabelFormatter,
private val statsUtils: StatsUtils,
private val analyticsTracker: AnalyticsTrackerWrapper,
private val useCaseMode: UseCaseMode,
private val contentDescriptionHelper: ContentDescriptionHelper
Expand Down Expand Up @@ -76,6 +79,16 @@ class SubscribersUseCase @Inject constructor(
override fun buildUiModel(domainModel: FollowersModel, uiState: SubscribersUiState): List<BlockListItem> {
val items = mutableListOf<BlockListItem>()

if (useCaseMode == VIEW_ALL) {
items.add(Title(R.string.stats_view_total_subscribers))
items.add(
BlockListItem.ValueWithChartItem(
value = statsUtils.toFormattedString(domainModel.totalCount, MILLION),
extraBottomMargin = true
)
)
}

if (useCaseMode == UseCaseMode.BLOCK) {
items.add(buildTitle())
}
Expand Down Expand Up @@ -138,6 +151,7 @@ class SubscribersUseCase @Inject constructor(
private val followersStore: FollowersStore,
private val statsSiteProvider: StatsSiteProvider,
private val statsSinceLabelFormatter: StatsSinceLabelFormatter,
private val statsUtils: StatsUtils,
private val analyticsTracker: AnalyticsTrackerWrapper,
private val contentDescriptionHelper: ContentDescriptionHelper
) : InsightUseCaseFactory {
Expand All @@ -147,6 +161,7 @@ class SubscribersUseCase @Inject constructor(
followersStore,
statsSiteProvider,
statsSinceLabelFormatter,
statsUtils,
analyticsTracker,
useCaseMode,
contentDescriptionHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.subscribers.usecase
import org.wordpress.android.ui.stats.refresh.utils.ContentDescriptionHelper
import org.wordpress.android.ui.stats.refresh.utils.StatsSinceLabelFormatter
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.StatsUtils
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import java.util.Date

Expand All @@ -45,6 +46,9 @@ class SubscribersUseCaseTest : BaseUnitTest() {
@Mock
lateinit var statsSinceLabelFormatter: StatsSinceLabelFormatter

@Mock
lateinit var statsUtils: StatsUtils

@Mock
lateinit var statsSiteProvider: StatsSiteProvider

Expand Down Expand Up @@ -79,11 +83,13 @@ class SubscribersUseCaseTest : BaseUnitTest() {
store,
statsSiteProvider,
statsSinceLabelFormatter,
statsUtils,
tracker,
contentDescriptionHelper
)
useCase = useCaseFactory.build(BLOCK)
whenever(statsSinceLabelFormatter.getSinceLabelLowerCase(dateSubscribed)).thenReturn(sinceLabel)
whenever(statsUtils.toFormattedString(any<Int>(), any())).then { (it.arguments[0] as Int).toString() }
whenever(statsSiteProvider.siteModel).thenReturn(site)
whenever(contentDescriptionHelper.buildContentDescription(any(), any<String>(), any()))
.thenReturn(contentDescription)
Expand Down Expand Up @@ -159,7 +165,7 @@ class SubscribersUseCaseTest : BaseUnitTest() {
useCase.liveData.observeForever { if (it != null) updatedResult = it }

button.loadMore()
assertThat(updatedResult.data).hasSize(12)
assertThat(updatedResult.data).hasSize(14)
}

private suspend fun loadFollowers(refresh: Boolean, forced: Boolean = false): UseCaseModel {
Expand All @@ -176,19 +182,19 @@ class SubscribersUseCaseTest : BaseUnitTest() {
}

private fun List<BlockListItem>.assertViewAllFollowersFirstLoad(): LoadingItem {
assertThat(this).hasSize(12)
assertThat(this[0]).isEqualTo(Header(R.string.stats_name_label, R.string.stats_subscriber_since_label))
val follower = this[1] as ListItemWithIcon
assertThat(this).hasSize(14)
assertThat(this[2]).isEqualTo(Header(R.string.stats_name_label, R.string.stats_subscriber_since_label))
val follower = this[3] as ListItemWithIcon
assertThat(follower.iconUrl).isEqualTo(avatar)
assertThat(follower.iconStyle).isEqualTo(AVATAR)
assertThat(follower.text).isEqualTo(user)
assertThat(follower.value).isEqualTo(sinceLabel)
assertThat(follower.contentDescription).isEqualTo(contentDescription)

assertThat(this[10] is ListItemWithIcon).isTrue()
assertThat(this[12] is ListItemWithIcon).isTrue()

assertThat(this[11] is LoadingItem).isTrue()
return this[11] as LoadingItem
assertThat(this[13] is LoadingItem).isTrue()
return this[13] as LoadingItem
}

private fun List<BlockListItem>.assertFollowers() {
Expand Down

0 comments on commit 1fd4c50

Please sign in to comment.