From 2b40d742656f2357cb5a05083114625d1fad8598 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Tue, 16 Mar 2021 15:58:59 +0530 Subject: [PATCH 1/9] added label for profile rename activity --- app/src/main/AndroidManifest.xml | 3 ++- app/src/main/res/values/strings.xml | 1 + .../profile/ProfileRenameActivityTest.kt | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 527ddca3034..7d015abdc0a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -99,7 +99,8 @@ android:theme="@style/OppiaThemeWithoutActionBar" /> + android:theme="@style/OppiaThemeWithoutActionBar" + android:label="@string/profile_rename_activity_label"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 111f51b8401..bfe37be397e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -299,6 +299,7 @@ Rename Profile New Name save + Profile Rename Activity Reset PIN Enter a new PIN for the user to enter when accessing their profile. diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 9e5d4d5cb2c..9207deb4a2f 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -22,7 +22,9 @@ import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule import com.google.android.material.textfield.TextInputLayout +import com.google.common.truth.Truth.assertThat import dagger.Component import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.not @@ -31,6 +33,7 @@ import org.hamcrest.Matcher import org.hamcrest.TypeSafeMatcher import org.junit.After import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -102,6 +105,11 @@ class ProfileRenameActivityTest { @Inject lateinit var editTextInputAction: EditTextInputAction + @get:Rule + val activityTestRule: ActivityTestRule = ActivityTestRule( + ProfileRenameActivity::class.java, true, false + ) + @Before fun setUp() { Intents.init() @@ -118,6 +126,21 @@ class ProfileRenameActivityTest { ApplicationProvider.getApplicationContext().inject(this) } + @Test + fun testProfileRenameActivity_hasCorrectActivityLabel() { + activityTestRule.launchActivity( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ) + + val title = activityTestRule.activity.title + assertThat(title).isEqualTo( + context.getString(R.string.profile_rename_activity_label) + ) + } + @Test fun testProfileRenameActivity_inputNewName_clickSave_checkProfileEditActivityIsOpen() { launch( From 14ae620ef14aace9c748a6cd54e6441a31c42113 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Tue, 16 Mar 2021 21:51:29 +0530 Subject: [PATCH 2/9] Improved Code Formatting and Fixed the failing CI test --- app/src/main/AndroidManifest.xml | 4 ++-- app/src/main/res/values/strings.xml | 1 - .../android/app/settings/profile/ProfileRenameActivityTest.kt | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7d015abdc0a..3a7f26e905d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -99,8 +99,8 @@ android:theme="@style/OppiaThemeWithoutActionBar" /> + android:label="@string/profile_rename_title" + android:theme="@style/OppiaThemeWithoutActionBar" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfe37be397e..111f51b8401 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -299,7 +299,6 @@ Rename Profile New Name save - Profile Rename Activity Reset PIN Enter a new PIN for the user to enter when accessing their profile. diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 9207deb4a2f..0677bf4525a 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -136,9 +136,7 @@ class ProfileRenameActivityTest { ) val title = activityTestRule.activity.title - assertThat(title).isEqualTo( - context.getString(R.string.profile_rename_activity_label) - ) + assertThat(title).isEqualTo(context.getString(R.string.profile_rename_title)) } @Test From e1b4fffbee3d8589f463b798e858159950d5a913 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Wed, 17 Mar 2021 22:49:18 +0530 Subject: [PATCH 3/9] changed the activity title string label and changed all instances of the string --- app/src/main/AndroidManifest.xml | 2 +- .../profile/ProfileRenameActivityPresenter.kt | 2 +- .../res/layout-land/profile_rename_activity.xml | 2 +- app/src/main/res/layout/profile_rename_activity.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- .../settings/profile/ProfileRenameActivityTest.kt | 13 +++++-------- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3a7f26e905d..4430805d406 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -99,7 +99,7 @@ android:theme="@style/OppiaThemeWithoutActionBar" /> diff --git a/app/src/main/res/layout/profile_rename_activity.xml b/app/src/main/res/layout/profile_rename_activity.xml index 7d7f971cb59..b1ca5468c7a 100644 --- a/app/src/main/res/layout/profile_rename_activity.xml +++ b/app/src/main/res/layout/profile_rename_activity.xml @@ -32,7 +32,7 @@ android:minHeight="?attr/actionBarSize" app:navigationContentDescription="@string/navigate_up" app:navigationIcon="?attr/homeAsUpIndicator" - app:title="@string/profile_rename_title" + app:title="@string/profile_rename_activity_title" app:titleTextAppearance="@style/ToolbarTextAppearance" app:titleTextColor="@color/white" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 111f51b8401..70350e68f0e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -296,7 +296,7 @@ View Profile Picture Choose From Library - Rename Profile + Rename Profile New Name save diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 0677bf4525a..4bebefc4225 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -38,12 +38,7 @@ 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.application.* import org.oppia.android.app.player.state.hintsandsolution.HintsAndSolutionConfigModule import org.oppia.android.app.shim.ViewBindingShimModule import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape @@ -107,7 +102,9 @@ class ProfileRenameActivityTest { @get:Rule val activityTestRule: ActivityTestRule = ActivityTestRule( - ProfileRenameActivity::class.java, true, false + ProfileRenameActivity::class.java, + /* initialTouchMode= */true, + /* launchActivity= */false ) @Before @@ -136,7 +133,7 @@ class ProfileRenameActivityTest { ) val title = activityTestRule.activity.title - assertThat(title).isEqualTo(context.getString(R.string.profile_rename_title)) + assertThat(title).isEqualTo(context.getString(R.string.profile_rename_activity_title)) } @Test From 287c32fd32c509f41910709aea32e97fee089013 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Wed, 17 Mar 2021 22:59:46 +0530 Subject: [PATCH 4/9] changed the context to application context --- .../app/settings/profile/ProfileRenameActivityTest.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 4bebefc4225..4feb8d65cb9 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -38,7 +38,12 @@ 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.* +import org.oppia.android.app.application.ActivityComponentFactory +import org.oppia.android.app.application.ApplicationComponent +import org.oppia.android.app.application.ApplicationInjectorProvider +import org.oppia.android.app.application.ApplicationInjector +import org.oppia.android.app.application.ApplicationStartupListenerModule +import org.oppia.android.app.application.ApplicationModule import org.oppia.android.app.player.state.hintsandsolution.HintsAndSolutionConfigModule import org.oppia.android.app.shim.ViewBindingShimModule import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape @@ -127,7 +132,7 @@ class ProfileRenameActivityTest { fun testProfileRenameActivity_hasCorrectActivityLabel() { activityTestRule.launchActivity( ProfileRenameActivity.createProfileRenameActivity( - context = context, + context = this.context.applicationContext, profileId = 1 ) ) From 69da742b12363d125fc666c169a29d960e7dab4c Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Wed, 17 Mar 2021 23:04:30 +0530 Subject: [PATCH 5/9] fixed the failing CI test --- .../android/app/settings/profile/ProfileRenameActivityTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 4feb8d65cb9..61edd8ecb04 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -40,10 +40,10 @@ 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.ApplicationInjectorProvider import org.oppia.android.app.application.ApplicationInjector -import org.oppia.android.app.application.ApplicationStartupListenerModule +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.utility.OrientationChangeAction.Companion.orientationLandscape From a325d2310649300b3a6dac03d17a0ded8da70933 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Fri, 19 Mar 2021 09:23:21 +0530 Subject: [PATCH 6/9] removed title from ProfileRenameActivityPresenter since it was not needed --- .../app/settings/profile/ProfileRenameActivityPresenter.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt index c3cf81b7124..aa36e273176 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt @@ -31,7 +31,6 @@ class ProfileRenameActivityPresenter @Inject constructor( } fun handleOnCreate() { - activity.title = activity.getString(R.string.profile_rename_activity_title) activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp) From 613d48934ecc653a0cc13ab08256295d95b8f770 Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Fri, 19 Mar 2021 20:01:29 +0530 Subject: [PATCH 7/9] modified code formatting --- .../android/app/settings/profile/ProfileRenameActivityTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 61edd8ecb04..41b093cd4ad 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -108,8 +108,8 @@ class ProfileRenameActivityTest { @get:Rule val activityTestRule: ActivityTestRule = ActivityTestRule( ProfileRenameActivity::class.java, - /* initialTouchMode= */true, - /* launchActivity= */false + /* initialTouchMode= */ true, + /* launchActivity= */ false ) @Before From 0c9f8931db9138d8022a7c5948a554b3fe8222fb Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Sun, 21 Mar 2021 23:23:33 +0530 Subject: [PATCH 8/9] added comment for readbility --- .../profile/ProfileRenameActivityTest.kt | 962 +++++++++--------- 1 file changed, 481 insertions(+), 481 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index 41b093cd4ad..bc13fec40be 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -1,481 +1,481 @@ -package org.oppia.android.app.settings.profile - -import android.app.Application -import android.content.Context -import android.view.View -import androidx.annotation.StringRes -import androidx.appcompat.app.AppCompatActivity -import androidx.test.core.app.ActivityScenario.launch -import androidx.test.core.app.ApplicationProvider -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.closeSoftKeyboard -import androidx.test.espresso.action.ViewActions.pressImeActionButton -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.intent.Intents -import androidx.test.espresso.intent.Intents.intended -import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent -import androidx.test.espresso.matcher.ViewMatchers.isClickable -import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA -import androidx.test.espresso.matcher.ViewMatchers.isEnabled -import androidx.test.espresso.matcher.ViewMatchers.isRoot -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.rule.ActivityTestRule -import com.google.android.material.textfield.TextInputLayout -import com.google.common.truth.Truth.assertThat -import dagger.Component -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.CoreMatchers.not -import org.hamcrest.Description -import org.hamcrest.Matcher -import org.hamcrest.TypeSafeMatcher -import org.junit.After -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.utility.OrientationChangeAction.Companion.orientationLandscape -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.EditTextInputAction -import org.oppia.android.testing.RobolectricModule -import org.oppia.android.testing.TestCoroutineDispatchers -import org.oppia.android.testing.TestDispatcherModule -import org.oppia.android.testing.TestLogReportingModule -import org.oppia.android.testing.profile.ProfileTestHelper -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.GlideImageLoaderModule -import org.oppia.android.util.parser.HtmlParserEntityTypeModule -import org.oppia.android.util.parser.ImageParsingModule -import org.robolectric.annotation.Config -import org.robolectric.annotation.LooperMode -import javax.inject.Inject -import javax.inject.Singleton - -/** Test for [ProfileRenameActivity]. */ -@RunWith(AndroidJUnit4::class) -@LooperMode(LooperMode.Mode.PAUSED) -@Config( - application = ProfileRenameActivityTest.TestApplication::class, - qualifiers = "port-xxhdpi" -) -class ProfileRenameActivityTest { - - @Inject - lateinit var context: Context - - @Inject - lateinit var profileTestHelper: ProfileTestHelper - - @Inject - lateinit var testCoroutineDispatchers: TestCoroutineDispatchers - - @Inject - lateinit var editTextInputAction: EditTextInputAction - - @get:Rule - val activityTestRule: ActivityTestRule = ActivityTestRule( - ProfileRenameActivity::class.java, - /* initialTouchMode= */ true, - /* launchActivity= */ false - ) - - @Before - fun setUp() { - Intents.init() - setUpTestApplicationComponent() - profileTestHelper.initializeProfiles() - } - - @After - fun tearDown() { - Intents.release() - } - - private fun setUpTestApplicationComponent() { - ApplicationProvider.getApplicationContext().inject(this) - } - - @Test - fun testProfileRenameActivity_hasCorrectActivityLabel() { - activityTestRule.launchActivity( - ProfileRenameActivity.createProfileRenameActivity( - context = this.context.applicationContext, - profileId = 1 - ) - ) - - val title = activityTestRule.activity.title - assertThat(title).isEqualTo(context.getString(R.string.profile_rename_activity_title)) - } - - @Test - fun testProfileRenameActivity_inputNewName_clickSave_checkProfileEditActivityIsOpen() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("James")) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - intended(hasComponent(ProfileEditActivity::class.java.name)) - } - } - - @Test - fun testProfileRenameActivity_inputNewName_clickImeActionButton_checkProfileEditActivityIsOpen() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform( - editTextInputAction.appendText("James"), - pressImeActionButton() - ) - testCoroutineDispatchers.runCurrent() - intended(hasComponent(ProfileEditActivity::class.java.name)) - } - } - - @Test - fun testProfileRenameActivity_inputNewName_configurationChange_checkSaveIsEnabled() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("James")) - testCoroutineDispatchers.runCurrent() - onView(isRoot()).perform(orientationLandscape()) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).check(matches(isEnabled())) - } - } - - @Test - fun testProfileRenameActivity_inputNewName_configurationChange_inputTextExists() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("James")) - testCoroutineDispatchers.runCurrent() - onView(isRoot()).perform(orientationLandscape()) - testCoroutineDispatchers.runCurrent() - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).check( - matches( - withText("James") - ) - ) - } - } - - @Test - fun testProfileRenameActivity_inputOldName_clickSave_checkNameNotUniqueError() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("Admin")) - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_input)) - .check(matches(hasErrorText(R.string.add_profile_error_name_not_unique))) - } - } - - @Test - fun testProfileRenameActivity_inputOldName_clickSave_inputName_checkErrorIsCleared() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("Admin")) - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText(" ")) - onView(withId(R.id.profile_rename_input)) - .check(matches(hasNoErrorText())) - } - } - - @Test - fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_checkNameOnlyLettersError() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("123")) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_input)) - .check(matches(hasErrorText(R.string.add_profile_error_name_only_letters))) - } - } - - @Test - fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_inputName_checkErrorIsCleared() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText("123")) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform(editTextInputAction.appendText(" ")) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_input)) - .check(matches(hasNoErrorText())) - } - } - - @Test - fun testProfileRenameActivity_inputName_changeConfiguration_checkNameIsDisplayed() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform( - editTextInputAction.appendText("test"), - closeSoftKeyboard() - ) - testCoroutineDispatchers.runCurrent() - onView(isRoot()).perform(orientationLandscape()) - testCoroutineDispatchers.runCurrent() - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).check( - matches( - withText("test") - ) - ) - } - } - - @Test - fun testProfileRenameActivity_inputOldName_clickSave_changeConfiguration_errorIsVisible() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView( - allOf( - withId(R.id.profile_rename_input_edit_text), - isDescendantOfA(withId(R.id.profile_rename_input)) - ) - ).perform( - editTextInputAction.appendText("Admin"), - closeSoftKeyboard() - ) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).perform(click()) - testCoroutineDispatchers.runCurrent() - onView(isRoot()).perform(orientationLandscape()) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_input)) - .check(matches(hasErrorText(R.string.add_profile_error_name_not_unique))) - } - } - - @Test - fun testProfileRenameActivity_clickSave_changeConfiguration_saveButtonIsNotClickable() { - launch( - ProfileRenameActivity.createProfileRenameActivity( - context = context, - profileId = 1 - ) - ).use { - onView(withId(R.id.profile_rename_save_button)).check(matches(not(isClickable()))) - onView(isRoot()).perform(orientationLandscape()) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.profile_rename_save_button)).check(matches(not(isClickable()))) - } - } - - private fun hasErrorText(@StringRes expectedErrorTextId: Int): Matcher { - return object : TypeSafeMatcher() { - override fun matchesSafely(view: View): Boolean { - val expectedErrorText = context.resources.getString(expectedErrorTextId) - return (view as TextInputLayout).error == expectedErrorText - } - - override fun describeTo(description: Description) { - description.appendText("TextInputLayout's error") - } - } - } - - private fun hasNoErrorText(): Matcher { - return object : TypeSafeMatcher() { - override fun matchesSafely(view: View): Boolean { - return (view as TextInputLayout).error.isNullOrEmpty() - } - - override fun describeTo(description: Description) { - description.appendText("") - } - } - } - - // TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them. - // TODO(#1675): Add NetworkModule once data module is migrated off of Moshi. - @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 - ] - ) - interface TestApplicationComponent : ApplicationComponent { - @Component.Builder - interface Builder : ApplicationComponent.Builder - - fun inject(profileRenameActivityTest: ProfileRenameActivityTest) - } - - class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { - private val component: TestApplicationComponent by lazy { - DaggerProfileRenameActivityTest_TestApplicationComponent.builder() - .setApplication(this) - .build() as TestApplicationComponent - } - - fun inject(profileRenameActivityTest: ProfileRenameActivityTest) { - component.inject(profileRenameActivityTest) - } - - override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { - return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() - } - - override fun getApplicationInjector(): ApplicationInjector = component - } -} +package org.oppia.android.app.settings.profile + +import android.app.Application +import android.content.Context +import android.view.View +import androidx.annotation.StringRes +import androidx.appcompat.app.AppCompatActivity +import androidx.test.core.app.ActivityScenario.launch +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.pressImeActionButton +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.intent.Intents +import androidx.test.espresso.intent.Intents.intended +import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent +import androidx.test.espresso.matcher.ViewMatchers.isClickable +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA +import androidx.test.espresso.matcher.ViewMatchers.isEnabled +import androidx.test.espresso.matcher.ViewMatchers.isRoot +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import com.google.android.material.textfield.TextInputLayout +import com.google.common.truth.Truth.assertThat +import dagger.Component +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.not +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.TypeSafeMatcher +import org.junit.After +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.utility.OrientationChangeAction.Companion.orientationLandscape +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.EditTextInputAction +import org.oppia.android.testing.RobolectricModule +import org.oppia.android.testing.TestCoroutineDispatchers +import org.oppia.android.testing.TestDispatcherModule +import org.oppia.android.testing.TestLogReportingModule +import org.oppia.android.testing.profile.ProfileTestHelper +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.GlideImageLoaderModule +import org.oppia.android.util.parser.HtmlParserEntityTypeModule +import org.oppia.android.util.parser.ImageParsingModule +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode +import javax.inject.Inject +import javax.inject.Singleton + +/** Test for [ProfileRenameActivity]. */ +@RunWith(AndroidJUnit4::class) +@LooperMode(LooperMode.Mode.PAUSED) +@Config( + application = ProfileRenameActivityTest.TestApplication::class, + qualifiers = "port-xxhdpi" +) +class ProfileRenameActivityTest { + + @Inject + lateinit var context: Context + + @Inject + lateinit var profileTestHelper: ProfileTestHelper + + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + + @Inject + lateinit var editTextInputAction: EditTextInputAction + + @get:Rule + val activityTestRule: ActivityTestRule = ActivityTestRule( + ProfileRenameActivity::class.java, + /* initialTouchMode= */ true, + /* launchActivity= */ false + ) + + @Before + fun setUp() { + Intents.init() + setUpTestApplicationComponent() + profileTestHelper.initializeProfiles() + } + + @After + fun tearDown() { + Intents.release() + } + + private fun setUpTestApplicationComponent() { + ApplicationProvider.getApplicationContext().inject(this) + } + + @Test + fun testProfileRenameActivity_hasCorrectActivityLabel() { + activityTestRule.launchActivity( + ProfileRenameActivity.createProfileRenameActivity( + context = this.context.applicationContext, + profileId = 1 + ) + ) + // Check if the activity title matches the resource string + val title = activityTestRule.activity.title + assertThat(title).isEqualTo(context.getString(R.string.profile_rename_activity_title)) + } + + @Test + fun testProfileRenameActivity_inputNewName_clickSave_checkProfileEditActivityIsOpen() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("James")) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + intended(hasComponent(ProfileEditActivity::class.java.name)) + } + } + + @Test + fun testProfileRenameActivity_inputNewName_clickImeActionButton_checkProfileEditActivityIsOpen() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform( + editTextInputAction.appendText("James"), + pressImeActionButton() + ) + testCoroutineDispatchers.runCurrent() + intended(hasComponent(ProfileEditActivity::class.java.name)) + } + } + + @Test + fun testProfileRenameActivity_inputNewName_configurationChange_checkSaveIsEnabled() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("James")) + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).check(matches(isEnabled())) + } + } + + @Test + fun testProfileRenameActivity_inputNewName_configurationChange_inputTextExists() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("James")) + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).check( + matches( + withText("James") + ) + ) + } + } + + @Test + fun testProfileRenameActivity_inputOldName_clickSave_checkNameNotUniqueError() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("Admin")) + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_input)) + .check(matches(hasErrorText(R.string.add_profile_error_name_not_unique))) + } + } + + @Test + fun testProfileRenameActivity_inputOldName_clickSave_inputName_checkErrorIsCleared() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("Admin")) + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText(" ")) + onView(withId(R.id.profile_rename_input)) + .check(matches(hasNoErrorText())) + } + } + + @Test + fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_checkNameOnlyLettersError() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("123")) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_input)) + .check(matches(hasErrorText(R.string.add_profile_error_name_only_letters))) + } + } + + @Test + fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_inputName_checkErrorIsCleared() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText("123")) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform(editTextInputAction.appendText(" ")) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_input)) + .check(matches(hasNoErrorText())) + } + } + + @Test + fun testProfileRenameActivity_inputName_changeConfiguration_checkNameIsDisplayed() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform( + editTextInputAction.appendText("test"), + closeSoftKeyboard() + ) + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).check( + matches( + withText("test") + ) + ) + } + } + + @Test + fun testProfileRenameActivity_inputOldName_clickSave_changeConfiguration_errorIsVisible() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView( + allOf( + withId(R.id.profile_rename_input_edit_text), + isDescendantOfA(withId(R.id.profile_rename_input)) + ) + ).perform( + editTextInputAction.appendText("Admin"), + closeSoftKeyboard() + ) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_input)) + .check(matches(hasErrorText(R.string.add_profile_error_name_not_unique))) + } + } + + @Test + fun testProfileRenameActivity_clickSave_changeConfiguration_saveButtonIsNotClickable() { + launch( + ProfileRenameActivity.createProfileRenameActivity( + context = context, + profileId = 1 + ) + ).use { + onView(withId(R.id.profile_rename_save_button)).check(matches(not(isClickable()))) + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.profile_rename_save_button)).check(matches(not(isClickable()))) + } + } + + private fun hasErrorText(@StringRes expectedErrorTextId: Int): Matcher { + return object : TypeSafeMatcher() { + override fun matchesSafely(view: View): Boolean { + val expectedErrorText = context.resources.getString(expectedErrorTextId) + return (view as TextInputLayout).error == expectedErrorText + } + + override fun describeTo(description: Description) { + description.appendText("TextInputLayout's error") + } + } + } + + private fun hasNoErrorText(): Matcher { + return object : TypeSafeMatcher() { + override fun matchesSafely(view: View): Boolean { + return (view as TextInputLayout).error.isNullOrEmpty() + } + + override fun describeTo(description: Description) { + description.appendText("") + } + } + } + + // TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them. + // TODO(#1675): Add NetworkModule once data module is migrated off of Moshi. + @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 + ] + ) + interface TestApplicationComponent : ApplicationComponent { + @Component.Builder + interface Builder : ApplicationComponent.Builder + + fun inject(profileRenameActivityTest: ProfileRenameActivityTest) + } + + class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { + private val component: TestApplicationComponent by lazy { + DaggerProfileRenameActivityTest_TestApplicationComponent.builder() + .setApplication(this) + .build() as TestApplicationComponent + } + + fun inject(profileRenameActivityTest: ProfileRenameActivityTest) { + component.inject(profileRenameActivityTest) + } + + override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { + return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() + } + + override fun getApplicationInjector(): ApplicationInjector = component + } +} From 30dd002d246090fda7966239a78f0f7ef7367a1c Mon Sep 17 00:00:00 2001 From: justdvnsh Date: Wed, 24 Mar 2021 12:46:27 +0530 Subject: [PATCH 9/9] added comment for better redability of code --- .../android/app/settings/profile/ProfileRenameActivityTest.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt index bc13fec40be..2c5e825b4d6 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt @@ -136,8 +136,10 @@ class ProfileRenameActivityTest { profileId = 1 ) ) - // Check if the activity title matches the resource string 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. assertThat(title).isEqualTo(context.getString(R.string.profile_rename_activity_title)) }