From ccc1ddb049a5dac832745b9911b61763b8b8ae67 Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Thu, 7 Jan 2021 10:56:24 +0530 Subject: [PATCH] fix home test (#2416) --- .../android/app/home/HomeActivityTest.kt | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt index ef89f402ef7..606d8c9d898 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt @@ -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 @@ -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(createHomeActivityIntent(internalProfileId)).use { + fun testHomeActivity_withAdminProfile_profileNameDisplayedSuccessfully() { + launch(createHomeActivityIntent(0)).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.home_recycler_view)).perform( + scrollToPosition(0) + ) onView( atPositionOnView( R.id.home_recycler_view, @@ -162,11 +161,10 @@ class HomeActivityTest { } @Test - fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodMorningMessageDisplayedSuccessful() { // ktlint-disable max-line-length - getApplicationDependencies() - oppiaClock.setCurrentTimeMs(MORNING_TIMESTAMP) - launch(createHomeActivityIntent(internalProfileId)).use { + fun testHomeActivity_withAdminProfile_configChange_profileNameDisplayedSuccessfully() { + launch(createHomeActivityIntent(0)).use { testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) onView(withId(R.id.home_recycler_view)).perform( scrollToPosition(0) ) @@ -174,16 +172,16 @@ class HomeActivityTest { 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(createHomeActivityIntent(internalProfileId)).use { testCoroutineDispatchers.runCurrent() onView(withId(R.id.home_recycler_view)).perform( @@ -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(createHomeActivityIntent(internalProfileId)).use { testCoroutineDispatchers.runCurrent() onView(withId(R.id.home_recycler_view)).perform( @@ -214,15 +212,16 @@ 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(createHomeActivityIntent(0)).use { + fun testHomeActivity_recyclerViewIndex0_displayGreetingMessageBasedOnTime_goodEveningMessageDisplayedSuccessful() { // ktlint-disable max-line-length + getApplicationDependencies() + oppiaClock.setCurrentTimeMs(EVENING_TIMESTAMP) + launch(createHomeActivityIntent(internalProfileId)).use { testCoroutineDispatchers.runCurrent() - onView(isRoot()).perform(orientationLandscape()) onView(withId(R.id.home_recycler_view)).perform( scrollToPosition(0) ) @@ -230,9 +229,9 @@ class HomeActivityTest { 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,"))) } }