Skip to content

Commit

Permalink
Fix part of #1870: Fix ProfileRenameActivityTest for Robolectric (#2067)
Browse files Browse the repository at this point in the history
* Fix ProfileRenameActivityTest for Robolectric

* added top level comment
  • Loading branch information
anandwana001 authored Nov 4, 2020
1 parent 93ec2c9 commit 66c1735
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -84,6 +87,9 @@ class ProfileEditActivityTest {
@Inject
lateinit var context: Context

@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

@Inject
lateinit var profileTestHelper: ProfileTestHelper

Expand All @@ -94,19 +100,39 @@ class ProfileEditActivityTest {
fun setUp() {
Intents.init()
setUpTestApplicationComponent()
testCoroutineDispatchers.registerIdlingResource()
profileTestHelper.initializeProfiles()
FirebaseApp.initializeApp(context)
}

@After
fun tearDown() {
testCoroutineDispatchers.unregisterIdlingResource()
Intents.release()
}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

@Test
fun testProfileEditActivity_updateName_checkNewNameDisplayed() {
profileManagementController.updateName(
ProfileId.newBuilder().setInternalId(1).build(),
newName = "Akshay"
)
ActivityScenario.launch<ProfileEditActivity>(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -91,6 +92,9 @@ class ProfileRenameActivityTest {
@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

@Inject
lateinit var editTextInputAction: EditTextInputAction

@Before
fun setUp() {
Intents.init()
Expand All @@ -109,9 +113,7 @@ class ProfileRenameActivityTest {
}

@Test
// TODO(#973): Fix ProfileRenameActivityTest
@Ignore
fun testProfileRenameActivity_inputNewName_clickSave_checkNameIsSaved() {
fun testProfileRenameActivity_inputNewName_clickSave_checkProfileEditActivityIsOpen() {
launch<ProfileRenameActivity>(
ProfileRenameActivity.createProfileRenameActivity(
context,
Expand All @@ -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")))
}
}

Expand Down Expand Up @@ -177,8 +180,6 @@ class ProfileRenameActivityTest {
}

@Test
// TODO(#973): Fix ProfileRenameActivityTest
@Ignore
fun testProfileRenameActivity_inputOldName_clickSave_checkNameNotUniqueError() {
launch<ProfileRenameActivity>(
ProfileRenameActivity.createProfileRenameActivity(
Expand All @@ -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),
Expand All @@ -203,8 +205,6 @@ class ProfileRenameActivityTest {
}

@Test
// TODO(#973): Fix ProfileRenameActivityTest
@Ignore
fun testProfileRenameActivity_inputOldName_clickSave_inputName_checkErrorIsCleared() {
launch<ProfileRenameActivity>(
ProfileRenameActivity.createProfileRenameActivity(
Expand All @@ -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),
Expand Down Expand Up @@ -261,8 +262,6 @@ class ProfileRenameActivityTest {
}

@Test
// TODO(#973): Fix ProfileRenameActivityTest
@Ignore
fun testProfileRenameActivity_inputNameWithNumbers_clickCreate_inputName_checkErrorIsCleared() {
launch<ProfileRenameActivity>(
ProfileRenameActivity.createProfileRenameActivity(
Expand All @@ -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(
Expand Down Expand Up @@ -319,8 +318,6 @@ class ProfileRenameActivityTest {
}

@Test
// TODO(#973): Fix ProfileRenameActivityTest
@Ignore
fun testProfileRenameActivity_inputOldName_clickSave_changeConfiguration_errorIsVisible() {
launch<ProfileRenameActivity>(
ProfileRenameActivity.createProfileRenameActivity(
Expand Down

0 comments on commit 66c1735

Please sign in to comment.