For #20919 quit the after removing a study.

upstream-sync
Arturo Mejia 3 years ago committed by mergify[bot]
parent bf5b4a5655
commit d3019986a4

@ -5,12 +5,15 @@
package org.mozilla.fenix.settings.studies
import android.annotation.SuppressLint
import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
@ -117,10 +120,32 @@ class StudiesAdapter(
holder.summaryView.text = study.userFacingDescription
holder.deleteButton.setOnClickListener {
studiesDelegate.onRemoveButtonClicked(study)
showDeleteDialog(holder.titleView.context, study)
}
}
@VisibleForTesting
internal fun showDeleteDialog(context: Context, study: EnrolledExperiment): AlertDialog {
val builder = AlertDialog.Builder(context)
.setPositiveButton(
R.string.studies_restart_dialog_ok
) { dialog, _ ->
studiesDelegate.onRemoveButtonClicked(study)
dialog.dismiss()
}
.setNegativeButton(
R.string.studies_restart_dialog_cancel
) { dialog: DialogInterface, _ ->
dialog.dismiss()
}
.setTitle(R.string.preference_experiments_2)
.setMessage(R.string.studies_restart_app)
.setCancelable(false)
val alertDialog: AlertDialog = builder.create()
alertDialog.show()
return alertDialog
}
internal fun createListWithSections(studies: List<EnrolledExperiment>): List<Any> {
val itemsWithSections = ArrayList<Any>()
val activeStudies = ArrayList<EnrolledExperiment>()

@ -4,10 +4,12 @@
package org.mozilla.fenix.settings.studies
import androidx.annotation.VisibleForTesting
import mozilla.components.service.nimbus.NimbusApi
import org.mozilla.experiments.nimbus.internal.EnrolledExperiment
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import kotlin.system.exitProcess
interface StudiesInteractor {
/**
@ -35,5 +37,11 @@ class DefaultStudiesInteractor(
override fun removeStudy(experiment: EnrolledExperiment) {
experiments.optOut(experiment.slug)
killApplication()
}
@VisibleForTesting
internal fun killApplication() {
exitProcess(0)
}
}

@ -623,6 +623,12 @@
<string name="studies_description">Firefox may install and run studies from time to time.</string>
<!-- Learn more link for studies, links to an article for more information about studies. -->
<string name="studies_learn_more">Learn more</string>
<!-- Dialog message shown after removing a study -->
<string name="studies_restart_app">The application will quit to apply changes</string>
<!-- Dialog button to confirm the removing a study. -->
<string name="studies_restart_dialog_ok">OK</string>
<!-- Dialog button text for canceling removing a study. -->
<string name="studies_restart_dialog_cancel">Cancel</string>
<!-- Sessions -->
<!-- Title for the list of tabs -->

@ -7,7 +7,10 @@ package org.mozilla.fenix.settings.studies
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.service.nimbus.NimbusApi
@ -30,7 +33,7 @@ class DefaultStudiesInteractorTest {
@Before
fun setup() {
MockKAnnotations.init(this)
interactor = DefaultStudiesInteractor(activity, experiments)
interactor = spyk(DefaultStudiesInteractor(activity, experiments))
}
@Test
@ -48,6 +51,7 @@ class DefaultStudiesInteractorTest {
val experiment = mockk<EnrolledExperiment>(relaxed = true)
every { experiment.slug } returns "slug"
every { interactor.killApplication() } just runs
interactor.removeStudy(experiment)

@ -16,9 +16,9 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import io.mockk.verify
import junit.framework.TestCase.assertTrue
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.support.test.robolectric.testContext
import org.junit.Before
@ -69,7 +69,7 @@ class StudiesAdapterTest {
fun `WHEN bindStudy THEN bind the study information`() {
val holder = mockk<StudyViewHolder>()
val study = mockk<EnrolledExperiment>()
val titleView = mockk<TextView>(relaxed = true)
val titleView = spyk(TextView(testContext))
val summaryView = mockk<TextView>(relaxed = true)
val deleteButton = spyk(MaterialButton(testContext))
@ -82,6 +82,8 @@ class StudiesAdapterTest {
adapter = spyk(StudiesAdapter(delegate, listOf(study), false))
every { adapter.showDeleteDialog(any(), any()) } returns mockk()
adapter.bindStudy(holder, study)
verify {
@ -92,7 +94,7 @@ class StudiesAdapterTest {
deleteButton.performClick()
verify {
delegate.onRemoveButtonClicked(study)
adapter.showDeleteDialog(any(), any())
}
}

Loading…
Cancel
Save