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:
parent
3184285217
commit
c1a3625559
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user