Skip to content

Commit 2fd9406

Browse files
committed
Fix rounding issue on most popular time stats card
1 parent 09a3984 commit 2fd9406

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler
2424
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
2525
import org.wordpress.android.util.text.PercentFormatter
2626
import org.wordpress.android.viewmodel.ResourceProvider
27+
import java.math.RoundingMode
2728
import javax.inject.Inject
2829
import javax.inject.Named
2930
import kotlin.math.roundToInt
@@ -75,11 +76,17 @@ class MostPopularInsightsUseCase
7576
} else {
7677
val highestDayPercent = resourceProvider.getString(
7778
R.string.stats_most_popular_percent_views,
78-
percentFormatter.format(domainModel.highestDayPercent.roundToInt())
79+
percentFormatter.format(
80+
value = domainModel.highestDayPercent.roundToInt(),
81+
rounding = RoundingMode.HALF_UP
82+
)
7983
)
8084
val highestHourPercent = resourceProvider.getString(
8185
R.string.stats_most_popular_percent_views,
82-
percentFormatter.format(domainModel.highestHourPercent.roundToInt())
86+
percentFormatter.format(
87+
value = domainModel.highestHourPercent.roundToInt(),
88+
rounding = RoundingMode.HALF_UP
89+
)
8390
)
8491
items.add(
8592
QuickScanItem(

WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler
3232
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
3333
import org.wordpress.android.util.text.PercentFormatter
3434
import org.wordpress.android.viewmodel.ResourceProvider
35+
import java.math.RoundingMode
36+
import java.math.RoundingMode.HALF_UP
3537
import kotlin.math.roundToInt
3638

3739
class MostPopularInsightsUseCaseTest : BaseUnitTest() {
@@ -66,8 +68,18 @@ class MostPopularInsightsUseCaseTest : BaseUnitTest() {
6668
actionCardHandler,
6769
percentFormatter
6870
)
69-
whenever(percentFormatter.format(highestDayPercent.roundToInt())).thenReturn("10%")
70-
whenever(percentFormatter.format(highestHourPercent.roundToInt())).thenReturn("20%")
71+
whenever(
72+
percentFormatter.format(
73+
value = highestDayPercent.roundToInt(),
74+
rounding = RoundingMode.HALF_UP
75+
)
76+
).thenReturn("10%")
77+
whenever(
78+
percentFormatter.format(
79+
value = highestHourPercent.roundToInt(),
80+
rounding = RoundingMode.HALF_UP
81+
)
82+
).thenReturn("20%")
7183
whenever(statsSiteProvider.siteModel).thenReturn(site)
7284
whenever(dateUtils.getWeekDay(day)).thenReturn(dayString)
7385

@@ -127,8 +139,14 @@ class MostPopularInsightsUseCaseTest : BaseUnitTest() {
127139
@Test
128140
fun `when buildUiModel is called, should call PercentFormatter`() = test {
129141
useCase.buildUiModel(InsightsMostPopularModel(0, day, hour, highestDayPercent, highestHourPercent))
130-
verify(percentFormatter).format(highestDayPercent.roundToInt())
131-
verify(percentFormatter).format(highestHourPercent.roundToInt())
142+
verify(percentFormatter).format(
143+
value = highestDayPercent.roundToInt(),
144+
rounding = HALF_UP
145+
)
146+
verify(percentFormatter).format(
147+
value = highestHourPercent.roundToInt(),
148+
rounding = HALF_UP
149+
)
132150
}
133151

134152
private fun assertTitle(item: BlockListItem) {

0 commit comments

Comments
 (0)