mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
Close #25982: Fix check between current and new when adding a bookmark
This commit is contained in:
parent
26d22e7528
commit
7309b671b1
@ -30,8 +30,8 @@ class BookmarksUseCase(
|
|||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
suspend operator fun invoke(url: String, title: String, position: UInt? = null): Boolean {
|
suspend operator fun invoke(url: String, title: String, position: UInt? = null): Boolean {
|
||||||
try {
|
return try {
|
||||||
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == it.url } == null
|
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == url } == null
|
||||||
|
|
||||||
if (canAdd) {
|
if (canAdd) {
|
||||||
storage.addItem(
|
storage.addItem(
|
||||||
@ -41,9 +41,9 @@ class BookmarksUseCase(
|
|||||||
position = position
|
position = position
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return canAdd
|
canAdd
|
||||||
} catch (e: PlacesException.UrlParseFailed) {
|
} catch (e: PlacesException.UrlParseFailed) {
|
||||||
return false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,11 @@ class BookmarksUseCaseTest {
|
|||||||
fun `WHEN adding bookmark THEN new item is stored`() = runTest {
|
fun `WHEN adding bookmark THEN new item is stored`() = runTest {
|
||||||
val bookmarksStorage = mockk<BookmarksStorage>(relaxed = true)
|
val bookmarksStorage = mockk<BookmarksStorage>(relaxed = true)
|
||||||
val historyStorage = mockk<HistoryStorage>(relaxed = true)
|
val historyStorage = mockk<HistoryStorage>(relaxed = true)
|
||||||
|
val bookmarkNode = mockk<BookmarkNode>()
|
||||||
val useCase = BookmarksUseCase(bookmarksStorage, historyStorage)
|
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")
|
val result = useCase.addBookmark("https://mozilla.org", "Mozilla")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user