2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Close https://github.com/mozilla-mobile/fenix/issues/25982: Fix check between current and new when adding a bookmark

This commit is contained in:
Jonathan Almeida 2022-07-11 12:29:15 -04:00 committed by mergify[bot]
parent 3184285217
commit c1a3625559
2 changed files with 7 additions and 5 deletions

View File

@ -30,8 +30,8 @@ class BookmarksUseCase(
*/
@WorkerThread
suspend operator fun invoke(url: String, title: String, position: UInt? = null): Boolean {
try {
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == it.url } == null
return try {
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == url } == null
if (canAdd) {
storage.addItem(
@ -41,9 +41,9 @@ class BookmarksUseCase(
position = position
)
}
return canAdd
canAdd
} catch (e: PlacesException.UrlParseFailed) {
return false
false
}
}
}

View File

@ -44,9 +44,11 @@ class BookmarksUseCaseTest {
fun `WHEN adding bookmark THEN new item is stored`() = runTest {
val bookmarksStorage = mockk<BookmarksStorage>(relaxed = true)
val historyStorage = mockk<HistoryStorage>(relaxed = true)
val bookmarkNode = mockk<BookmarkNode>()
val useCase = BookmarksUseCase(bookmarksStorage, historyStorage)
coEvery { bookmarksStorage.getBookmarksWithUrl(any()) }.coAnswers { emptyList() }
every { bookmarkNode.url }.answers { "https://firefox.com" }
coEvery { bookmarksStorage.getBookmarksWithUrl(any()) }.coAnswers { listOf(bookmarkNode) }
val result = useCase.addBookmark("https://mozilla.org", "Mozilla")