mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/25811 - Add header to unified search engine menu
This commit is contained in:
parent
2dca91e984
commit
ae6bdc265d
@ -730,9 +730,9 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
||||
) {
|
||||
interactor.onMenuItemTapped(SearchSelectorMenu.Item.SearchEngine(it))
|
||||
}
|
||||
} + searchSelectorMenu.menuItems()
|
||||
}
|
||||
|
||||
searchSelectorMenu.menuController.submitList(searchEngineList)
|
||||
searchSelectorMenu.menuController.submitList(searchSelectorMenu.menuItems(searchEngineList))
|
||||
toolbarView.view.invalidateActions()
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,13 @@
|
||||
package org.mozilla.fenix.search.toolbar
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import mozilla.components.browser.menu2.BrowserMenuController
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.concept.menu.MenuController
|
||||
import mozilla.components.concept.menu.candidate.DecorativeTextMenuCandidate
|
||||
import mozilla.components.concept.menu.candidate.DrawableMenuIcon
|
||||
import mozilla.components.concept.menu.candidate.MenuCandidate
|
||||
import mozilla.components.concept.menu.candidate.TextMenuCandidate
|
||||
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
||||
import org.mozilla.fenix.R
|
||||
@ -47,10 +48,11 @@ class SearchSelectorMenu(
|
||||
|
||||
val menuController: MenuController by lazy { BrowserMenuController() }
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun menuItems(): List<TextMenuCandidate> {
|
||||
return listOf(
|
||||
TextMenuCandidate(
|
||||
internal fun menuItems(searchEngines: List<MenuCandidate>): List<MenuCandidate> {
|
||||
val headerCandidate = DecorativeTextMenuCandidate(
|
||||
text = context.getString(R.string.search_header_menu_item),
|
||||
)
|
||||
val settingsCandidate = TextMenuCandidate(
|
||||
text = context.getString(R.string.search_settings_menu_item),
|
||||
start = DrawableMenuIcon(
|
||||
drawable = AppCompatResources.getDrawable(
|
||||
@ -61,7 +63,7 @@ class SearchSelectorMenu(
|
||||
),
|
||||
) {
|
||||
interactor.onMenuItemTapped(Item.SearchSettings)
|
||||
},
|
||||
)
|
||||
}
|
||||
return listOf(headerCandidate) + searchEngines + listOf(settingsCandidate)
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +239,8 @@
|
||||
<string name="search_engine_suggestions_description">Search directly from the address bar</string>
|
||||
<!-- Menu option in the search selector menu to open the search settings -->
|
||||
<string name="search_settings_menu_item">Search settings</string>
|
||||
<!-- Header text for the search selector menu -->
|
||||
<string name="search_header_menu_item">This time search:</string>
|
||||
|
||||
<!-- Home onboarding -->
|
||||
<!-- Onboarding home screen dialog title text. The first parameter is the name of the application.-->
|
||||
|
@ -0,0 +1,47 @@
|
||||
package org.mozilla.fenix.search.toolbar
|
||||
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.concept.menu.candidate.DecorativeTextMenuCandidate
|
||||
import mozilla.components.concept.menu.candidate.TextMenuCandidate
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class SearchSelectorMenuTest {
|
||||
|
||||
private lateinit var menu: SearchSelectorMenu
|
||||
private val interactor = mockk<ToolbarInteractor>()
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
menu = SearchSelectorMenu(testContext, interactor)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN building the menu items THEN the header is the first item AND the search settings is the last item`() {
|
||||
every { interactor.onMenuItemTapped(any()) } just Runs
|
||||
|
||||
val items = menu.menuItems(listOf())
|
||||
val lastItem = (items.last() as TextMenuCandidate)
|
||||
lastItem.onClick()
|
||||
|
||||
assertEquals(
|
||||
testContext.getString(R.string.search_header_menu_item),
|
||||
(items.first() as DecorativeTextMenuCandidate).text,
|
||||
)
|
||||
assertEquals(
|
||||
testContext.getString(R.string.search_settings_menu_item),
|
||||
lastItem.text,
|
||||
)
|
||||
verify { interactor.onMenuItemTapped(SearchSelectorMenu.Item.SearchSettings) }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user