[fenix] For https://github.com/mozilla-mobile/fenix/issues/14034: Add debug preference to override AMO collection in Nightly
parent
9e86e369b6
commit
76018e2fe0
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/custom_amo_user"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/customize_addon_collection_user_hint"
|
||||
android:singleLine="true"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textColor="?primaryText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/custom_amo_collection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/customize_addon_collection_hint"
|
||||
android:singleLine="true"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textColor="?primaryText"/>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,76 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.settings
|
||||
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.Preference
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
import org.robolectric.Robolectric
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class SettingsFragmentTest {
|
||||
|
||||
@Test
|
||||
fun `Add-on collection override pref is visible if debug menu active`() {
|
||||
val settingsFragment = SettingsFragment()
|
||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
||||
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.add(settingsFragment, "test")
|
||||
.commitNow()
|
||||
|
||||
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
||||
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection)
|
||||
)
|
||||
|
||||
settingsFragment.setupAmoCollectionOverridePreference(mockk(relaxed = true))
|
||||
assertNotNull(preferenceAmoCollectionOverride)
|
||||
assertFalse(preferenceAmoCollectionOverride!!.isVisible)
|
||||
|
||||
val settings: Settings = mockk(relaxed = true)
|
||||
every { settings.showSecretDebugMenuThisSession } returns true
|
||||
settingsFragment.setupAmoCollectionOverridePreference(settings)
|
||||
assertTrue(preferenceAmoCollectionOverride.isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Add-on collection override pref is visible if already configured`() {
|
||||
val settingsFragment = SettingsFragment()
|
||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
||||
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.add(settingsFragment, "test")
|
||||
.commitNow()
|
||||
|
||||
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
||||
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection)
|
||||
)
|
||||
|
||||
settingsFragment.setupAmoCollectionOverridePreference(mockk(relaxed = true))
|
||||
assertNotNull(preferenceAmoCollectionOverride)
|
||||
assertFalse(preferenceAmoCollectionOverride!!.isVisible)
|
||||
|
||||
val settings: Settings = mockk(relaxed = true)
|
||||
every { settings.showSecretDebugMenuThisSession } returns false
|
||||
|
||||
every { settings.amoCollectionOverrideConfigured() } returns false
|
||||
settingsFragment.setupAmoCollectionOverridePreference(settings)
|
||||
assertFalse(preferenceAmoCollectionOverride.isVisible)
|
||||
|
||||
every { settings.amoCollectionOverrideConfigured() } returns true
|
||||
settingsFragment.setupAmoCollectionOverridePreference(settings)
|
||||
assertTrue(preferenceAmoCollectionOverride.isVisible)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue