1
0
Fork 0

Test settings about/advanced (#12023)

master
Tiger Oakes 2020-06-26 15:53:30 -07:00 committed by GitHub
parent e71e7fb9c6
commit 7287b5579f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 128 additions and 49 deletions

View File

@ -12,7 +12,8 @@ import org.mozilla.fenix.ext.showToolbar
/**
* Lets the user customize Private browsing options.
*/
class SecretSettingsPreference : PreferenceFragmentCompat() {
class SecretSettingsFragment : PreferenceFragmentCompat() {
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.preferences_debug_settings))

View File

@ -25,13 +25,13 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.crashes.CrashListActivity
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Do
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.about.AboutItemType.LICENSING_INFO
import org.mozilla.fenix.settings.about.AboutItemType.PRIVACY_NOTICE
import org.mozilla.fenix.settings.about.AboutItemType.RIGHTS
import org.mozilla.fenix.settings.about.AboutItemType.SUPPORT
import org.mozilla.fenix.settings.about.AboutItemType.WHATS_NEW
import org.mozilla.fenix.utils.Do
import org.mozilla.fenix.whatsnew.WhatsNew
import org.mozilla.geckoview.BuildConfig as GeckoViewBuildConfig
@ -145,39 +145,39 @@ class AboutFragment : Fragment(), AboutPageListener {
val context = requireContext()
return listOf(
AboutPageItem.Item(
AboutPageItem(
AboutItem.ExternalLink(
WHATS_NEW,
SupportUtils.getWhatsNewUrl(context)
), getString(R.string.about_whats_new, getString(R.string.app_name))
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.ExternalLink(
SUPPORT,
SupportUtils.getSumoURLForTopic(context, SupportUtils.SumoTopic.HELP)
), getString(R.string.about_support)
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.Crashes,
getString(R.string.about_crashes)
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.ExternalLink(
PRIVACY_NOTICE,
SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.PRIVATE_NOTICE)
), getString(R.string.about_privacy_notice)
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.ExternalLink(
RIGHTS,
SupportUtils.getSumoURLForTopic(context, SupportUtils.SumoTopic.YOUR_RIGHTS)
), getString(R.string.about_know_your_rights)
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.ExternalLink(LICENSING_INFO, ABOUT_LICENSE_URL),
getString(R.string.about_licensing_information)
),
AboutPageItem.Item(
AboutPageItem(
AboutItem.Libraries,
getString(R.string.about_other_open_source_libraries)
)

View File

@ -14,6 +14,4 @@ enum class AboutItemType {
WHATS_NEW, SUPPORT, PRIVACY_NOTICE, RIGHTS, LICENSING_INFO
}
sealed class AboutPageItem {
data class Item(val type: AboutItem, val title: String) : AboutPageItem()
}
data class AboutPageItem(val type: AboutItem, val title: String)

View File

@ -20,19 +20,16 @@ class AboutPageAdapter(private val listener: AboutPageListener) :
}
override fun onBindViewHolder(holder: AboutItemViewHolder, position: Int) {
holder.bind(getItem(position) as AboutPageItem.Item)
holder.bind(getItem(position))
}
private object DiffCallback : DiffUtil.ItemCallback<AboutPageItem>() {
override fun areItemsTheSame(oldItem: AboutPageItem, newItem: AboutPageItem) =
oldItem === newItem
oldItem.title == newItem.title
override fun areContentsTheSame(oldItem: AboutPageItem, newItem: AboutPageItem) =
when (oldItem) {
is AboutPageItem.Item ->
newItem is AboutPageItem.Item && oldItem.title == newItem.title
}
oldItem == newItem
}
}

View File

@ -17,7 +17,7 @@ class AboutItemViewHolder(
) : RecyclerView.ViewHolder(view) {
private val title = view.about_item_title
private lateinit var item: AboutPageItem.Item
private lateinit var item: AboutPageItem
init {
itemView.setOnClickListener {
@ -25,7 +25,7 @@ class AboutItemViewHolder(
}
}
fun bind(item: AboutPageItem.Item) {
fun bind(item: AboutPageItem) {
this.item = item
title.text = item.title
}

View File

@ -23,9 +23,8 @@ class LocaleAdapter(private val interactor: LocaleSettingsViewInteractor) :
private var selectedLocale: Locale = Locale.getDefault()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseLocaleViewHolder {
val view =
LayoutInflater.from(parent.context)
.inflate(R.layout.locale_settings_item, parent, false)
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.locale_settings_item, parent, false)
return when (viewType) {
ItemType.DEFAULT.ordinal -> SystemLocaleViewHolder(

View File

@ -10,7 +10,7 @@ import android.view.ViewGroup
import androidx.core.content.ContextCompat.getColor
import androidx.core.view.isVisible
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.quicksettings_website_info.view.*
import kotlinx.android.synthetic.main.quicksettings_website_info.*
import mozilla.components.support.ktx.android.content.getDrawableWithTint
import org.mozilla.fenix.R
@ -19,13 +19,14 @@ import org.mozilla.fenix.R
*
* Currently it does not support any user interaction.
*
* @param containerView [ViewGroup] in which this View will inflate itself.
* @param container [ViewGroup] in which this View will inflate itself.
*/
class WebsiteInfoView(
override val containerView: ViewGroup
container: ViewGroup
) : LayoutContainer {
val view: View = LayoutInflater.from(containerView.context)
.inflate(R.layout.quicksettings_website_info, containerView, true)
override val containerView: View = LayoutInflater.from(container.context)
.inflate(R.layout.quicksettings_website_info, container, true)
/**
* Allows changing what this View displays.
@ -39,25 +40,25 @@ class WebsiteInfoView(
bindCertificateName(state.certificateName)
}
private fun bindUrl(url: String) {
view.url.text = url
private fun bindUrl(websiteUrl: String) {
url.text = websiteUrl
}
private fun bindTitle(title: String) {
view.title.text = title
private fun bindTitle(websiteTitle: String) {
title.text = websiteTitle
}
private fun bindCertificateName(cert: String) {
val certificateLabel = view.context.getString(R.string.certificate_info_verified_by, cert)
view.certificateInfo.text = certificateLabel
view.certificateInfo.isVisible = cert.isNotEmpty()
val certificateLabel = containerView.context.getString(R.string.certificate_info_verified_by, cert)
certificateInfo.text = certificateLabel
certificateInfo.isVisible = cert.isNotEmpty()
}
private fun bindSecurityInfo(uiValues: WebsiteSecurityUiValues) {
val tint = getColor(view.context, uiValues.iconTintRes)
view.securityInfo.setText(uiValues.securityInfoRes)
view.securityInfoIcon.setImageDrawable(
view.context.getDrawableWithTint(uiValues.iconRes, tint)
val tint = getColor(containerView.context, uiValues.iconTintRes)
securityInfo.setText(uiValues.securityInfoRes)
securityInfoIcon.setImageDrawable(
containerView.context.getDrawableWithTint(uiValues.iconRes, tint)
)
}
}

View File

@ -544,7 +544,7 @@
android:name="org.mozilla.fenix.settings.about.AboutFragment"/>
<fragment
android:id="@+id/secretSettingsPreference"
android:name="org.mozilla.fenix.settings.SecretSettingsPreference"
android:name="org.mozilla.fenix.settings.SecretSettingsFragment"
android:label="@string/preferences_debug_settings" />
<fragment
android:id="@+id/crashReporterFragment"

View File

@ -17,20 +17,21 @@ import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.settings.about.viewholders.AboutItemViewHolder
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.settings.about.viewholders.AboutItemViewHolder
@RunWith(FenixRobolectricTestRunner::class)
class AboutPageAdapterTest {
private var aboutList: List<AboutPageItem> =
mutableListOf(
AboutPageItem.Item(
private val aboutList: List<AboutPageItem> =
listOf(
AboutPageItem(
AboutItem.ExternalLink(
AboutItemType.WHATS_NEW,
"https://mozilla.org"
), "Libraries"
),
AboutPageItem.Item(AboutItem.Libraries, "Libraries")
AboutPageItem(AboutItem.Libraries, "Libraries"),
AboutPageItem(AboutItem.Crashes, "Crashes")
)
private val listener: AboutPageListener = mockk(relaxed = true)
@ -47,7 +48,7 @@ class AboutPageAdapterTest {
adapter.submitList(aboutList)
assertEquals(2, adapter.itemCount)
assertEquals(3, adapter.itemCount)
}
@Test
@ -78,6 +79,6 @@ class AboutPageAdapterTest {
adapter.submitList(aboutList)
adapter.bindViewHolder(viewHolder, 1)
verify { viewHolder.bind(aboutList[1] as AboutPageItem.Item) }
verify { viewHolder.bind(aboutList[1]) }
}
}

View File

@ -22,7 +22,7 @@ import org.mozilla.fenix.settings.about.AboutPageListener
@RunWith(FenixRobolectricTestRunner::class)
class AboutItemViewHolderTest {
private val item = AboutPageItem.Item(AboutItem.Libraries, "Libraries")
private val item = AboutPageItem(AboutItem.Libraries, "Libraries")
private lateinit var view: View
private lateinit var listener: AboutPageListener

View File

@ -6,10 +6,13 @@ package org.mozilla.fenix.settings.account
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mozilla.fenix.R
@ -34,6 +37,7 @@ class AccountSettingsInteractorTest {
@Test
fun onChangeDeviceName() {
val store: AccountSettingsFragmentStore = mockk(relaxed = true)
val invalidNameResponse = mockk<() -> Unit>(relaxed = true)
val interactor = AccountSettingsInteractor(
mockk(),
@ -42,9 +46,28 @@ class AccountSettingsInteractorTest {
store
)
interactor.onChangeDeviceName("New Name") {}
assertTrue(interactor.onChangeDeviceName("New Name", invalidNameResponse))
verify { store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName("New Name")) }
verify { invalidNameResponse wasNot Called }
}
@Test
fun onChangeDeviceNameSyncFalse() {
val store: AccountSettingsFragmentStore = mockk(relaxed = true)
val invalidNameResponse = mockk<() -> Unit>(relaxed = true)
val interactor = AccountSettingsInteractor(
mockk(),
mockk(),
{ false },
store
)
assertFalse(interactor.onChangeDeviceName("New Name", invalidNameResponse))
verify { store wasNot Called }
verify { invalidNameResponse() }
}
@Test

View File

@ -0,0 +1,59 @@
/* 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.quicksettings
import android.widget.FrameLayout
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.library_site_item.title
import kotlinx.android.synthetic.main.library_site_item.url
import kotlinx.android.synthetic.main.quicksettings_website_info.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class WebsiteInfoViewTest {
private lateinit var view: WebsiteInfoView
@Before
fun setup() {
view = WebsiteInfoView(FrameLayout(testContext))
}
@Test
fun bindUrlAndTitle() {
view.update(WebsiteInfoState(
websiteUrl = "https://mozilla.org",
websiteTitle = "Mozilla",
websiteSecurityUiValues = WebsiteSecurityUiValues.SECURE,
certificateName = ""
))
assertEquals("https://mozilla.org", view.url.text)
assertEquals("Mozilla", view.title.text)
assertEquals("Secure Connection", view.securityInfo.text)
assertFalse(view.certificateInfo.isVisible)
}
@Test
fun bindCert() {
view.update(WebsiteInfoState(
websiteUrl = "https://mozilla.org",
websiteTitle = "Mozilla",
websiteSecurityUiValues = WebsiteSecurityUiValues.INSECURE,
certificateName = "Certificate"
))
assertEquals("Insecure Connection", view.securityInfo.text)
assertEquals("Verified By: Certificate", view.certificateInfo.text)
assertTrue(view.certificateInfo.isVisible)
}
}