2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-05 21:20:45 +00:00

For #22477: Ignore null and empty values for share data title.

This commit is contained in:
mcarare 2021-12-15 15:29:01 +02:00 committed by mergify[bot]
parent e9a4272e82
commit 64a8932e3c
2 changed files with 70 additions and 1 deletions

View File

@ -204,7 +204,9 @@ class DefaultShareController(
}
@VisibleForTesting
internal fun getShareSubject() = shareSubject ?: shareData.map { it.title }.joinToString(", ")
internal fun getShareSubject() =
shareSubject ?: shareData.filterNot { it.title.isNullOrEmpty() }
.joinToString(", ") { it.title.toString() }
// Navigation between app fragments uses ShareTab as arguments. SendTabUseCases uses TabData.
@VisibleForTesting

View File

@ -187,6 +187,73 @@ class ShareControllerTest {
}
}
@Test
fun `getShareSubject should return the shareSubject when shareSubject is not null`() {
val activityContext: Context = mockk<Activity>()
val testController = DefaultShareController(
activityContext, shareSubject, shareData, mockk(),
mockk(), mockk(), recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
assertEquals(shareSubject, testController.getShareSubject())
}
@Test
fun `getShareSubject should return a combination of non-null titles when shareSubject is null`() {
val activityContext: Context = mockk<Activity>()
val testController = DefaultShareController(
activityContext, null, shareData, mockk(),
mockk(), mockk(), recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
assertEquals("title0, title1", testController.getShareSubject())
}
@Test
fun `getShareSubject should return just the not null titles string when shareSubject is null`() {
val activityContext: Context = mockk<Activity>()
val partialTitlesShareData = listOf(
ShareData(url = "url0", title = null),
ShareData(url = "url1", title = "title1")
)
val testController = DefaultShareController(
activityContext, null, partialTitlesShareData, mockk(),
mockk(), mockk(), recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
assertEquals("title1", testController.getShareSubject())
}
@Test
fun `getShareSubject should return empty string when shareSubject and all titles are null`() {
val activityContext: Context = mockk<Activity>()
val noTitleShareData = listOf(
ShareData(url = "url0", title = null),
ShareData(url = "url1", title = null)
)
val testController = DefaultShareController(
activityContext, null, noTitleShareData, mockk(),
mockk(), mockk(), recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
assertEquals("", testController.getShareSubject())
}
@Test
fun `getShareSubject should return empty string when shareSubject is null and and all titles are empty`() {
val activityContext: Context = mockk<Activity>()
val noTitleShareData = listOf(
ShareData(url = "url0", title = ""),
ShareData(url = "url1", title = "")
)
val testController = DefaultShareController(
activityContext, null, noTitleShareData, mockk(),
mockk(), mockk(), recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
assertEquals("", testController.getShareSubject())
}
@Test
@Suppress("DeferredResultUnused")
fun `handleShareToDevice should share to account device, inform callbacks and dismiss`() {