diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt index eb643054c3..e0c6f9fa54 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt @@ -264,51 +264,6 @@ class BookmarksTest { } } - @Test - fun openAllInTabsTest() { - val nbPages = 4 - val webPages = List(nbPages) { - TestAssetHelper.getGenericAsset(mockWebServer, it + 1) - } - - homeScreen { - }.openThreeDotMenu { - }.openBookmarks { - createFolder("root") - createFolder("sub", "root") - createFolder("empty", "root") - }.closeMenu { - } - - browserScreen { - createBookmark(webPages[0].url, "root") - createBookmark(webPages[1].url, "root") - createBookmark(webPages[2].url, "sub") - // out of folder and should not be opened - createBookmark(webPages[3].url) - }.openTabDrawer { - closeTab() - } - - browserScreen { - }.openThreeDotMenu { - }.openBookmarks { - }.openThreeDotMenu("root") { - }.clickOpenAllInTabs { - verifyTabTrayIsOpened() - verifyNormalModeSelected() - - verifyExistingOpenTabs("Test_Page_1") - verifyExistingOpenTabs("Test_Page_2") - verifyExistingOpenTabs("Test_Page_3") - closeTab() - closeTab() - closeTab() - // no more tabs should be presents and auto close tab tray - verifyTabTrayIsClosed() - } - } - @Test fun openBookmarkInPrivateTabTest() { val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt index 4b4f881fe9..0b4a6d0431 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt @@ -150,21 +150,12 @@ class BookmarksRobot { .click() } - fun createFolder(name: String, parent: String? = null) { + fun createFolder(name: String) { clickAddFolderButton() addNewFolderName(name) - if (!parent.isNullOrBlank()) { - setParentFolder(parent) - } saveNewFolder() } - fun setParentFolder(parentName: String) { - clickParentFolderSelector() - selectFolder(parentName) - navigateUp() - } - fun clickAddFolderButton() { mDevice.waitNotNull( Until.findObject(By.desc("Add folder")), diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt index 905aa9a5ba..702640fb40 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt @@ -334,21 +334,13 @@ class BrowserRobot { menuSaveImage.click() } - fun createBookmark(url: Uri, folder: String? = null) { + fun createBookmark(url: Uri) { navigationToolbar { }.enterURLAndEnterToBrowser(url) { // needs to wait for the right url to load before saving a bookmark verifyUrl(url.toString()) }.openThreeDotMenu { - }.bookmarkPage { - // continue only if a folder is defined - }.takeIf { !folder.isNullOrBlank() }?.let { - it.openThreeDotMenu { - }.editBookmarkPage { - setParentFolder(folder!!) - saveEditBookmark() - } - } + }.bookmarkPage { } } fun clickLinkMatchingText(expectedText: String) { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuBookmarksRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuBookmarksRobot.kt index 25f6ec3754..2c13ba626b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuBookmarksRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuBookmarksRobot.kt @@ -52,13 +52,6 @@ class ThreeDotMenuBookmarksRobot { return TabDrawerRobot.Transition() } - fun clickOpenAllInTabs(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition { - openAllInTabsButton().click() - - TabDrawerRobot().interact() - return TabDrawerRobot.Transition() - } - fun clickDelete(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { deleteButton().click() @@ -78,6 +71,4 @@ private fun openInNewTabButton() = onView(withText("Open in new tab")) private fun openInPrivateTabButton() = onView(withText("Open in private tab")) -private fun openAllInTabsButton() = onView(withText("Open All Bookmarks")) - private fun deleteButton() = onView(withText("Delete")) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index 12dc1d7166..865e17adaf 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -208,14 +208,6 @@ class ThreeDotMenuMainRobot { return BrowserRobot.Transition() } - fun editBookmarkPage(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { - mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime) - editBookmarkButton().click() - - BookmarksRobot().interact() - return BookmarksRobot.Transition() - } - fun openHelp(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { mDevice.waitNotNull(Until.findObject(By.text("Help")), waitingTime) helpButton().click() diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt index 69205b9331..4f96e26ac6 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt @@ -15,7 +15,6 @@ import mozilla.appservices.places.BookmarkRoot import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.prompt.ShareData import mozilla.components.concept.storage.BookmarkNode -import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.service.fxa.sync.SyncReason import org.mozilla.fenix.BrowserDirection @@ -45,7 +44,6 @@ interface BookmarkController { fun handleCopyUrl(item: BookmarkNode) fun handleBookmarkSharing(item: BookmarkNode) fun handleOpeningBookmark(item: BookmarkNode, mode: BrowsingMode) - fun handleBookmarkFolderOpening(folder: BookmarkNode) /** * Handle bookmark nodes deletion @@ -77,7 +75,6 @@ class DefaultBookmarkController( private val tabsUseCases: TabsUseCases?, private val loadBookmarkNode: suspend (String) -> BookmarkNode?, private val showSnackbar: (String) -> Unit, - private val onOpenAllInTabsEmpty: () -> Unit, private val deleteBookmarkNodes: (Set, BookmarkRemoveType) -> Unit, private val deleteBookmarkFolder: (Set) -> Unit, private val showTabTray: () -> Unit, @@ -161,35 +158,6 @@ class DefaultBookmarkController( showTabTray() } - private suspend fun recursiveBookmarkFolderOpening(folder: BookmarkNode, firstLaunch: Boolean = false) { - val node = loadBookmarkNode.invoke(folder.guid) ?: return - if (!node.children.isNullOrEmpty()) { - if (firstLaunch) invokePendingDeletion.invoke() - - node.children!!.iterator().forEach { - when (it.type) { - BookmarkNodeType.FOLDER -> recursiveBookmarkFolderOpening(it, mode = mode) - BookmarkNodeType.ITEM -> { - it.url?.let { url -> tabsUseCases?.addTab?.invoke(url, private = (mode == BrowsingMode.Private)) } - } - BookmarkNodeType.SEPARATOR -> {} - } - }.also { - if (firstLaunch) { - activity.browsingModeManager.mode = BrowsingMode.fromBoolean(mode == BrowsingMode.Private) - showTabTray() - } - } - } else if (firstLaunch) onOpenAllInTabsEmpty.invoke() - } - - override fun handleBookmarkFolderOpening(folder: BookmarkNode) { - // potentially heavy function with a lot of bookmarks to open => use a coroutine - scope.launch { - recursiveBookmarkFolderOpening(folder, true) - } - } - override fun handleBookmarkDeletion(nodes: Set, removeType: BookmarkRemoveType) { deleteBookmarkNodes(nodes, removeType) } diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt index 48a778f523..34e15347cc 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt @@ -101,7 +101,6 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan tabsUseCases = activity?.components?.useCases?.tabsUseCases, loadBookmarkNode = ::loadBookmarkNode, showSnackbar = ::showSnackBarWithText, - onOpenAllInTabsEmpty = ::onOpenAllInTabsEmpty, deleteBookmarkNodes = ::deleteMulti, deleteBookmarkFolder = ::showRemoveFolderDialog, showTabTray = ::showTabTray, @@ -293,27 +292,6 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan } } - private fun alertHeavyOpen(n: Int, function: () -> (Unit)) { - AlertDialog.Builder(requireContext()).apply { - setTitle(R.string.open_all_warning_title) - setMessage(String.format(context.getString(R.string.open_all_warning_message), n)) - setPositiveButton( - R.string.open_all_warning_confirm, - ) { dialog, _ -> - function() - dialog.dismiss() - } - setNegativeButton( - R.string.open_all_warning_cancel, - ) { dialog: DialogInterface, _ -> - dialog.dismiss() - } - setCancelable(false) - create() - show() - } - } - private fun deleteMulti( selected: Set, eventType: BookmarkRemoveType = BookmarkRemoveType.MULTIPLE, diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractor.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractor.kt index c4b6c86c01..9515764a13 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractor.kt @@ -79,11 +79,6 @@ class BookmarkFragmentInteractor( } } - override fun onOpenAllInTabs(folder: BookmarkNode) { - require(folder.type == BookmarkNodeType.FOLDER) - bookmarksController.handleBookmarkFolderOpening(folder) - } - override fun onDelete(nodes: Set) { if (nodes.find { it.type == BookmarkNodeType.SEPARATOR } != null) { throw IllegalStateException("Cannot delete separators") diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenu.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenu.kt index 2d678f7ec2..e437490ca2 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenu.kt @@ -13,7 +13,6 @@ import mozilla.components.concept.menu.candidate.TextStyle import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.R -import org.mozilla.fenix.ext.bookmarkStorage class BookmarkItemMenu( private val context: Context, @@ -26,87 +25,57 @@ class BookmarkItemMenu( Share, OpenInNewTab, OpenInPrivateTab, - OpenAllInTabs, Delete, ; } val menuController: MenuController by lazy { BrowserMenuController() } - /** - * Check if the menu item has to be displayed or not for the type of bookmark. - * If wanted, return the item. - * Else, return null. - */ - private fun maybeCreateMenuItem( - itemType: BookmarkNodeType, - wantedType: BookmarkNodeType, - text: String, - action: Item, - ): TextMenuCandidate? { - return maybeCreateMenuItem(itemType, listOf(wantedType), text, action) - } - - private fun maybeCreateMenuItem( - itemType: BookmarkNodeType, - wantedTypes: List, - text: String, - action: Item, - ): TextMenuCandidate? { - return if (itemType in wantedTypes) { - TextMenuCandidate( - text = text, - ) { - onItemTapped.invoke(action) - } - } else { - null - } - } - @VisibleForTesting - internal suspend fun menuItems(itemType: BookmarkNodeType, itemId: String): List { - // if have at least one child - val hasAtLeastOneChild = !context.bookmarkStorage.getTree(itemId)?.children.isNullOrEmpty() - + internal fun menuItems(itemType: BookmarkNodeType): List { return listOfNotNull( - maybeCreateMenuItem( - itemType, - listOf(BookmarkNodeType.ITEM, BookmarkNodeType.FOLDER), - context.getString(R.string.bookmark_menu_edit_button), - Item.Edit, - ), - maybeCreateMenuItem( - itemType, - BookmarkNodeType.ITEM, - context.getString(R.string.bookmark_menu_copy_button), - Item.Copy, - ), - maybeCreateMenuItem( - itemType, - BookmarkNodeType.ITEM, - context.getString(R.string.bookmark_menu_share_button), - Item.Share, - ), - maybeCreateMenuItem( - itemType, - BookmarkNodeType.ITEM, - context.getString(R.string.bookmark_menu_open_in_new_tab_button), - Item.OpenInNewTab, - ), - maybeCreateMenuItem( - itemType, - BookmarkNodeType.ITEM, - context.getString(R.string.bookmark_menu_open_in_private_tab_button), - Item.OpenInPrivateTab, - ), - if (hasAtLeastOneChild) { - maybeCreateMenuItem( - itemType, - BookmarkNodeType.FOLDER, - context.getString(R.string.bookmark_menu_open_all_in_tabs_button), - Item.OpenAllInTabs, - ) + if (itemType != BookmarkNodeType.SEPARATOR) { + TextMenuCandidate( + text = context.getString(R.string.bookmark_menu_edit_button), + ) { + onItemTapped.invoke(Item.Edit) + } + } else { + null + }, + if (itemType == BookmarkNodeType.ITEM) { + TextMenuCandidate( + text = context.getString(R.string.bookmark_menu_copy_button), + ) { + onItemTapped.invoke(Item.Copy) + } + } else { + null + }, + if (itemType == BookmarkNodeType.ITEM) { + TextMenuCandidate( + text = context.getString(R.string.bookmark_menu_share_button), + ) { + onItemTapped.invoke(Item.Share) + } + } else { + null + }, + if (itemType == BookmarkNodeType.ITEM) { + TextMenuCandidate( + text = context.getString(R.string.bookmark_menu_open_in_new_tab_button), + ) { + onItemTapped.invoke(Item.OpenInNewTab) + } + } else { + null + }, + if (itemType == BookmarkNodeType.ITEM) { + TextMenuCandidate( + text = context.getString(R.string.bookmark_menu_open_in_private_tab_button), + ) { + onItemTapped.invoke(Item.OpenInPrivateTab) + } } else { null }, @@ -119,7 +88,7 @@ class BookmarkItemMenu( ) } - suspend fun updateMenu(itemType: BookmarkNodeType, itemId: String) { - menuController.submitList(menuItems(itemType, itemId)) + fun updateMenu(itemType: BookmarkNodeType) { + menuController.submitList(menuItems(itemType)) } } diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt index 853a20009a..b6cbcf292f 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt @@ -79,13 +79,6 @@ interface BookmarkViewInteractor : SelectionInteractor { */ fun onOpenInPrivateTab(item: BookmarkNode) - /** - * Opens all bookmark items in new tabs. - * - * @param folder the bookmark folder containing all items to open in new tabs - */ - fun onOpenAllInTabs(folder: BookmarkNode) - /** * Deletes a set of bookmark nodes. * diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkNodeViewHolder.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkNodeViewHolder.kt index 8131c92b6c..dc1d8c8b9b 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkNodeViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkNodeViewHolder.kt @@ -6,9 +6,6 @@ package org.mozilla.fenix.library.bookmarks.viewholders import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType import org.mozilla.fenix.R @@ -45,7 +42,6 @@ class BookmarkNodeViewHolder( BookmarkItemMenu.Item.Share -> interactor.onSharePressed(item) BookmarkItemMenu.Item.OpenInNewTab -> interactor.onOpenInNormalTab(item) BookmarkItemMenu.Item.OpenInPrivateTab -> interactor.onOpenInPrivateTab(item) - BookmarkItemMenu.Item.OpenAllInTabs -> interactor.onOpenAllInTabs(item) BookmarkItemMenu.Item.Delete -> interactor.onDelete(setOf(item)) } } @@ -62,10 +58,7 @@ class BookmarkNodeViewHolder( containerView.urlView.isVisible = item.type == BookmarkNodeType.ITEM containerView.setSelectionInteractor(item, mode, interactor) - - CoroutineScope(Dispatchers.Default).launch { - menu.updateMenu(item.type, item.guid) - } + menu.updateMenu(item.type) // Hide menu button if this item is a root folder or is selected if (item.type == BookmarkNodeType.FOLDER && item.inRoots()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5c9cabf4b..dfe29c9875 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -856,8 +856,6 @@ Open in new tab Open in private tab - - Open all in new tabs Delete diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt index 4a8a7c0529..510389f5f6 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt @@ -358,55 +358,6 @@ class BookmarkControllerTest { } } - @Test - fun `handleBookmarkFolderOpening should open all bookmarks in normal tabs`() { - var showTabTrayInvoked = false - createController( - showTabTray = { - showTabTrayInvoked = true - }, - loadBookmarkNode = { - fun recurseFind(item: BookmarkNode, guid: String): BookmarkNode? { - if (item.guid == guid) { - return item - } else { - item.children?.iterator()?.forEach { - val res = recurseFind(it, guid) - if (res != null) { - return res - } - } - return null - } - } - recurseFind(tree, it) - }, - ).handleBookmarkFolderOpening(tree) - - assertTrue(showTabTrayInvoked) - verifyOrder { - addNewTabUseCase.invoke(item.url!!, private = false) - addNewTabUseCase.invoke(item.url!!, private = false) - addNewTabUseCase.invoke(childItem.url!!, private = false) - homeActivity.browsingModeManager.mode = BrowsingMode.Normal - } - } - - @Test - fun `handleBookmarkFolderOpening for an empty folder should show toast`() { - var onOpenAllInTabsEmptyInvoked = false - createController( - onOpenAllInTabsEmpty = { - onOpenAllInTabsEmptyInvoked = true - }, - loadBookmarkNode = { - subfolder - }, - ).handleBookmarkFolderOpening(subfolder) - - assertTrue(onOpenAllInTabsEmptyInvoked) - } - @Test fun `handleBookmarkDeletion for an item should properly call a passed in delegate`() { var deleteBookmarkNodesInvoked = false @@ -477,7 +428,6 @@ class BookmarkControllerTest { private fun createController( loadBookmarkNode: suspend (String) -> BookmarkNode? = { _ -> null }, showSnackbar: (String) -> Unit = { _ -> }, - onOpenAllInTabsEmpty: () -> Unit = { }, deleteBookmarkNodes: (Set, BookmarkRemoveType) -> Unit = { _, _ -> }, deleteBookmarkFolder: (Set) -> Unit = { _ -> }, showTabTray: () -> Unit = { }, @@ -492,7 +442,6 @@ class BookmarkControllerTest { tabsUseCases = tabsUseCases, loadBookmarkNode = loadBookmarkNode, showSnackbar = showSnackbar, - onOpenAllInTabsEmpty = onOpenAllInTabsEmpty, deleteBookmarkNodes = deleteBookmarkNodes, deleteBookmarkFolder = deleteBookmarkFolder, showTabTray = showTabTray, diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractorTest.kt index 8b670bf229..58a4c0b69f 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentInteractorTest.kt @@ -170,15 +170,6 @@ class BookmarkFragmentInteractorTest { assertNull(BookmarksManagement.openInPrivateTab.testGetValue()!!.single().extra) } - @Test - fun `open all bookmarks item in new tabs`() { - interactor.onOpenAllInTabs(tree) - - verify { - bookmarkController.handleBookmarkFolderOpening(tree) - } - } - @Test fun `delete a bookmark item`() { interactor.onDelete(setOf(item)) diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenuTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenuTest.kt index 82a1ec5b0e..f251132bf5 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenuTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkItemMenuTest.kt @@ -6,23 +6,15 @@ package org.mozilla.fenix.library.bookmarks import android.content.Context import androidx.appcompat.view.ContextThemeWrapper -import io.mockk.coEvery -import io.mockk.every -import io.mockk.mockk -import io.mockk.mockkStatic -import kotlinx.coroutines.runBlocking -import mozilla.components.concept.menu.candidate.TextMenuCandidate import mozilla.components.concept.menu.candidate.TextStyle import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.R -import org.mozilla.fenix.ext.bookmarkStorage import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.library.bookmarks.BookmarkItemMenu.Item @@ -41,64 +33,6 @@ class BookmarkItemMenuTest { } } - @Test - fun `delete item has special styling`() = runBlocking { - var deleteItem: TextMenuCandidate? = null - mockkStatic("org.mozilla.fenix.ext.BookmarkNodeKt") { - every { any().bookmarkStorage } returns mockk(relaxed = true) - - deleteItem = menu.menuItems(BookmarkNodeType.SEPARATOR, "").last() - } - assertNotNull(deleteItem) - assertEquals("Delete", deleteItem!!.text) - assertEquals( - TextStyle(color = context.getColorFromAttr(R.attr.textWarning)), - deleteItem!!.textStyle, - ) - - deleteItem!!.onClick() - - assertEquals(Item.Delete, lastItemTapped) - } - - @Test - fun `edit item appears for folders`() = runBlocking { - // empty folder - var emptyFolderItems: List? = null - mockkStatic("org.mozilla.fenix.ext.BookmarkNodeKt") { - every { any().bookmarkStorage } returns mockk(relaxed = true) - - emptyFolderItems = menu.menuItems(BookmarkNodeType.FOLDER, "") - } - assertNotNull(emptyFolderItems) - assertEquals(2, emptyFolderItems!!.size) - - // not empty - var folderItems: List? = null - mockkStatic("org.mozilla.fenix.ext.BookmarkNodeKt") { - coEvery { any().bookmarkStorage.getTree("")?.children } returns listOf(mockk(relaxed = true)) - - folderItems = menu.menuItems(BookmarkNodeType.FOLDER, "") - } - assertNotNull(folderItems) - assertEquals(3, folderItems!!.size) - - val (edit, openAll, delete) = folderItems!! - - assertEquals("Edit", edit.text) - assertEquals("Open All Bookmarks", openAll.text) - assertEquals("Delete", delete.text) - - edit.onClick() - assertEquals(Item.Edit, lastItemTapped) - - openAll.onClick() - assertEquals(Item.OpenAllInTabs, lastItemTapped) - - delete.onClick() - assertEquals(Item.Delete, lastItemTapped) - } - @Test fun `delete item has special styling`() { val deleteItem = menu.menuItems(BookmarkNodeType.SEPARATOR).last() @@ -127,16 +61,10 @@ class BookmarkItemMenuTest { } @Test - fun `all item appears for sites`() = runBlocking { - var siteItems: List? = null - mockkStatic("org.mozilla.fenix.ext.BookmarkNodeKt") { - every { any().bookmarkStorage } returns mockk(relaxed = true) - - siteItems = menu.menuItems(BookmarkNodeType.ITEM, "") - } - assertNotNull(siteItems) - assertEquals(6, siteItems!!.size) - val (edit, copy, share, openInNewTab, openInPrivateTab, delete) = siteItems!! + fun `all item appears for sites`() { + val siteItems = menu.menuItems(BookmarkNodeType.ITEM) + assertEquals(6, siteItems.size) + val (edit, copy, share, openInNewTab, openInPrivateTab, delete) = siteItems assertEquals("Edit", edit.text) assertEquals("Copy", copy.text)