Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes part of #4302 - Introducing a JUnit annotation & rule for overriding Platform Parameters and Feature Flags #5565

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Done with app module test migrations
  • Loading branch information
Rd4dev committed Dec 12, 2024
commit 56460a974de9d578f95c772289e13d1322f4f048
Original file line number Diff line number Diff line change
@@ -83,7 +83,6 @@ import org.oppia.android.testing.FakeAnalyticsEventLogger
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestCoroutineDispatchers
import org.oppia.android.testing.threading.TestDispatcherModule
@@ -107,6 +106,9 @@ import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton
import org.oppia.android.domain.platformparameter.PlatformParameterModule
import org.oppia.android.testing.EnableFeatureFlag
import org.oppia.android.util.platformparameter.FeatureFlag

@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@@ -174,8 +176,9 @@ class ExplorationActivityLocalTest {
}

@Test
@EnableFeatureFlag(FeatureFlag.ENABLE_NPS_SURVEY)
fun testExplorationActivity_closeExploration_surveyGatingCriteriaMet_showsSurveyPopup() {
setUpTestWithNpsEnabled()
setUpTestApplicationComponent()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeMs(afternoonUtcTimestampMillis)

@@ -227,8 +230,9 @@ class ExplorationActivityLocalTest {
}

@Test
@EnableFeatureFlag(FeatureFlag.ENABLE_NPS_SURVEY)
fun testExplorationActivity_closeExploration_surveyGatingCriteriaNotMet_noSurveyPopup() {
setUpTestWithNpsEnabled()
setUpTestApplicationComponent()
getApplicationDependencies(
internalProfileId,
TEST_CLASSROOM_ID_0,
@@ -273,8 +277,9 @@ class ExplorationActivityLocalTest {
}

@Test
@EnableFeatureFlag(FeatureFlag.ENABLE_NPS_SURVEY)
fun testExplorationActivity_updateGatingProvider_surveyGatingCriteriaMet_keepsSurveyDialog() {
setUpTestWithNpsEnabled()
setUpTestApplicationComponent()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeMs(afternoonUtcTimestampMillis)

@@ -337,11 +342,6 @@ class ExplorationActivityLocalTest {
}
}

private fun setUpTestWithNpsEnabled() {
TestPlatformParameterModule.forceEnableNpsSurvey(true)
setUpTestApplicationComponent()
}

private fun markAllSpotlightsSeen() {
markSpotlightSeen(Spotlight.FeatureCase.LESSONS_BACK_BUTTON)
markSpotlightSeen(Spotlight.FeatureCase.VOICEOVER_PLAY_ICON)
@@ -405,7 +405,7 @@ class ExplorationActivityLocalTest {
@Component(
modules = [
TestDispatcherModule::class, ApplicationModule::class, RobolectricModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
Original file line number Diff line number Diff line change
@@ -148,7 +148,6 @@ import org.oppia.android.testing.espresso.KonfettiViewMatcher.Companion.hasExpec
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.junit.DefineAppLanguageLocaleContext
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.profile.ProfileTestHelper
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.CoroutineExecutorService
@@ -180,6 +179,7 @@ import java.util.Locale
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
import org.oppia.android.domain.platformparameter.PlatformParameterModule

/**
* Tests for [StateFragment] that can only be run locally, e.g. using Robolectric, and not on an
@@ -2913,7 +2913,7 @@ class StateFragmentLocalTest {
@Component(
modules = [
TestModule::class, TestDispatcherModule::class, ApplicationModule::class,
RobolectricModule::class, TestPlatformParameterModule::class,
RobolectricModule::class, PlatformParameterModule::class,
PlatformParameterSingletonModule::class, LoggerModule::class, ContinueModule::class,
FractionInputModule::class, ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
Original file line number Diff line number Diff line change
@@ -69,7 +69,6 @@ import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.profile.ProfileTestHelper
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestCoroutineDispatchers
@@ -88,11 +87,11 @@ import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule
import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule
import org.oppia.android.util.parser.image.GlideImageLoaderModule
import org.oppia.android.util.parser.image.ImageParsingModule
import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton
import org.oppia.android.domain.platformparameter.PlatformParameterModule

@RunWith(AndroidJUnit4::class)
@Config(application = OptionsFragmentTest.TestApplication::class, qualifiers = "sw600dp")
@@ -109,9 +108,6 @@ class OptionsFragmentTest {

@Before
fun setUp() {
TestPlatformParameterModule.forceEnableEditAccountsOptionsUi(
ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
)
setUpTestApplicationComponent()
testCoroutineDispatchers.registerIdlingResource()
profileTestHelper.initializeProfiles()
@@ -219,7 +215,7 @@ class OptionsFragmentTest {
@Component(
modules = [
TestDispatcherModule::class, ApplicationModule::class, RobolectricModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ import org.oppia.android.testing.FakeAnalyticsEventLogger
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestCoroutineDispatchers
import org.oppia.android.testing.threading.TestDispatcherModule
@@ -84,6 +83,10 @@ import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton
import org.oppia.android.domain.platformparameter.PlatformParameterModule
import org.oppia.android.testing.EnableFeatureFlag
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.util.platformparameter.FeatureFlag

private const val TEST_CLASSROOM_ID = "test_classroom_id_1"
private const val TEST_TOPIC_ID = "GJ2rLXRKD5hw"
@@ -96,6 +99,7 @@ private const val TEST_TOPIC_ID = "GJ2rLXRKD5hw"
)
class TopicInfoFragmentLocalTest {
@get:Rule val initializeDefaultLocaleRule = InitializeDefaultLocaleRule()
@get:Rule val oppiaTestRule = OppiaTestRule()

@Inject lateinit var fakeAnalyticsEventLogger: FakeAnalyticsEventLogger
@Inject lateinit var testCoroutineDispatchers: TestCoroutineDispatchers
@@ -108,8 +112,8 @@ class TopicInfoFragmentLocalTest {
}

@Test
@EnableFeatureFlag(FeatureFlag.EXTRA_TOPIC_TABS_UI)
fun testTopicInfoFragment_onLaunch_logsEvent() {
TestPlatformParameterModule.forceEnableExtraTopicTabsUi(true)
launchTopicActivityIntent(internalProfileId, TEST_CLASSROOM_ID, TEST_TOPIC_ID).use {
testCoroutineDispatchers.runCurrent()
val event = fakeAnalyticsEventLogger.getMostRecentEvent()
@@ -144,7 +148,7 @@ class TopicInfoFragmentLocalTest {
@Component(
modules = [
TestDispatcherModule::class, ApplicationModule::class, RobolectricModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
Original file line number Diff line number Diff line change
@@ -330,10 +330,10 @@ class PlatformParameterModule {
fun provideEnableNpsSurvey(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Boolean> {
return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY)
?: PlatformParameterValue.createDefaultParameter(
ENABLE_NPS_SURVEY_DEFAULT_VALUE
)
return overriddenFeatureFlags[FeatureFlag.ENABLE_NPS_SURVEY]?.let {
PlatformParameterValue.createDefaultParameter(it as Boolean)
} ?: platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY)
?: PlatformParameterValue.createDefaultParameter(ENABLE_NPS_SURVEY_DEFAULT_VALUE)
}

@Provides