Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #1870: Fix ProfileRenameActivityTest for Robolectric #2067

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Down Expand Up @@ -84,6 +86,9 @@ class ProfileEditActivityTest {
@Inject
lateinit var context: Context

@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

@Inject
lateinit var profileTestHelper: ProfileTestHelper

Expand All @@ -94,19 +99,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 Down Expand Up @@ -91,6 +91,9 @@ class ProfileRenameActivityTest {
@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

@Inject
lateinit var editTextInputAction: EditTextInputAction

@Before
fun setUp() {
Intents.init()
Expand All @@ -109,9 +112,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 +125,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 +179,6 @@ class ProfileRenameActivityTest {
}

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

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

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

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