mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Rename SearchStore/State/Action to SearchFragmentStore/State/Action.
This commit is contained in:
parent
5a3bfb2b77
commit
0a46f6d16a
@ -36,7 +36,7 @@ interface SearchController {
|
||||
|
||||
class DefaultSearchController(
|
||||
private val context: Context,
|
||||
private val store: SearchStore,
|
||||
private val store: SearchFragmentStore,
|
||||
private val navController: NavController
|
||||
) : SearchController {
|
||||
|
||||
@ -68,10 +68,10 @@ class DefaultSearchController(
|
||||
}
|
||||
|
||||
override fun handleTextChanged(text: String) {
|
||||
store.dispatch(SearchAction.UpdateQuery(text))
|
||||
store.dispatch(SearchFragmentAction.UpdateQuery(text))
|
||||
|
||||
if (userTypingCheck.ranOnTextChanged && !userTypingCheck.userHasTyped) {
|
||||
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(false))
|
||||
store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false))
|
||||
handleTurnOnStartedTyping()
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ class DefaultSearchController(
|
||||
}
|
||||
|
||||
override fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine) {
|
||||
store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine))
|
||||
store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine))
|
||||
context.metrics.track(Event.SearchShortcutSelected(searchEngine.name))
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
private lateinit var awesomeBarView: AwesomeBarView
|
||||
private val qrFeature = ViewBoundFeatureWrapper<QrFeature>()
|
||||
private var permissionDidUpdate = false
|
||||
private lateinit var searchStore: SearchStore
|
||||
private lateinit var searchStore: SearchFragmentStore
|
||||
private lateinit var searchInteractor: SearchInteractor
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -85,8 +85,8 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
)
|
||||
|
||||
searchStore = StoreProvider.get(this) {
|
||||
SearchStore(
|
||||
SearchState(
|
||||
SearchFragmentStore(
|
||||
SearchFragmentState(
|
||||
query = url,
|
||||
showShortcutEnginePicker = displayShortcutEnginePicker,
|
||||
searchEngineSource = currentSearchEngine,
|
||||
@ -180,7 +180,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
|
||||
searchShortcutsButton.setOnClickListener {
|
||||
val isOpen = searchStore.state.showShortcutEnginePicker
|
||||
searchStore.dispatch(SearchAction.ShowSearchShortcutEnginePicker(!isOpen))
|
||||
searchStore.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(!isOpen))
|
||||
|
||||
if (isOpen) {
|
||||
requireComponents.analytics.metrics.track(Event.SearchShortcutMenuClosed)
|
||||
@ -215,7 +215,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
|
||||
if (searchStore.state.defaultEngineSource.searchEngine != currentDefaultEngine) {
|
||||
searchStore.dispatch(
|
||||
SearchAction.SelectNewDefaultSearchEngine
|
||||
SearchFragmentAction.SelectNewDefaultSearchEngine
|
||||
(currentDefaultEngine)
|
||||
)
|
||||
}
|
||||
@ -244,7 +244,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSearchEngineIcon(searchState: SearchState) {
|
||||
private fun updateSearchEngineIcon(searchState: SearchFragmentState) {
|
||||
val searchIcon = searchState.searchEngineSource.searchEngine.icon
|
||||
val draw = BitmapDrawable(resources, searchIcon)
|
||||
val iconSize = resources.getDimension(R.dimen.preference_icon_drawable_size).toInt()
|
||||
@ -252,12 +252,12 @@ class SearchFragment : Fragment(), BackHandler {
|
||||
searchEngineIcon?.backgroundDrawable = draw
|
||||
}
|
||||
|
||||
private fun updateSearchWithLabel(searchState: SearchState) {
|
||||
private fun updateSearchWithLabel(searchState: SearchFragmentState) {
|
||||
searchWithShortcuts.visibility =
|
||||
if (searchState.showShortcutEnginePicker) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
private fun updateSearchShortuctsIcon(searchState: SearchState) {
|
||||
private fun updateSearchShortuctsIcon(searchState: SearchFragmentState) {
|
||||
with(requireContext()) {
|
||||
val showShortcuts = searchState.showShortcutEnginePicker
|
||||
searchShortcutsButton?.isChecked = showShortcuts
|
||||
|
@ -11,11 +11,11 @@ import mozilla.components.lib.state.State
|
||||
import mozilla.components.lib.state.Store
|
||||
|
||||
/**
|
||||
* The [Store] for holding the [SearchState] and applying [SearchAction]s.
|
||||
* The [Store] for holding the [SearchFragmentState] and applying [SearchFragmentAction]s.
|
||||
*/
|
||||
class SearchStore(
|
||||
initialState: SearchState
|
||||
) : Store<SearchState, SearchAction>(
|
||||
class SearchFragmentStore(
|
||||
initialState: SearchFragmentState
|
||||
) : Store<SearchFragmentState, SearchFragmentAction>(
|
||||
initialState,
|
||||
::searchStateReducer
|
||||
)
|
||||
@ -40,7 +40,7 @@ sealed class SearchEngineSource {
|
||||
* @property showVisitedSitesBookmarks Whether or not to show history and bookmark suggestions in the AwesomeBar
|
||||
* @property session The current session if available
|
||||
*/
|
||||
data class SearchState(
|
||||
data class SearchFragmentState(
|
||||
val query: String,
|
||||
val showShortcutEnginePicker: Boolean,
|
||||
val searchEngineSource: SearchEngineSource,
|
||||
@ -53,28 +53,28 @@ data class SearchState(
|
||||
/**
|
||||
* Actions to dispatch through the `SearchStore` to modify `SearchState` through the reducer.
|
||||
*/
|
||||
sealed class SearchAction : Action {
|
||||
data class SearchShortcutEngineSelected(val engine: SearchEngine) : SearchAction()
|
||||
data class SelectNewDefaultSearchEngine(val engine: SearchEngine) : SearchAction()
|
||||
data class ShowSearchShortcutEnginePicker(val show: Boolean) : SearchAction()
|
||||
data class UpdateQuery(val query: String) : SearchAction()
|
||||
sealed class SearchFragmentAction : Action {
|
||||
data class SearchShortcutEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
|
||||
data class SelectNewDefaultSearchEngine(val engine: SearchEngine) : SearchFragmentAction()
|
||||
data class ShowSearchShortcutEnginePicker(val show: Boolean) : SearchFragmentAction()
|
||||
data class UpdateQuery(val query: String) : SearchFragmentAction()
|
||||
}
|
||||
|
||||
/**
|
||||
* The SearchState Reducer.
|
||||
*/
|
||||
fun searchStateReducer(state: SearchState, action: SearchAction): SearchState {
|
||||
fun searchStateReducer(state: SearchFragmentState, action: SearchFragmentAction): SearchFragmentState {
|
||||
return when (action) {
|
||||
is SearchAction.SearchShortcutEngineSelected ->
|
||||
is SearchFragmentAction.SearchShortcutEngineSelected ->
|
||||
state.copy(
|
||||
searchEngineSource = SearchEngineSource.Shortcut(action.engine),
|
||||
showShortcutEnginePicker = false
|
||||
)
|
||||
is SearchAction.ShowSearchShortcutEnginePicker ->
|
||||
is SearchFragmentAction.ShowSearchShortcutEnginePicker ->
|
||||
state.copy(showShortcutEnginePicker = action.show)
|
||||
is SearchAction.UpdateQuery ->
|
||||
is SearchFragmentAction.UpdateQuery ->
|
||||
state.copy(query = action.query)
|
||||
is SearchAction.SelectNewDefaultSearchEngine ->
|
||||
is SearchFragmentAction.SelectNewDefaultSearchEngine ->
|
||||
state.copy(
|
||||
searchEngineSource = SearchEngineSource.Default(action.engine),
|
||||
showShortcutEnginePicker = false
|
@ -29,7 +29,7 @@ import org.mozilla.fenix.ext.asActivity
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.getColorFromAttr
|
||||
import org.mozilla.fenix.search.SearchEngineSource
|
||||
import org.mozilla.fenix.search.SearchState
|
||||
import org.mozilla.fenix.search.SearchFragmentState
|
||||
|
||||
/**
|
||||
* Interface for the AwesomeBarView Interactor. This interface is implemented by objects that want
|
||||
@ -171,7 +171,7 @@ class AwesomeBarView(
|
||||
}
|
||||
}
|
||||
|
||||
fun update(state: SearchState) {
|
||||
fun update(state: SearchFragmentState) {
|
||||
view.removeAllProviders()
|
||||
|
||||
if (state.showShortcutEnginePicker) {
|
||||
|
@ -17,7 +17,7 @@ import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
|
||||
import mozilla.components.support.ktx.android.util.dpToPx
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.getColorFromAttr
|
||||
import org.mozilla.fenix.search.SearchState
|
||||
import org.mozilla.fenix.search.SearchFragmentState
|
||||
|
||||
/**
|
||||
* Interface for the Toolbar Interactor. This interface is implemented by objects that want
|
||||
@ -109,7 +109,7 @@ class ToolbarView(
|
||||
}
|
||||
}
|
||||
|
||||
fun update(searchState: SearchState) {
|
||||
fun update(searchState: SearchFragmentState) {
|
||||
if (!isInitialized) {
|
||||
view.url = searchState.query
|
||||
view.setSearchTerms(searchState.session?.searchTerms ?: "")
|
||||
|
@ -28,7 +28,7 @@ import org.mozilla.fenix.ext.searchEngineManager
|
||||
class DefaultSearchControllerTest {
|
||||
|
||||
private val context: HomeActivity = mockk(relaxed = true)
|
||||
private val store: SearchStore = mockk(relaxed = true)
|
||||
private val store: SearchFragmentStore = mockk(relaxed = true)
|
||||
private val navController: NavController = mockk(relaxed = true)
|
||||
private val defaultSearchEngine: SearchEngine? = mockk(relaxed = true)
|
||||
private val session: Session? = mockk(relaxed = true)
|
||||
@ -82,9 +82,9 @@ class DefaultSearchControllerTest {
|
||||
|
||||
controller.handleTextChanged(text)
|
||||
|
||||
verify { store.dispatch(SearchAction.UpdateQuery(text)) }
|
||||
verify { store.dispatch(SearchFragmentAction.UpdateQuery(text)) }
|
||||
verify(inverse = true) {
|
||||
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(false))
|
||||
store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false))
|
||||
}
|
||||
assertTrue(controller.userTypingCheck.ranOnTextChanged)
|
||||
}
|
||||
@ -124,7 +124,7 @@ class DefaultSearchControllerTest {
|
||||
|
||||
controller.handleSearchShortcutEngineSelected(searchEngine)
|
||||
|
||||
verify { store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)) }
|
||||
verify { store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine)) }
|
||||
verify { metrics.track(Event.SearchShortcutSelected(searchEngine.name)) }
|
||||
}
|
||||
|
||||
|
@ -11,15 +11,15 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Test
|
||||
|
||||
class SearchStoreTest {
|
||||
class SearchFragmentStoreTest {
|
||||
|
||||
@Test
|
||||
fun updateQuery() = runBlocking {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = SearchStore(initialState)
|
||||
val store = SearchFragmentStore(initialState)
|
||||
val query = "test query"
|
||||
|
||||
store.dispatch(SearchAction.UpdateQuery(query)).join()
|
||||
store.dispatch(SearchFragmentAction.UpdateQuery(query)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(query, store.state.query)
|
||||
}
|
||||
@ -27,10 +27,10 @@ class SearchStoreTest {
|
||||
@Test
|
||||
fun selectSearchShortcutEngine() = runBlocking {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = SearchStore(initialState)
|
||||
val store = SearchFragmentStore(initialState)
|
||||
val searchEngine: SearchEngine = mockk()
|
||||
|
||||
store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)).join()
|
||||
store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(SearchEngineSource.Shortcut(searchEngine), store.state.searchEngineSource)
|
||||
}
|
||||
@ -38,14 +38,14 @@ class SearchStoreTest {
|
||||
@Test
|
||||
fun showSearchShortcutEnginePicker() = runBlocking {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = SearchStore(initialState)
|
||||
val store = SearchFragmentStore(initialState)
|
||||
|
||||
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(true)).join()
|
||||
store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(true, store.state.showShortcutEnginePicker)
|
||||
}
|
||||
|
||||
private fun emptyDefaultState(): SearchState = SearchState(
|
||||
private fun emptyDefaultState(): SearchFragmentState = SearchFragmentState(
|
||||
query = "",
|
||||
searchEngineSource = mockk(),
|
||||
defaultEngineSource = mockk(),
|
@ -28,8 +28,8 @@ class SearchInteractorTest {
|
||||
@Test
|
||||
fun onUrlCommitted() {
|
||||
val context: HomeActivity = mockk()
|
||||
val store: SearchStore = mockk()
|
||||
val state: SearchState = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
val state: SearchFragmentState = mockk()
|
||||
val searchEngineManager: SearchEngineManager = mockk(relaxed = true)
|
||||
val searchEngine = SearchEngineSource.Default(mockk())
|
||||
|
||||
@ -64,7 +64,7 @@ class SearchInteractorTest {
|
||||
@Test
|
||||
fun onEditingCanceled() {
|
||||
val navController: NavController = mockk(relaxed = true)
|
||||
val store: SearchStore = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
|
||||
every { store.state } returns mockk(relaxed = true)
|
||||
|
||||
@ -84,7 +84,7 @@ class SearchInteractorTest {
|
||||
|
||||
@Test
|
||||
fun onTextChanged() {
|
||||
val store: SearchStore = mockk(relaxed = true)
|
||||
val store: SearchFragmentStore = mockk(relaxed = true)
|
||||
|
||||
every { store.state } returns mockk(relaxed = true)
|
||||
|
||||
@ -97,14 +97,14 @@ class SearchInteractorTest {
|
||||
|
||||
interactor.onTextChanged("test")
|
||||
|
||||
verify { store.dispatch(SearchAction.UpdateQuery("test")) }
|
||||
verify { store.dispatch(SearchFragmentAction.UpdateQuery("test")) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onUrlTapped() {
|
||||
val context: HomeActivity = mockk()
|
||||
val store: SearchStore = mockk()
|
||||
val state: SearchState = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
val state: SearchFragmentState = mockk()
|
||||
|
||||
every { context.metrics } returns mockk(relaxed = true)
|
||||
every { context.openToBrowserAndLoad(any(), any(), any()) } just Runs
|
||||
@ -134,8 +134,8 @@ class SearchInteractorTest {
|
||||
@Test
|
||||
fun onSearchTermsTapped() {
|
||||
val context: HomeActivity = mockk()
|
||||
val store: SearchStore = mockk()
|
||||
val state: SearchState = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
val state: SearchFragmentState = mockk()
|
||||
val searchEngineManager: SearchEngineManager = mockk(relaxed = true)
|
||||
val searchEngine = SearchEngineSource.Default(mockk())
|
||||
|
||||
@ -174,8 +174,8 @@ class SearchInteractorTest {
|
||||
|
||||
every { context.metrics } returns mockk(relaxed = true)
|
||||
|
||||
val store: SearchStore = mockk(relaxed = true)
|
||||
val state: SearchState = mockk(relaxed = true)
|
||||
val store: SearchFragmentStore = mockk(relaxed = true)
|
||||
val state: SearchFragmentState = mockk(relaxed = true)
|
||||
|
||||
every { store.state } returns state
|
||||
|
||||
@ -189,13 +189,13 @@ class SearchInteractorTest {
|
||||
|
||||
interactor.onSearchShortcutEngineSelected(searchEngine)
|
||||
|
||||
verify { store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)) }
|
||||
verify { store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onClickSearchEngineSettings() {
|
||||
val navController: NavController = mockk()
|
||||
val store: SearchStore = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
|
||||
every { store.state } returns mockk(relaxed = true)
|
||||
|
||||
@ -224,7 +224,7 @@ class SearchInteractorTest {
|
||||
val context: Context = mockk(relaxed = true)
|
||||
val applicationContext: FenixApplication = mockk(relaxed = true)
|
||||
every { context.applicationContext } returns applicationContext
|
||||
val store: SearchStore = mockk()
|
||||
val store: SearchFragmentStore = mockk()
|
||||
every { store.state } returns mockk(relaxed = true)
|
||||
|
||||
val searchController: SearchController = DefaultSearchController(
|
||||
|
Loading…
Reference in New Issue
Block a user