-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Label profile list activity added * Review Changes
- Loading branch information
Showing
2 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileListActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package org.oppia.android.app.settings.profile | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.rule.ActivityTestRule | ||
import com.google.common.truth.Truth | ||
import dagger.Component | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.oppia.android.R | ||
import org.oppia.android.app.activity.ActivityComponent | ||
import org.oppia.android.app.application.ActivityComponentFactory | ||
import org.oppia.android.app.application.ApplicationComponent | ||
import org.oppia.android.app.application.ApplicationInjector | ||
import org.oppia.android.app.application.ApplicationInjectorProvider | ||
import org.oppia.android.app.application.ApplicationModule | ||
import org.oppia.android.app.application.ApplicationStartupListenerModule | ||
import org.oppia.android.app.player.state.hintsandsolution.HintsAndSolutionConfigModule | ||
import org.oppia.android.app.shim.ViewBindingShimModule | ||
import org.oppia.android.app.topic.PracticeTabModule | ||
import org.oppia.android.domain.classify.InteractionsModule | ||
import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule | ||
import org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputModule | ||
import org.oppia.android.domain.classify.rules.fractioninput.FractionInputModule | ||
import org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputModule | ||
import org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputModule | ||
import org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputModule | ||
import org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsRuleModule | ||
import org.oppia.android.domain.classify.rules.numericinput.NumericInputRuleModule | ||
import org.oppia.android.domain.classify.rules.ratioinput.RatioInputModule | ||
import org.oppia.android.domain.classify.rules.textinput.TextInputRuleModule | ||
import org.oppia.android.domain.onboarding.ExpirationMetaDataRetrieverModule | ||
import org.oppia.android.domain.oppialogger.LogStorageModule | ||
import org.oppia.android.domain.oppialogger.loguploader.LogUploadWorkerModule | ||
import org.oppia.android.domain.oppialogger.loguploader.WorkManagerConfigurationModule | ||
import org.oppia.android.domain.question.QuestionModule | ||
import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule | ||
import org.oppia.android.testing.TestLogReportingModule | ||
import org.oppia.android.testing.robolectric.RobolectricModule | ||
import org.oppia.android.testing.threading.TestDispatcherModule | ||
import org.oppia.android.testing.time.FakeOppiaClockModule | ||
import org.oppia.android.util.accessibility.AccessibilityTestModule | ||
import org.oppia.android.util.caching.testing.CachingTestModule | ||
import org.oppia.android.util.gcsresource.GcsResourceModule | ||
import org.oppia.android.util.logging.LoggerModule | ||
import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule | ||
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.robolectric.annotation.Config | ||
import org.robolectric.annotation.LooperMode | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** Tests for [ProfileListActivity]. */ | ||
@RunWith(AndroidJUnit4::class) | ||
@LooperMode(LooperMode.Mode.PAUSED) | ||
@Config(application = ProfileListActivityTest.TestApplication::class, qualifiers = "port-xxhdpi") | ||
class ProfileListActivityTest { | ||
|
||
@get:Rule | ||
val activityTestRule: ActivityTestRule<ProfileListActivity> = ActivityTestRule( | ||
ProfileListActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false | ||
) | ||
|
||
@Inject | ||
lateinit var context: Context | ||
|
||
@Before | ||
fun setUp() { | ||
setUpTestApplicationComponent() | ||
} | ||
|
||
@Test | ||
fun testProfileListActivity_hasCorrectActivityLabel() { | ||
activityTestRule.launchActivity(createProfileListActivityIntent()) | ||
val title = activityTestRule.activity.title | ||
|
||
// Verify that the activity label is correct as a proxy to verify TalkBack will announce the | ||
// correct string when it's read out. | ||
Truth.assertThat(title).isEqualTo(context.getString(R.string.profile_list_activity_title)) | ||
} | ||
|
||
private fun setUpTestApplicationComponent() { | ||
ApplicationProvider.getApplicationContext<TestApplication>().inject(this) | ||
} | ||
|
||
private fun createProfileListActivityIntent(): Intent { | ||
return ProfileListActivity.createProfileListActivityIntent( | ||
ApplicationProvider.getApplicationContext() | ||
) | ||
} | ||
|
||
// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them. | ||
@Singleton | ||
@Component( | ||
modules = [ | ||
RobolectricModule::class, | ||
TestDispatcherModule::class, ApplicationModule::class, | ||
LoggerModule::class, ContinueModule::class, FractionInputModule::class, | ||
ItemSelectionInputModule::class, MultipleChoiceInputModule::class, | ||
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class, | ||
DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class, | ||
GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class, | ||
HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class, | ||
AccessibilityTestModule::class, LogStorageModule::class, CachingTestModule::class, | ||
PrimeTopicAssetsControllerModule::class, ExpirationMetaDataRetrieverModule::class, | ||
ViewBindingShimModule::class, RatioInputModule::class, | ||
ApplicationStartupListenerModule::class, LogUploadWorkerModule::class, | ||
WorkManagerConfigurationModule::class, HintsAndSolutionConfigModule::class, | ||
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class | ||
] | ||
) | ||
interface TestApplicationComponent : ApplicationComponent { | ||
@Component.Builder | ||
interface Builder : ApplicationComponent.Builder | ||
|
||
fun inject(profileListActivityTest: ProfileListActivityTest) | ||
} | ||
|
||
class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { | ||
private val component: TestApplicationComponent by lazy { | ||
DaggerProfileListActivityTest_TestApplicationComponent.builder() | ||
.setApplication(this) | ||
.build() as TestApplicationComponent | ||
} | ||
|
||
fun inject(profileListActivityTest: ProfileListActivityTest) { | ||
component.inject(profileListActivityTest) | ||
} | ||
|
||
override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { | ||
return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() | ||
} | ||
|
||
override fun getApplicationInjector(): ApplicationInjector = component | ||
} | ||
} |