Bug 1854709 - Add Store actions for remaining History interactor calls

fenix/120.0
Matthew Tighe 9 months ago committed by mergify[bot]
parent c403789ab4
commit 1020af9827

@ -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
}
}

@ -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
}
}

@ -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))
}
}
}
}

@ -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<NavController>()
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))
}
}

Loading…
Cancel
Save