From bab0149d647d427954cecf884b4d321cb5fb012e Mon Sep 17 00:00:00 2001 From: James Hugman Date: Wed, 18 May 2022 16:45:02 +0100 Subject: [PATCH] [fenix] Filter messaging experiments from the Studies screen --- .../fenix/gleanplumb/NimbusMessagingStorage.kt | 13 +++++++++++++ .../fenix/settings/studies/StudiesAdapter.kt | 11 ++++++++++- .../settings/studies/StudiesAdapterTest.kt | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/gleanplumb/NimbusMessagingStorage.kt b/app/src/main/java/org/mozilla/fenix/gleanplumb/NimbusMessagingStorage.kt index 4205490594..d2458d8824 100644 --- a/app/src/main/java/org/mozilla/fenix/gleanplumb/NimbusMessagingStorage.kt +++ b/app/src/main/java/org/mozilla/fenix/gleanplumb/NimbusMessagingStorage.kt @@ -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]. */ diff --git a/app/src/main/java/org/mozilla/fenix/settings/studies/StudiesAdapter.kt b/app/src/main/java/org/mozilla/fenix/settings/studies/StudiesAdapter.kt index d08a1762d7..40c1467a79 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/studies/StudiesAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/studies/StudiesAdapter.kt @@ -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() val activeStudies = ArrayList() - 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) = + 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) diff --git a/app/src/test/java/org/mozilla/fenix/settings/studies/StudiesAdapterTest.kt b/app/src/test/java/org/mozilla/fenix/settings/studies/StudiesAdapterTest.kt index 547184afbb..0fa5a09e80 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/studies/StudiesAdapterTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/studies/StudiesAdapterTest.kt @@ -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() + every { study.slug } returns "slug" + + val message = mockk() + 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) + } }