|
|
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.autofill
|
|
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
import androidx.preference.Preference
|
|
|
|
|
import androidx.preference.SwitchPreference
|
|
|
|
|
import io.mockk.every
|
|
|
|
|
import io.mockk.mockk
|
|
|
|
|
import io.mockk.verify
|
|
|
|
@ -17,8 +18,10 @@ import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
|
|
|
|
import mozilla.components.support.test.rule.runTestOnMain
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
@ -34,15 +37,17 @@ class AutofillSettingFragmentTest {
|
|
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
|
val coroutinesTestRule = MainCoroutineRule()
|
|
|
|
|
private val testDispatcher = coroutinesTestRule.testDispatcher
|
|
|
|
|
private lateinit var autofillSettingFragment: AutofillSettingFragment
|
|
|
|
|
private val navController: NavController = mockk(relaxed = true)
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setUp() = runTestOnMain {
|
|
|
|
|
every { testContext.components.settings } returns mockk(relaxed = true)
|
|
|
|
|
every { testContext.components.core } returns mockk(relaxed = true)
|
|
|
|
|
|
|
|
|
|
every { testContext.components.settings.addressFeature } returns true
|
|
|
|
|
every { testContext.components.settings.shouldAutofillCreditCardDetails } returns true
|
|
|
|
|
every { testContext.components.settings.shouldAutofillAddressDetails } returns true
|
|
|
|
|
|
|
|
|
|
autofillSettingFragment = AutofillSettingFragment()
|
|
|
|
|
|
|
|
|
@ -163,4 +168,60 @@ class AutofillSettingFragmentTest {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN the autofill addresses feature is enabled THEN the addresses switch preference is checked`() = runTestOnMain {
|
|
|
|
|
every { testContext.components.settings.shouldAutofillAddressDetails } returns true
|
|
|
|
|
|
|
|
|
|
val autofillAddressesPreference = autofillSettingFragment.findPreference<SwitchPreference>(
|
|
|
|
|
autofillSettingFragment.getPreferenceKey(R.string.pref_key_addresses_save_and_autofill_addresses)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
autofillSettingFragment.updateSaveAndAutofillAddressesSwitch()
|
|
|
|
|
|
|
|
|
|
assertNotNull(autofillAddressesPreference)
|
|
|
|
|
assertTrue(autofillAddressesPreference?.isChecked!!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN the autofill addresses feature is disabled THEN the addresses switch preference is NOT checked`() = runTestOnMain {
|
|
|
|
|
every { testContext.components.settings.shouldAutofillAddressDetails } returns false
|
|
|
|
|
|
|
|
|
|
val autofillAddressesPreference = autofillSettingFragment.findPreference<SwitchPreference>(
|
|
|
|
|
autofillSettingFragment.getPreferenceKey(R.string.pref_key_addresses_save_and_autofill_addresses)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
autofillSettingFragment.updateSaveAndAutofillAddressesSwitch()
|
|
|
|
|
|
|
|
|
|
assertNotNull(autofillAddressesPreference)
|
|
|
|
|
assertFalse(autofillAddressesPreference?.isChecked!!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN the autofill cards feature is enabled THEN cards the switch preference is checked`() = runTestOnMain {
|
|
|
|
|
every { testContext.components.settings.shouldAutofillCreditCardDetails } returns true
|
|
|
|
|
|
|
|
|
|
val autofillCardsPreference = autofillSettingFragment.findPreference<SwitchPreference>(
|
|
|
|
|
autofillSettingFragment.getPreferenceKey(R.string.pref_key_credit_cards_save_and_autofill_cards)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
autofillSettingFragment.updateSaveAndAutofillCardsSwitch()
|
|
|
|
|
|
|
|
|
|
assertNotNull(autofillCardsPreference)
|
|
|
|
|
assertTrue(autofillCardsPreference?.isChecked!!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN the autofill cards feature is disabled THEN the cards switch preference is NOT checked`() = runTestOnMain {
|
|
|
|
|
every { testContext.components.settings.shouldAutofillCreditCardDetails } returns false
|
|
|
|
|
|
|
|
|
|
val autofillCardsPreference = autofillSettingFragment.findPreference<SwitchPreference>(
|
|
|
|
|
autofillSettingFragment.getPreferenceKey(R.string.pref_key_credit_cards_save_and_autofill_cards)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
autofillSettingFragment.updateSaveAndAutofillCardsSwitch()
|
|
|
|
|
|
|
|
|
|
assertNotNull(autofillCardsPreference)
|
|
|
|
|
assertFalse(autofillCardsPreference?.isChecked!!)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|