From 9b20f9c1c0b6e4c61483fd884e755fd4919ce5c7 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Wed, 11 Aug 2021 17:12:48 -0400 Subject: [PATCH] [fenix] Close https://github.com/mozilla-mobile/fenix/issues/20792: Fix intermittent test failures in QuickSettingsFragmentReducerTest --- .../QuickSettingsFragmentReducer.kt | 2 +- .../QuickSettingsFragmentReducerTest.kt | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducer.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducer.kt index e26c7f3f0f..3260fee33a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducer.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducer.kt @@ -7,7 +7,7 @@ package org.mozilla.fenix.settings.quicksettings /** * Parent Reducer for all [QuickSettingsFragmentState]s of all Views shown in this Fragment. */ -fun quickSettingsFragmentReducer( +internal fun quickSettingsFragmentReducer( state: QuickSettingsFragmentState, action: QuickSettingsFragmentAction ): QuickSettingsFragmentState { diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducerTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducerTest.kt index 14e4cfc525..82653d1805 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentReducerTest.kt @@ -4,16 +4,14 @@ package org.mozilla.fenix.settings.quicksettings -import mozilla.components.support.test.mock +import mozilla.components.feature.sitepermissions.SitePermissionsRules import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue -import org.junit.Ignore import org.junit.Test import org.mozilla.fenix.settings.PhoneFeature class QuickSettingsFragmentReducerTest { - @Ignore("See https://github.com/mozilla-mobile/fenix/issues/20792") @Test fun `WebsitePermissionAction - TogglePermission`() { val toggleablePermission = WebsitePermission.Toggleable( @@ -26,8 +24,8 @@ class QuickSettingsFragmentReducerTest { val map = mapOf(PhoneFeature.CAMERA to toggleablePermission) - - val state = QuickSettingsFragmentState(mock(), map) + val infoState = WebsiteInfoState("", "", WebsiteSecurityUiValues.SECURE, "") + val state = QuickSettingsFragmentState(infoState, map) val newState = quickSettingsFragmentReducer( state, WebsitePermissionAction.TogglePermission( @@ -46,7 +44,7 @@ class QuickSettingsFragmentReducerTest { val permissionPermission = WebsitePermission.Autoplay( autoplayValue = AutoplayValue.BlockAll( label = "label", - rules = mock(), + rules = createTestRule(), sitePermission = null ), options = emptyList(), @@ -55,11 +53,11 @@ class QuickSettingsFragmentReducerTest { val map = mapOf(PhoneFeature.AUTOPLAY to permissionPermission) - - val state = QuickSettingsFragmentState(mock(), map) + val infoState = WebsiteInfoState("", "", WebsiteSecurityUiValues.SECURE, "") + val state = QuickSettingsFragmentState(infoState, map) val autoplayValue = AutoplayValue.AllowAll( label = "newLabel", - rules = mock(), + rules = createTestRule(), sitePermission = null ) val newState = quickSettingsFragmentReducer( @@ -71,4 +69,15 @@ class QuickSettingsFragmentReducerTest { newState.websitePermissionsState[PhoneFeature.AUTOPLAY] as WebsitePermission.Autoplay assertEquals(autoplayValue, result.autoplayValue) } + + private fun createTestRule() = SitePermissionsRules( + SitePermissionsRules.Action.ALLOWED, + SitePermissionsRules.Action.ALLOWED, + SitePermissionsRules.Action.ALLOWED, + SitePermissionsRules.Action.ALLOWED, + SitePermissionsRules.AutoplayAction.ALLOWED, + SitePermissionsRules.AutoplayAction.ALLOWED, + SitePermissionsRules.Action.ALLOWED, + SitePermissionsRules.Action.ALLOWED, + ) }