mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] Filter messaging experiments from the Studies screen
This commit is contained in:
parent
1894c0528d
commit
bab0149d64
@ -16,6 +16,19 @@ import org.mozilla.fenix.nimbus.ControlMessageBehavior
|
||||
import org.mozilla.fenix.nimbus.Messaging
|
||||
import org.mozilla.fenix.nimbus.StyleData
|
||||
|
||||
/**
|
||||
* This ID must match the name given in the `nimbus.fml.yaml` file, which
|
||||
* itself generates the classname for [org.mozilla.fenix.nimbus.Messaging].
|
||||
*
|
||||
* If that ever changes, it should also change here.
|
||||
*
|
||||
* This constant is the id for the messaging feature (the Nimbus feature). We declare it here
|
||||
* so as to afford the best chance of it being changed if a rename operation is needed.
|
||||
*
|
||||
* It is used in the Studies view, to filter out any experiments which only use a messaging surface.
|
||||
*/
|
||||
const val MESSAGING_FEATURE_ID = "messaging"
|
||||
|
||||
/**
|
||||
* Provides messages from [messagingFeature] and combine with the metadata store on [metadataStorage].
|
||||
*/
|
||||
|
@ -20,6 +20,7 @@ import androidx.recyclerview.widget.ListAdapter
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import org.mozilla.experiments.nimbus.internal.EnrolledExperiment
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.gleanplumb.MESSAGING_FEATURE_ID
|
||||
import org.mozilla.fenix.settings.studies.CustomViewHolder.SectionViewHolder
|
||||
import org.mozilla.fenix.settings.studies.CustomViewHolder.StudyViewHolder
|
||||
|
||||
@ -150,7 +151,7 @@ class StudiesAdapter(
|
||||
val itemsWithSections = ArrayList<Any>()
|
||||
val activeStudies = ArrayList<EnrolledExperiment>()
|
||||
|
||||
activeStudies.addAll(studies)
|
||||
activeStudies.addAll(filterStudies(studies))
|
||||
|
||||
if (activeStudies.isNotEmpty()) {
|
||||
itemsWithSections.add(Section(R.string.studies_active, true))
|
||||
@ -160,6 +161,14 @@ class StudiesAdapter(
|
||||
return itemsWithSections
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out studies which only affect the messaging feature.
|
||||
*/
|
||||
private fun filterStudies(studies: List<EnrolledExperiment>) =
|
||||
studies.filterNot {
|
||||
it.featureIds.size == 1 && it.featureIds.contains(MESSAGING_FEATURE_ID)
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal data class Section(@StringRes val title: Int, val visibleDivider: Boolean = true)
|
||||
|
||||
|
@ -25,6 +25,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.experiments.nimbus.internal.EnrolledExperiment
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.gleanplumb.MESSAGING_FEATURE_ID
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.settings.studies.CustomViewHolder.SectionViewHolder
|
||||
import org.mozilla.fenix.settings.studies.CustomViewHolder.StudyViewHolder
|
||||
@ -131,4 +132,21 @@ class StudiesAdapterTest {
|
||||
assertTrue(list[0] is Section)
|
||||
assertTrue(list[1] is EnrolledExperiment)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN calling createListWithSections THEN returns the section + experiments, filtering messages`() {
|
||||
val study = mockk<EnrolledExperiment>()
|
||||
every { study.slug } returns "slug"
|
||||
|
||||
val message = mockk<EnrolledExperiment>()
|
||||
every { message.featureIds } returns listOf(MESSAGING_FEATURE_ID)
|
||||
|
||||
adapter = spyk(StudiesAdapter(delegate, listOf(study, message), false))
|
||||
|
||||
val list = adapter.createListWithSections(listOf(study))
|
||||
|
||||
assertEquals(2, list.size)
|
||||
assertTrue(list[0] is Section)
|
||||
assertTrue(list[1] is EnrolledExperiment)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user