diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragmentStore.kt index 6927a4f536..8667840c7e 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragmentStore.kt @@ -159,6 +159,11 @@ sealed class HistoryFragmentAction : Action { */ object BackPressed : HistoryFragmentAction() + /** + * The search menu item has been clicked. + */ + object SearchClicked : HistoryFragmentAction() + /** * Updates the empty state of [org.mozilla.fenix.library.history.HistoryView]. */ @@ -281,6 +286,7 @@ private fun historyStateReducer( is HistoryFragmentAction.DeleteItems, is HistoryFragmentAction.DeleteTimeRange, is HistoryFragmentAction.EnterRecentlyClosed, + is HistoryFragmentAction.SearchClicked, -> state } } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddleware.kt b/app/src/main/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddleware.kt index 13fd0386af..564e51783e 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddleware.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.launch import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.MiddlewareContext import org.mozilla.fenix.R +import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.library.history.History import org.mozilla.fenix.library.history.HistoryFragmentAction import org.mozilla.fenix.library.history.HistoryFragmentDirections @@ -72,6 +73,12 @@ class HistoryNavigationMiddleware( } } } + is HistoryFragmentAction.SearchClicked -> { + navController.navigateSafe( + R.id.historyFragment, + HistoryFragmentDirections.actionGlobalSearchDialog(null), + ) + } else -> Unit } } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt b/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt index 9842cd9c79..06b65e45f7 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt @@ -45,7 +45,11 @@ class HistoryListItemViewHolder( contentDescription = view.context.getString(R.string.history_delete_item) setOnClickListener { val item = item ?: return@setOnClickListener - historyInteractor.onDeleteSome(setOf(item)) + if (FeatureFlags.historyFragmentLibStateRefactor) { + store.dispatch(HistoryFragmentAction.DeleteItems(setOf(item))) + } else { + historyInteractor.onDeleteSome(setOf(item)) + } } } } diff --git a/app/src/test/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddlewareTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddlewareTest.kt index 42d6e24885..01a1f0d4bc 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddlewareTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/state/HistoryNavigationMiddlewareTest.kt @@ -19,6 +19,7 @@ import org.junit.Rule import org.junit.Test import org.mockito.Mockito.verify import org.mozilla.fenix.R +import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.library.history.History import org.mozilla.fenix.library.history.HistoryFragmentAction import org.mozilla.fenix.library.history.HistoryFragmentDirections @@ -168,4 +169,23 @@ class HistoryNavigationMiddlewareTest { assertTrue(onBackPressed) } + + @Test + fun `WHEN search is clicked THEN search navigated to`() = runTest { + val navController = mock() + val middleware = HistoryNavigationMiddleware( + navController = navController, + openToBrowser = { }, + onBackPressed = { }, + scope = this, + ) + + val store = + HistoryFragmentStore(HistoryFragmentState.initial, middleware = listOf(middleware)) + + store.dispatch(HistoryFragmentAction.SearchClicked).joinBlocking() + advanceUntilIdle() + + verify(navController).navigateSafe(R.id.historyFragment, HistoryFragmentDirections.actionGlobalSearchDialog(null)) + } }