commit b87aaa0c735361b75d26564e5d6c577cd1b449fe
parent f9d8702e26624ab46a35bf6561a7c8143c6f246a
Author: mcarare <48995920+mcarare@users.noreply.github.com>
Date: Mon, 29 Dec 2025 15:22:04 +0000
Bug 2007342 - Refactor TrustPanelNavigationMiddlewareTest to use runTest scope. r=android-reviewers,rebecatudor273
Updated `TrustPanelNavigationMiddlewareTest` to remove `MainCoroutineRule` and instead use the `CoroutineScope` provided by `runTest`. Included calls to `testScheduler.advanceUntilIdle()` to ensure dispatched actions are processed before verification.
Differential Revision: https://phabricator.services.mozilla.com/D277349
Diffstat:
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/settings/trustpanel/TrustPanelNavigationMiddlewareTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/settings/trustpanel/TrustPanelNavigationMiddlewareTest.kt
@@ -12,9 +12,8 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
+import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.runTest
-import mozilla.components.support.test.rule.MainCoroutineRule
-import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.settings.PhoneFeature
@@ -25,10 +24,6 @@ import org.mozilla.fenix.settings.trustpanel.store.TrustPanelStore
class TrustPanelNavigationMiddlewareTest {
- @get:Rule
- val coroutinesTestRule = MainCoroutineRule()
- private val scope = coroutinesTestRule.scope
-
private val navController: NavController = mockk(relaxed = true) {
every { navigate(any<NavDirections>(), any<NavOptions>()) } just runs
every { currentDestination?.id } returns R.id.trustPanelFragment
@@ -37,8 +32,9 @@ class TrustPanelNavigationMiddlewareTest {
@Test
fun `WHEN navigate to privacy security settings action is dispatched THEN navigate to privacy and security settings`() = runTest {
val privacySecurityPrefKey = "pref_key_privacy_security_category"
- val store = createStore(privacySecurityPrefKey = privacySecurityPrefKey)
+ val store = createStore(privacySecurityPrefKey = privacySecurityPrefKey, scope = this)
store.dispatch(TrustPanelAction.Navigate.PrivacySecuritySettings)
+ testScheduler.advanceUntilIdle()
verify {
navController.navigate(
@@ -52,8 +48,9 @@ class TrustPanelNavigationMiddlewareTest {
@Test
fun `WHEN navigate to manage phone feature is dispatched THEN navigate to manage phone feature`() = runTest {
- val store = createStore()
+ val store = createStore(scope = this)
store.dispatch(TrustPanelAction.Navigate.ManagePhoneFeature(PhoneFeature.CAMERA))
+ testScheduler.advanceUntilIdle()
verify {
navController.navigate(
@@ -66,6 +63,7 @@ class TrustPanelNavigationMiddlewareTest {
private fun createStore(
trustPanelState: TrustPanelState = TrustPanelState(),
privacySecurityPrefKey: String = "",
+ scope: CoroutineScope,
) = TrustPanelStore(
initialState = trustPanelState,
middleware = listOf(