From bcb68f53d5b2fa2421d3986372bb4d2654f4ea6e Mon Sep 17 00:00:00 2001 From: Andy Valdez Date: Wed, 3 Apr 2024 17:12:29 -0400 Subject: [PATCH 1/3] [Stats] Add year to date picker for weeks. --- .../android/ui/stats/refresh/utils/StatsDateFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt index b262f70dfc04..0c8280959126 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt @@ -110,7 +110,7 @@ class StatsDateFormatter val startCalendar = Calendar.getInstance() startCalendar.time = endCalendar.time startCalendar.add(Calendar.DAY_OF_WEEK, -6) - return printWeek(startCalendar, endCalendar) + return printWeek(startCalendar, endCalendar, true) } MONTHS -> outputMonthFormat.format(date) .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } From 5763ceca5bf8151cefc987c9935810a5d690049b Mon Sep 17 00:00:00 2001 From: Andy Valdez Date: Mon, 8 Apr 2024 17:08:39 -0400 Subject: [PATCH 2/3] [Stats] Feature flagged adding the year to the week datepicker granularity. Additionally fixing some test failures. --- .../stats/refresh/utils/StatsDateFormatter.kt | 9 +++- .../refresh/utils/StatsDateFormatterTest.kt | 43 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt index 0c8280959126..4ae0d0607848 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatter.kt @@ -9,6 +9,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS import org.wordpress.android.fluxc.utils.SiteUtils import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig import org.wordpress.android.viewmodel.ResourceProvider import java.text.DateFormat import java.text.ParseException @@ -30,7 +31,11 @@ private const val YEARS_FORMAT = "MMM" private const val REMOVE_YEAR = "([^\\p{Alpha}']|('[\\p{Alpha}]+'))*y+([^\\p{Alpha}']|('[\\p{Alpha}]+'))*" class StatsDateFormatter -@Inject constructor(private val localeManagerWrapper: LocaleManagerWrapper, val resourceProvider: ResourceProvider) { +@Inject constructor( + private val localeManagerWrapper: LocaleManagerWrapper, + val resourceProvider: ResourceProvider, + val statsTrafficTabFeatureConfig: StatsTrafficTabFeatureConfig +) { private val inputFormat: SimpleDateFormat get() { return SimpleDateFormat(STATS_INPUT_FORMAT, localeManagerWrapper.getLocale()) @@ -110,7 +115,7 @@ class StatsDateFormatter val startCalendar = Calendar.getInstance() startCalendar.time = endCalendar.time startCalendar.add(Calendar.DAY_OF_WEEK, -6) - return printWeek(startCalendar, endCalendar, true) + return printWeek(startCalendar, endCalendar, statsTrafficTabFeatureConfig.isEnabled()) } MONTHS -> outputMonthFormat.format(date) .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt index f06c4b71e7cc..37d7c0295a4f 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt @@ -17,6 +17,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig import org.wordpress.android.viewmodel.ResourceProvider import java.util.Calendar import java.util.Locale @@ -27,6 +28,9 @@ class StatsDateFormatterTest : BaseUnitTest() { @Mock lateinit var localeManagerWrapper: LocaleManagerWrapper + @Mock + lateinit var statsTrafficTabFeatureConfig: StatsTrafficTabFeatureConfig + @Mock lateinit var resourceProvider: ResourceProvider private lateinit var statsDateFormatter: StatsDateFormatter @@ -34,7 +38,8 @@ class StatsDateFormatterTest : BaseUnitTest() { @Before fun setUp() { whenever(localeManagerWrapper.getLocale()).thenReturn(Locale.US) - statsDateFormatter = StatsDateFormatter(localeManagerWrapper, resourceProvider) + whenever(statsTrafficTabFeatureConfig.isEnabled()).thenReturn(false) + statsDateFormatter = StatsDateFormatter(localeManagerWrapper, resourceProvider, statsTrafficTabFeatureConfig) } @Test @@ -72,6 +77,42 @@ class StatsDateFormatterTest : BaseUnitTest() { assertThat(parsedDate).isEqualTo("Dec 17 - Dec 23") } + @Test + fun `prints a week date in string format in granular stats screen`() { + whenever(statsTrafficTabFeatureConfig.isEnabled()).thenReturn(true) + val unparsedDate = "2018W12W19" + val result = "Dec 17 - Dec 23, 2018" + whenever( + resourceProvider.getString( + R.string.stats_from_to_dates_in_week_label, + "Dec 17", + "Dec 23, 2018" + ) + ).thenReturn(result) + + val parsedDate = statsDateFormatter.printGranularDate(unparsedDate, WEEKS) + + assertThat(parsedDate).isEqualTo("Dec 17 - Dec 23, 2018") + } + + @Test + fun `prints a week date in string format in traffic tab`() { + whenever(statsTrafficTabFeatureConfig.isEnabled()).thenReturn(true) + val unparsedDate = "2018W12W31" + val result = "Dec 31, 2018 - Jan 6, 2019" + whenever( + resourceProvider.getString( + R.string.stats_from_to_dates_in_week_label, + "Dec 31, 2018", + "Jan 6, 2019" + ) + ).thenReturn(result) + + val parsedDate = statsDateFormatter.printGranularDate(unparsedDate, WEEKS) + + assertThat(parsedDate).isEqualTo("Dec 31, 2018 - Jan 6, 2019") + } + @Test fun `prints a week date`() { val calendar = Calendar.getInstance() From 6ab59a0f0f709f68a4c1c8faf3bc106a0f61a808 Mon Sep 17 00:00:00 2001 From: Andy Valdez Date: Tue, 9 Apr 2024 14:55:06 -0400 Subject: [PATCH 3/3] Updated test names to be clearer. --- .../android/ui/stats/refresh/utils/StatsDateFormatterTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt index 37d7c0295a4f..000d42ebf933 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/StatsDateFormatterTest.kt @@ -78,7 +78,7 @@ class StatsDateFormatterTest : BaseUnitTest() { } @Test - fun `prints a week date in string format in granular stats screen`() { + fun `prints a week date in the same year in string format with stats traffic tab enabled`() { whenever(statsTrafficTabFeatureConfig.isEnabled()).thenReturn(true) val unparsedDate = "2018W12W19" val result = "Dec 17 - Dec 23, 2018" @@ -96,7 +96,7 @@ class StatsDateFormatterTest : BaseUnitTest() { } @Test - fun `prints a week date in string format in traffic tab`() { + fun `prints a week date in two different years in string format with traffic tab enabled`() { whenever(statsTrafficTabFeatureConfig.isEnabled()).thenReturn(true) val unparsedDate = "2018W12W31" val result = "Dec 31, 2018 - Jan 6, 2019"