From 62fdaeeea467c01cc58b3959db4919fe90180d54 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 8 Apr 2024 03:32:13 +0300 Subject: [PATCH 1/5] Add singular strings resources for weekly roundup notification --- WordPress/src/main/res/values/strings.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index e93b2cd4f041..8af139e97596 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4198,9 +4198,14 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Weekly Roundup Weekly Roundup: %s Last week you had %1$s views, %2$s likes, and %3$s comments. + Last week you had %1$s views, 1 like, and %3$s comments. + Last week you had %1$s views, %2$s likes, and 1 comment. + Last week you had %1$s views, 1 like, and 1 comment. Last week you had %1$s views. Last week you had %1$s views and %2$s likes + Last week you had %1$s views and 1 like Last week you had %1$s views and %2$s comments + Last week you had %1$s views and 1 comment Blog From 5351dac9e103827c5d8717ddd9d999c269bad02b Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 8 Apr 2024 03:47:51 +0300 Subject: [PATCH 2/5] Use singular strings for building weekly roundup notification text --- .../weeklyroundup/WeeklyRoundupNotifier.kt | 78 ++++++++++++------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt b/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt index 93d7e89bf823..0e1643e929f9 100644 --- a/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt +++ b/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt @@ -90,34 +90,56 @@ class WeeklyRoundupNotifier @Inject constructor( } private fun buildContentText(data: WeeklyRoundupData) = when { - data.likes <= 0 && data.comments <= 0 -> { - resourceProvider.getString( - R.string.weekly_roundup_notification_text_views_only, - statsUtils.toFormattedString(data.views) - ) - } - data.likes > 0 && data.comments <= 0 -> { - resourceProvider.getString( - R.string.weekly_roundup_notification_text_views_and_likes, - statsUtils.toFormattedString(data.views), - statsUtils.toFormattedString(data.likes) - ) - } - data.likes <= 0 && data.comments > 0 -> { - resourceProvider.getString( - R.string.weekly_roundup_notification_text_views_and_comments, - statsUtils.toFormattedString(data.views), - statsUtils.toFormattedString(data.comments) - ) - } - else -> { - resourceProvider.getString( - R.string.weekly_roundup_notification_text_all, - statsUtils.toFormattedString(data.views), - statsUtils.toFormattedString(data.likes), - statsUtils.toFormattedString(data.comments) - ) - } + data.likes <= 0 && data.comments <= 0 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_only, + statsUtils.toFormattedString(data.views) + ) + + data.likes.toInt() == 1 && data.comments <= 0 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_and_like, + statsUtils.toFormattedString(data.views) + ) + + data.likes > 0 && data.comments <= 0 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_and_likes, + statsUtils.toFormattedString(data.views), + statsUtils.toFormattedString(data.likes) + ) + + data.likes <= 0 && data.comments.toInt() == 1 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_and_comment, + statsUtils.toFormattedString(data.views) + ) + + data.likes <= 0 && data.comments > 0 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_and_comments, + statsUtils.toFormattedString(data.views), + statsUtils.toFormattedString(data.comments) + ) + + data.likes.toInt() == 1 && data.comments.toInt() == 1 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_like_comment, + statsUtils.toFormattedString(data.views) + ) + + data.likes.toInt() == 1 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_like_comments, + statsUtils.toFormattedString(data.views), + statsUtils.toFormattedString(data.comments) + ) + + data.comments.toInt() == 1 -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_likes_comment, + statsUtils.toFormattedString(data.views), + statsUtils.toFormattedString(data.likes) + ) + + else -> resourceProvider.getString( + R.string.weekly_roundup_notification_text_all, + statsUtils.toFormattedString(data.views), + statsUtils.toFormattedString(data.likes), + statsUtils.toFormattedString(data.comments) + ) } companion object { From 01b90bdeed39bc801b87e516e003c5ebe85a4570 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 8 Apr 2024 03:49:52 +0300 Subject: [PATCH 3/5] Assert contentText instead contentTitle in WeeklyRoundupNotifierTest --- .../workers/weeklyroundup/WeeklyRoundupNotifierTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt b/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt index 715b35f12b73..dee1ca7d86f5 100644 --- a/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt @@ -181,7 +181,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { val list = weeklyRoundupNotifier.buildNotifications() - assertThat(list.first().contentTitle).isEqualTo( + assertThat(list.first().contentText).isEqualTo( resourceProvider.getString( R.string.weekly_roundup_notification_text_views_only, statsUtils.toFormattedString(data!!.views) @@ -199,7 +199,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { val list = weeklyRoundupNotifier.buildNotifications() - assertThat(list.first().contentTitle).isEqualTo( + assertThat(list.first().contentText).isEqualTo( resourceProvider.getString( R.string.weekly_roundup_notification_text_views_and_comments, statsUtils.toFormattedString(data!!.views), @@ -218,7 +218,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { val list = weeklyRoundupNotifier.buildNotifications() - assertThat(list.first().contentTitle).isEqualTo( + assertThat(list.first().contentText).isEqualTo( resourceProvider.getString( R.string.weekly_roundup_notification_text_views_and_likes, statsUtils.toFormattedString(data!!.views), @@ -237,7 +237,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { val list = weeklyRoundupNotifier.buildNotifications() - assertThat(list.first().contentTitle).isEqualTo( + assertThat(list.first().contentText).isEqualTo( resourceProvider.getString( R.string.weekly_roundup_notification_text_all, statsUtils.toFormattedString(data!!.views), From e5ae99ede94946b1da093dcb81b2d8d262628625 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 8 Apr 2024 03:51:22 +0300 Subject: [PATCH 4/5] Assert singular notification texts in WeeklyRoundupNotifierTest --- .../WeeklyRoundupNotifierTest.kt | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt b/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt index dee1ca7d86f5..d174010e1cda 100644 --- a/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifierTest.kt @@ -8,6 +8,7 @@ import org.junit.runner.RunWith import org.mockito.junit.MockitoJUnitRunner import org.mockito.kotlin.any import org.mockito.kotlin.anyVararg +import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.times import org.mockito.kotlin.verify @@ -39,7 +40,20 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { } private val contextProvider: ContextProvider = mock() private val resourceProvider: ResourceProvider = mock { - on { getString(any(), anyVararg()) }.thenReturn("mock_string") + on { getString(eq(R.string.weekly_roundup_notification_title), anyVararg()) } + .thenReturn("weekly_roundup_notification_title") + on { getString(eq(R.string.weekly_roundup_notification_text_views_only), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_views_only") + on { getString(eq(R.string.weekly_roundup_notification_text_views_and_comments), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_views_and_comments") + on { getString(eq(R.string.weekly_roundup_notification_text_views_and_likes), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_views_and_likes") + on { getString(eq(R.string.weekly_roundup_notification_text_all), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_all") + on { getString(eq(R.string.weekly_roundup_notification_text_views_likes_comment), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_views_likes_comment") + on { getString(eq(R.string.weekly_roundup_notification_text_views_like_comments), anyVararg()) } + .thenReturn("weekly_roundup_notification_text_views_like_comments") } private val weeklyRoundupScheduler: WeeklyRoundupScheduler = mock() private val notificationsTracker: SystemNotificationsTracker = mock() @@ -157,7 +171,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { val mockSites = buildMockSites() val data1 = buildMockData(mockSites[0], views = 10, comments = 0, likes = 0) val data2 = buildMockData(mockSites[1], views = 9, comments = 8, likes = 8) - val data3 = buildMockData(mockSites[2], views = 10, comments = 1, likes = 1) + val data3 = buildMockData(mockSites[2], views = 10, comments = 2, likes = 2) val unsortedData = listOf(data1, data2, data3) val sortedData = listOf(data1, data3, data2) @@ -192,7 +206,7 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { @Test fun `buildNotifications should not include likes with 0 count`() = test { val mockSites = buildMockSites() - val data = buildMockData(mockSites[2], views = 10, comments = 1, likes = 0) + val data = buildMockData(mockSites[2], views = 10, comments = 2, likes = 0) whenever(siteStore.sitesAccessedViaWPComRest).thenReturn(mockSites) whenever(weeklyRoundupRepository.fetchWeeklyRoundupData(any())).then { data } @@ -247,6 +261,44 @@ class WeeklyRoundupNotifierTest : BaseUnitTest() { ) } + @Test + fun `buildNotifications should include singular comment string if the comment is one`() = test { + val mockSites = buildMockSites() + val data = buildMockData(mockSites[1], views = 9, comments = 1, likes = 8) + + whenever(siteStore.sitesAccessedViaWPComRest).thenReturn(mockSites) + whenever(weeklyRoundupRepository.fetchWeeklyRoundupData(any())).then { data } + + val list = weeklyRoundupNotifier.buildNotifications() + + assertThat(list.first().contentText).isEqualTo( + resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_likes_comment, + statsUtils.toFormattedString(data!!.views), + statsUtils.toFormattedString(data.likes), + ) + ) + } + + @Test + fun `buildNotifications should include singular like string if the comment is one`() = test { + val mockSites = buildMockSites() + val data = buildMockData(mockSites[1], views = 9, comments = 8, likes = 1) + + whenever(siteStore.sitesAccessedViaWPComRest).thenReturn(mockSites) + whenever(weeklyRoundupRepository.fetchWeeklyRoundupData(any())).then { data } + + val list = weeklyRoundupNotifier.buildNotifications() + + assertThat(list.first().contentText).isEqualTo( + resourceProvider.getString( + R.string.weekly_roundup_notification_text_views_like_comments, + statsUtils.toFormattedString(data!!.views), + statsUtils.toFormattedString(data.comments) + ) + ) + } + private companion object { fun buildMockSites(quantity: Int = 3) = (1..quantity).map { SiteModel().apply { From 4f2556bd966a6aa360d15b2b00839d940474facb Mon Sep 17 00:00:00 2001 From: Ravi Date: Mon, 8 Apr 2024 12:41:26 +1000 Subject: [PATCH 5/5] Update strings.xml Fix StringFormatCount lint error --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 8af139e97596..56b846ca36e6 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4198,7 +4198,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Weekly Roundup Weekly Roundup: %s Last week you had %1$s views, %2$s likes, and %3$s comments. - Last week you had %1$s views, 1 like, and %3$s comments. + Last week you had %1$s views, 1 like, and %2$s comments. Last week you had %1$s views, %2$s likes, and 1 comment. Last week you had %1$s views, 1 like, and 1 comment. Last week you had %1$s views.