From 0a46f6d16a6ad5c867fbd6cc060e945c2b75dbdd Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Fri, 30 Aug 2019 15:21:34 +0200 Subject: [PATCH] [fenix] Rename SearchStore/State/Action to SearchFragmentStore/State/Action. --- .../mozilla/fenix/search/SearchController.kt | 8 ++--- .../mozilla/fenix/search/SearchFragment.kt | 16 +++++----- ...{SearchStore.kt => SearchFragmentStore.kt} | 30 +++++++++---------- .../fenix/search/awesomebar/AwesomeBarView.kt | 4 +-- .../fenix/search/toolbar/ToolbarView.kt | 4 +-- .../search/DefaultSearchControllerTest.kt | 8 ++--- ...toreTest.kt => SearchFragmentStoreTest.kt} | 16 +++++----- .../fenix/search/SearchInteractorTest.kt | 28 ++++++++--------- 8 files changed, 57 insertions(+), 57 deletions(-) rename app/src/main/java/org/mozilla/fenix/search/{SearchStore.kt => SearchFragmentStore.kt} (76%) rename app/src/test/java/org/mozilla/fenix/search/{SearchStoreTest.kt => SearchFragmentStoreTest.kt} (73%) diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt index 2f1fc0c2b2..3fa0eda8c9 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt @@ -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)) } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index fab7241ea3..7949ea6e4d 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -50,7 +50,7 @@ class SearchFragment : Fragment(), BackHandler { private lateinit var awesomeBarView: AwesomeBarView private val qrFeature = ViewBoundFeatureWrapper() 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 diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchStore.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt similarity index 76% rename from app/src/main/java/org/mozilla/fenix/search/SearchStore.kt rename to app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt index 98f9ae3252..7bed7d7ec0 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchStore.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt @@ -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( +class SearchFragmentStore( + initialState: SearchFragmentState +) : Store( 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 diff --git a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt index 3fac4cb3f7..42c6335ab7 100644 --- a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt @@ -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) { diff --git a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt index 77127e38a0..761dfd2001 100644 --- a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt @@ -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 ?: "") diff --git a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt index 193e40abd2..5fcdadd1d6 100644 --- a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt @@ -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)) } } diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchStoreTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt similarity index 73% rename from app/src/test/java/org/mozilla/fenix/search/SearchStoreTest.kt rename to app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt index 1b1375a9f6..f01e7724b4 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt @@ -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(), diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt index b2c9dc359f..12ace11ce9 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt @@ -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(