Skip to content

Commit

Permalink
Added KDocs for annotations and parameter constants
Browse files Browse the repository at this point in the history
Yet to add for override platform parameters.
  • Loading branch information
Rd4dev committed Jan 7, 2025
1 parent f490edb commit 6499245
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,38 @@ class PlatformParameterModule {
private val overriddenFeatureFlags = mutableMapOf<FeatureFlag, Any>()
private val overriddenPlatformParameters = mutableMapOf<PlatformParameter, Any>()

/**
* Overrides the value of the specified feature flag with a new value for testing.
*
* @param name The feature flag to override.
* @param value The new value to assign to the feature flag for testing.
*/
fun overrideFeatureFlags(name: FeatureFlag, value: Any) {
println("Name: $name, value: $value")
overriddenFeatureFlags[name] = value
}

/**
* Overrides the value of the specified platform parameter with a new value for testing.
*
* @param name The platform parameter to override.
* @param value The new value to assign to the platform parameter for testing.
*/
fun overridePlatformParameters(name: PlatformParameter, value: Any) {
println("Name: $name, value: $value")
overriddenPlatformParameters[name] = value
}

/**
* Resets the specified feature flag to its default value by removing it from the overridden map.
*
* @param name The feature flag to reset.
*/
fun resetFeatureFlagToDefault(name: FeatureFlag) {
println("Resetting $name")
overriddenFeatureFlags.remove(name)
}

/**
* Clears all overridden feature flags and platform parameters.
*/
fun clearAllParameterOverrides() {
overriddenFeatureFlags.clear()
overriddenPlatformParameters.clear()
Expand Down
24 changes: 24 additions & 0 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,14 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/DisableAccessibilityChecks.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/DisableFeatureFlag.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/EnableFeatureFlag.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/FakeAnalyticsEventLogger.kt"
source_file_is_incompatible_with_code_coverage: true
Expand Down Expand Up @@ -3990,6 +3998,22 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/OppiaTestRunner.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/OverrideBoolParameter.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/OverrideIntParameter.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/OverrideStringParameter.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/ResetFeatureFlagToDefault.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/RichTextViewMatcher.kt"
test_file_not_required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package org.oppia.android.testing

import org.oppia.android.util.platformparameter.FeatureFlag

/**
* Repeatable test class or method annotation for disabling the feature flag for tests of the
* class or the specific method may run on. The feature flag names are provided by the
* FeatureFlagConstants.kt.
*
* Note that this annotation only works if the test also has an [OppiaTestRule] hooked up.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Repeatable
annotation class DisableFeatureFlag(val name: FeatureFlag)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package org.oppia.android.testing

import org.oppia.android.util.platformparameter.FeatureFlag

/**
* Repeatable test class or method annotation for enabling the feature flag for tests of the
* class or the specific method may run on. The feature flag names are provided by the
* FeatureFlagConstants.kt.
*
* Note that this annotation only works if the test also has an [OppiaTestRule] hooked up.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Repeatable
annotation class EnableFeatureFlag(val name: FeatureFlag)
14 changes: 2 additions & 12 deletions testing/src/main/java/org/oppia/android/testing/OppiaTestRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,14 @@ class OppiaTestRule : TestRule {
description?.annotations, ResetFeatureFlagToDefault::class.java
)

val resetParameterToDefault = extractParametersAndFeatureFlags(
description?.annotations, ResetParameterToDefault::class.java
)

try {
applyOverrides(
enabledFeatureFlags,
disabledFeatureFlags,
overriddenBoolParameters,
overriddenIntParameters,
overriddenStringParameters,
resetFeatureFlagToDefault,
resetParameterToDefault
resetFeatureFlagToDefault
)

when {
Expand Down Expand Up @@ -132,8 +127,7 @@ class OppiaTestRule : TestRule {
overriddenBoolParameters: List<OverrideBoolParameter>?,
overriddenIntParameters: List<OverrideIntParameter>?,
overriddenStringParameters: List<OverrideStringParameter>?,
resetFeatureFlagToDefault: List<ResetFeatureFlagToDefault>?,
resetParameterToDefault: List<ResetParameterToDefault>?
resetFeatureFlagToDefault: List<ResetFeatureFlagToDefault>?
) {
enabledFeatureFlags?.forEach { flag ->
PlatformParameterModule.overrideFeatureFlags(flag.name, true)
Expand All @@ -156,10 +150,6 @@ class OppiaTestRule : TestRule {
overriddenStringParameters?.forEach { _ ->
// PlatformParameterModule.overrideParameter(overriddenValue.name, overriddenValue.value)
}

resetParameterToDefault?.forEach { _ ->
// PlatformParameterModule.resetParameterToDefault(resetParameter.name)
}
}

private fun getCurrentPlatform(): TestPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package org.oppia.android.testing

import org.oppia.android.util.platformparameter.FeatureFlag

/**
* Repeatable test method annotation for resetting the feature flag for tests of the
* specific method may run on. The feature flag names are provided by the
* FeatureFlagConstants.kt.
*
* Note that this annotation only works if the test also has an [OppiaTestRule] hooked up.
*/
@Target(AnnotationTarget.FUNCTION)
@Repeatable
annotation class ResetFeatureFlagToDefault(val name: FeatureFlag)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,45 @@ package org.oppia.android.util.platformparameter

import javax.inject.Qualifier

/** Represents all the feature flag names. */
enum class FeatureFlag {
/** Corresponds to downloads support. */
DOWNLOADS_SUPPORT,

/** Corresponds to extra topics tab UI. */
EXTRA_TOPIC_TABS_UI,

/** Corresponds to learner study related analytics logging. */
LEARNER_STUDY_ANALYTICS,

/** Corresponds to allow learners to quickly switch between content languages. */
FAST_LANGUAGE_SWITCHING_IN_LESSON,

/** Corresponds to generating and logging learner study IDs. */
LOGGING_LEARNER_STUDY_IDS,

/** Corresponds to edit accounts options. */
EDIT_ACCOUNTS_OPTIONS_UI,

/** Corresponds to record performance metrics. */
ENABLE_PERFORMANCE_METRICS_COLLECTION,

/** Corresponds to spotlight UI. */
SPOTLIGHT_UI,

/** Corresponds to retaining input interaction state across configuration changes. */
INTERACTION_CONFIG_CHANGE_STATE_RETENTION,

/** Corresponds to app and OS deprecation. */
APP_AND_OS_DEPRECATION,

/** Corresponds to NPS survey. */
ENABLE_NPS_SURVEY,

/** Corresponds to new onboarding flow. */
ENABLE_ONBOARDING_FLOW_V2,

/** Corresponds to new multiple classrooms. */
ENABLE_MULTIPLE_CLASSROOMS
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,42 @@ package org.oppia.android.util.platformparameter

import javax.inject.Qualifier

/** Represents all the platform parameter names. */
enum class PlatformParameter {
/** Corresponds to automatically updating topics. */
AUTOMATIC_UPDATE_TOPIC_SETTING,

/** Corresponds to visibility of splash screen welcome message. */
SPLASH_SCREEN_WELCOME_MSG,

/** Corresponds to time period in hours. */
SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS,

/** Corresponds to cache LaTeX rendering using Glide. */
CACHE_LATEX_RENDERING,

/** Corresponds to uploading time interval of previously recorded performance metrics in minutes. */
PERFORMANCE_METRICS_COLLECTION_UPLOAD_TIME_INTERVAL_IN_MINUTES,

/** Corresponds to recording time interval of high frequent performance metrics collection in minutes. */
PERFORMANCE_METRICS_COLLECTION_HIGH_FREQUENCY_TIME_INTERVAL_IN_MINUTES,

/** Corresponds to recording time interval of low frequent performance metrics collection in minutes. */
PERFORMANCE_METRICS_COLLECTION_LOW_FREQUENCY_TIME_INTERVAL_IN_MINUTES,

/** Corresponds to version code of latest app available soft update. */
OPTIONAL_APP_UPDATE_VERSION_CODE,

/** Corresponds to version code of latest app available forced update. */
FORCED_APP_UPDATE_VERSION_CODE,

/** Corresponds to integer indicating lowest supported Android API level. */
LOWEST_SUPPORTED_API_LEVEL,

/** Corresponds to time interval of showing subsequent NPS surveys in days. */
NPS_SURVEY_GRACE_PERIOD_IN_DAYS,

/** Corresponds to minimum learning time in a topic in minutes. */
NPS_SURVEY_MINIMUM_AGGREGATE_LEARNING_TIME_IN_A_TOPIC_IN_MINUTES
}

Expand Down

0 comments on commit 6499245

Please sign in to comment.