Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/12259-userAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Apr 8, 2024
2 parents d549a46 + d1577bb commit caea747
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4198,9 +4198,14 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->
<string name="weekly_roundup">Weekly Roundup</string>
<string name="weekly_roundup_notification_title">Weekly Roundup: %s</string>
<string name="weekly_roundup_notification_text_all">Last week you had %1$s views, %2$s likes, and %3$s comments.</string>
<string name="weekly_roundup_notification_text_views_like_comments">Last week you had %1$s views, 1 like, and %2$s comments.</string>
<string name="weekly_roundup_notification_text_views_likes_comment">Last week you had %1$s views, %2$s likes, and 1 comment.</string>
<string name="weekly_roundup_notification_text_views_like_comment">Last week you had %1$s views, 1 like, and 1 comment.</string>
<string name="weekly_roundup_notification_text_views_only">Last week you had %1$s views.</string>
<string name="weekly_roundup_notification_text_views_and_likes">Last week you had %1$s views and %2$s likes</string>
<string name="weekly_roundup_notification_text_views_and_like">Last week you had %1$s views and 1 like</string>
<string name="weekly_roundup_notification_text_views_and_comments">Last week you had %1$s views and %2$s comments</string>
<string name="weekly_roundup_notification_text_views_and_comment">Last week you had %1$s views and 1 comment</string>

<!-- About -->
<string name="about_blog">Blog</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -181,7 +195,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)
Expand All @@ -192,14 +206,14 @@ 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 }

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),
Expand All @@ -218,7 +232,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),
Expand All @@ -237,7 +251,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),
Expand All @@ -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 {
Expand Down

0 comments on commit caea747

Please sign in to comment.