diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManager.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManager.kt index fc69e6cd1837..5f5df372abb5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManager.kt @@ -11,12 +11,17 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.TRAFFIC +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig import javax.inject.Inject const val SELECTED_SECTION_KEY = "SELECTED_STATS_SECTION_KEY" class SelectedSectionManager -@Inject constructor(private val sharedPrefs: SharedPreferences) { +@Inject constructor( + private val sharedPrefs: SharedPreferences, + private val statsTrafficTabFeatureConfig: StatsTrafficTabFeatureConfig +) { private val _liveSelectedSection = MutableLiveData() val liveSelectedSection: LiveData get() { @@ -28,7 +33,8 @@ class SelectedSectionManager } fun getSelectedSection(): StatsSection { - val value = sharedPrefs.getString(SELECTED_SECTION_KEY, INSIGHTS.name) + val defaultValue = if (statsTrafficTabFeatureConfig.isEnabled()) TRAFFIC else INSIGHTS + val value = sharedPrefs.getString(SELECTED_SECTION_KEY, defaultValue.name) return value?.let { StatsSection.valueOf(value) } ?: INSIGHTS } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManagerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManagerTest.kt index e69304a93053..5de19d62b157 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManagerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/utils/SelectedSectionManagerTest.kt @@ -13,9 +13,13 @@ import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig @ExperimentalCoroutinesApi class SelectedSectionManagerTest : BaseUnitTest() { + @Mock + private lateinit var trafficTabFeatureConfig: StatsTrafficTabFeatureConfig + @Mock lateinit var sharedPreferences: SharedPreferences @@ -25,7 +29,7 @@ class SelectedSectionManagerTest : BaseUnitTest() { @Before fun setUp() { - selectedSectionManager = SelectedSectionManager(sharedPreferences) + selectedSectionManager = SelectedSectionManager(sharedPreferences, trafficTabFeatureConfig) whenever(sharedPreferences.edit()).thenReturn(sharedPreferencesEditor) }