Skip to content

Commit

Permalink
fix home test (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandwana001 authored Jan 7, 2021
1 parent 83e409a commit ccc1ddb
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
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 @@ -145,12 +144,12 @@ class HomeActivityTest {
}

@Test
@Ignore(
"This test case is incorrect as it depends on internalProfileId " +
"which is not guaranteed to be 0 for admin."
)
fun testHomeActivity_recyclerViewIndex0_withProfileId0_displayProfileName_profileNameDisplayedSuccessfully() { // ktlint-disable max-line-length
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
fun testHomeActivity_withAdminProfile_profileNameDisplayedSuccessfully() {
launch<HomeActivity>(createHomeActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(0)
)
onView(
atPositionOnView(
R.id.home_recycler_view,
Expand All @@ -162,28 +161,27 @@ class HomeActivityTest {
}

@Test
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodMorningMessageDisplayedSuccessful() { // ktlint-disable max-line-length
getApplicationDependencies()
oppiaClock.setCurrentTimeMs(MORNING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
fun testHomeActivity_withAdminProfile_configChange_profileNameDisplayedSuccessfully() {
launch<HomeActivity>(createHomeActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(0)
)
onView(
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.welcome_text_view
R.id.profile_name_textview
)
).check(matches(withText("Good morning,")))
).check(matches(withText("Admin!")))
}
}

@Test
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodAfternoonMessageDisplayedSuccessful() { // ktlint-disable max-line-length
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodMorningMessageDisplayedSuccessful() { // ktlint-disable max-line-length
getApplicationDependencies()
oppiaClock.setCurrentTimeMs(AFTERNOON_TIMESTAMP)
oppiaClock.setCurrentTimeMs(MORNING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
Expand All @@ -195,14 +193,14 @@ class HomeActivityTest {
0,
R.id.welcome_text_view
)
).check(matches(withText("Good afternoon,")))
).check(matches(withText("Good morning,")))
}
}

@Test
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodEveningMessageDisplayedSuccessful() { // ktlint-disable max-line-length
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodAfternoonMessageDisplayedSuccessful() { // ktlint-disable max-line-length
getApplicationDependencies()
oppiaClock.setCurrentTimeMs(EVENING_TIMESTAMP)
oppiaClock.setCurrentTimeMs(AFTERNOON_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
Expand All @@ -214,25 +212,26 @@ class HomeActivityTest {
0,
R.id.welcome_text_view
)
).check(matches(withText("Good evening,")))
).check(matches(withText("Good afternoon,")))
}
}

@Test
fun testHomeActivity_recyclerViewIndex0_configurationChange_displaysWelcomeMessageCorrectly() {
launch<HomeActivity>(createHomeActivityIntent(0)).use {
fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodEveningMessageDisplayedSuccessful() { // ktlint-disable max-line-length
getApplicationDependencies()
oppiaClock.setCurrentTimeMs(EVENING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(0)
)
onView(
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_textview
R.id.welcome_text_view
)
).check(matches(withText("Admin!")))
).check(matches(withText("Good evening,")))
}
}

Expand Down

0 comments on commit ccc1ddb

Please sign in to comment.