diff --git a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt index a70fb82d809..afbdcd66ea4 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt @@ -35,6 +35,7 @@ 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.model.ProfileId 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 @@ -57,6 +58,7 @@ import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.domain.question.QuestionModule import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule import org.oppia.android.testing.TestAccessibilityModule +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 @@ -73,6 +75,7 @@ import org.robolectric.annotation.LooperMode import javax.inject.Inject import javax.inject.Singleton +/** Test for [ProfileEditActivity]. */ @RunWith(AndroidJUnit4::class) @LooperMode(LooperMode.Mode.PAUSED) @Config( @@ -84,6 +87,9 @@ class ProfileEditActivityTest { @Inject lateinit var context: Context + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + @Inject lateinit var profileTestHelper: ProfileTestHelper @@ -94,12 +100,14 @@ class ProfileEditActivityTest { fun setUp() { Intents.init() setUpTestApplicationComponent() + testCoroutineDispatchers.registerIdlingResource() profileTestHelper.initializeProfiles() FirebaseApp.initializeApp(context) } @After fun tearDown() { + testCoroutineDispatchers.unregisterIdlingResource() Intents.release() } @@ -107,6 +115,24 @@ class ProfileEditActivityTest { ApplicationProvider.getApplicationContext().inject(this) } + @Test + fun testProfileEditActivity_updateName_checkNewNameDisplayed() { + profileManagementController.updateName( + ProfileId.newBuilder().setInternalId(1).build(), + newName = "Akshay" + ) + ActivityScenario.launch( + ProfileEditActivity.createProfileEditActivity( + context, + 1 + ) + ).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.action_bar)).check(matches(hasDescendant(withText("Akshay")))) + onView(withId(R.id.profile_edit_name)).check(matches(withText("Akshay"))) + } + } + @Test // TODO(#973): Fix ProfileEditActivityTest @Ignore 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 ef1a450e801..6e04a6afb28 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 @@ -26,7 +26,6 @@ import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.not import org.junit.After import org.junit.Before -import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -57,6 +56,7 @@ 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.TestAccessibilityModule import org.oppia.android.testing.TestCoroutineDispatchers import org.oppia.android.testing.TestDispatcherModule @@ -74,6 +74,7 @@ import org.robolectric.annotation.LooperMode import javax.inject.Inject import javax.inject.Singleton +/** Test for [ProfileRenameActivity]. */ @RunWith(AndroidJUnit4::class) @LooperMode(LooperMode.Mode.PAUSED) @Config( @@ -91,6 +92,9 @@ class ProfileRenameActivityTest { @Inject lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + @Inject + lateinit var editTextInputAction: EditTextInputAction + @Before fun setUp() { Intents.init() @@ -109,9 +113,7 @@ class ProfileRenameActivityTest { } @Test - // TODO(#973): Fix ProfileRenameActivityTest - @Ignore - fun testProfileRenameActivity_inputNewName_clickSave_checkNameIsSaved() { + fun testProfileRenameActivity_inputNewName_clickSave_checkProfileEditActivityIsOpen() { launch( ProfileRenameActivity.createProfileRenameActivity( context, @@ -124,9 +126,10 @@ class ProfileRenameActivityTest { isDescendantOfA(withId(R.id.input_name)) ) ).perform(typeText("James")) + testCoroutineDispatchers.runCurrent() onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() intended(hasComponent(ProfileEditActivity::class.java.name)) - onView(withId(R.id.profile_edit_name)).check(matches(withText("James"))) } } @@ -177,8 +180,6 @@ class ProfileRenameActivityTest { } @Test - // TODO(#973): Fix ProfileRenameActivityTest - @Ignore fun testProfileRenameActivity_inputOldName_clickSave_checkNameNotUniqueError() { launch( ProfileRenameActivity.createProfileRenameActivity( @@ -191,8 +192,9 @@ class ProfileRenameActivityTest { withId(R.id.input), isDescendantOfA(withId(R.id.input_name)) ) - ).perform(typeText("Admin")) + ).perform(editTextInputAction.appendText("Admin")) onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() onView( allOf( withId(R.id.error_text), @@ -203,8 +205,6 @@ class ProfileRenameActivityTest { } @Test - // TODO(#973): Fix ProfileRenameActivityTest - @Ignore fun testProfileRenameActivity_inputOldName_clickSave_inputName_checkErrorIsCleared() { launch( ProfileRenameActivity.createProfileRenameActivity( @@ -217,14 +217,15 @@ class ProfileRenameActivityTest { withId(R.id.input), isDescendantOfA(withId(R.id.input_name)) ) - ).perform(typeText("Admin")) + ).perform(editTextInputAction.appendText("Admin")) onView(withId(R.id.profile_rename_save_button)).perform(click()) + testCoroutineDispatchers.runCurrent() onView( allOf( withId(R.id.input), isDescendantOfA(withId(R.id.input_name)) ) - ).perform(typeText(" ")) + ).perform(editTextInputAction.appendText(" ")) onView( allOf( withId(R.id.error_text), @@ -261,8 +262,6 @@ class ProfileRenameActivityTest { } @Test - // TODO(#973): Fix ProfileRenameActivityTest - @Ignore fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_inputName_checkErrorIsCleared() { launch( ProfileRenameActivity.createProfileRenameActivity( @@ -284,7 +283,7 @@ class ProfileRenameActivityTest { withId(R.id.input), isDescendantOfA(withId(R.id.input_name)) ) - ).perform(typeText(" ")) + ).perform(editTextInputAction.appendText(" ")) testCoroutineDispatchers.runCurrent() onView( allOf( @@ -319,8 +318,6 @@ class ProfileRenameActivityTest { } @Test - // TODO(#973): Fix ProfileRenameActivityTest - @Ignore fun testProfileRenameActivity_inputOldName_clickSave_changeConfiguration_errorIsVisible() { launch( ProfileRenameActivity.createProfileRenameActivity(