diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ca2cc9e4299..25d6626213d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,9 +19,11 @@ + tools:context=".app.administratorcontrols.appversion.AppVersionActivity"> diff --git a/app/src/main/res/layout/app_version_activity.xml b/app/src/main/res/layout/app_version_activity.xml index d47c28f22a4..c7309d4b0f6 100644 --- a/app/src/main/res/layout/app_version_activity.xml +++ b/app/src/main/res/layout/app_version_activity.xml @@ -24,7 +24,7 @@ app:navigationContentDescription="@string/navigate_up" app:navigationIcon="?attr/homeAsUpIndicator" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" - app:title="@string/administrator_controls_app_version" + app:title="@string/app_version_activity_title" app:titleTextAppearance="@style/ToolbarTextAppearance" app:titleTextColor="@color/white" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca65f9b599f..4a05630f25c 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,6 +8,7 @@ Help Switch Profile Administrator Controls + Administrator Controls Navigation Menu Open Navigation Menu Close Welcome to Oppia! @@ -187,7 +188,7 @@ \u0020|\u0020 - Profile selection page + Profile selection page Administrator Select your profile Add Profile @@ -329,6 +330,7 @@ Ok Are you sure you want to log out of your profile? + App Version App Version %s The last update was installed on %s. Use the above version number to send feedback about bugs. diff --git a/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt index a053d6f2131..4a4f8b583de 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt @@ -11,8 +11,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.widget.NestedScrollView import androidx.drawerlayout.widget.DrawerLayout import androidx.recyclerview.widget.RecyclerView -import androidx.test.core.app.ActivityScenario -import androidx.test.core.app.ActivityScenario.launch import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView import androidx.test.espresso.PerformException @@ -34,12 +32,15 @@ import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.util.HumanReadables +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat import dagger.Component import org.hamcrest.Matchers import org.hamcrest.Matchers.not import org.junit.After import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -103,6 +104,10 @@ import javax.inject.Singleton ) class AdministratorControlsActivityTest { + @get:Rule + val activityScenarioRule: ActivityScenarioRule = + ActivityScenarioRule(createAdministratorControlsActivityIntent(profileId = 0)) + @Inject lateinit var profileTestHelper: ProfileTestHelper @@ -131,299 +136,239 @@ class AdministratorControlsActivityTest { } @Test - fun testAdministratorControlsFragment_generalAndProfileManagementIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 0, - targetView = R.id.general_text_view - ) - verifyTextOnAdministratorListItemAtPosition( - itemPosition = 0, - targetViewId = R.id.edit_account_text_view, - stringIdToMatch = R.string.administrator_controls_edit_account - ) - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 1, - targetView = R.id.profile_management_text_view - ) - verifyTextOnAdministratorListItemAtPosition( - itemPosition = 1, - targetViewId = R.id.edit_profiles_text_view, - stringIdToMatch = R.string.administrator_controls_edit_profiles + fun testAdministratorControlsActivity_hasCorrectActivityLabel() { + activityScenarioRule.scenario.onActivity { + // Verify that the activity label is correct as a proxy to verify TalkBack will announce the + // correct string when it's read out. + assertThat(it.title).isEqualTo( + context.getString(R.string.administrator_controls_activity_title) ) } } + @Test + fun testAdministratorControlsFragment_generalAndProfileManagementIsDisplayed() { + testCoroutineDispatchers.runCurrent() + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 0, + targetView = R.id.general_text_view + ) + verifyTextOnAdministratorListItemAtPosition( + itemPosition = 0, + targetViewId = R.id.edit_account_text_view, + stringIdToMatch = R.string.administrator_controls_edit_account + ) + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 1, + targetView = R.id.profile_management_text_view + ) + verifyTextOnAdministratorListItemAtPosition( + itemPosition = 1, + targetViewId = R.id.edit_profiles_text_view, + stringIdToMatch = R.string.administrator_controls_edit_profiles + ) + } + @Test fun testAdministratorControlsFragment_downloadPermissionsAndSettingsIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - verifyTextOnAdministratorListItemAtPosition( - itemPosition = 2, - targetViewId = R.id.download_permissions_text_view, - stringIdToMatch = R.string.administrator_controls_download_permissions_label - ) - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 2, - targetView = R.id.topic_update_on_wifi_constraint_layout - ) - scrollToPosition(position = 2) - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 2, - targetView = R.id.auto_update_topic_constraint_layout - ) - } + testCoroutineDispatchers.runCurrent() + verifyTextOnAdministratorListItemAtPosition( + itemPosition = 2, + targetViewId = R.id.download_permissions_text_view, + stringIdToMatch = R.string.administrator_controls_download_permissions_label + ) + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 2, + targetView = R.id.topic_update_on_wifi_constraint_layout + ) + scrollToPosition(position = 2) + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 2, + targetView = R.id.auto_update_topic_constraint_layout + ) } @Test fun testAdministratorControlsFragment_applicationSettingsIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 3) - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 3, - targetView = R.id.app_information_text_view - ) - verifyTextOnAdministratorListItemAtPosition( - itemPosition = 3, - targetViewId = R.id.app_version_text_view, - stringIdToMatch = R.string.administrator_controls_app_version - ) - verifyItemDisplayedOnAdministratorControlListItem( - itemPosition = 4, - targetView = R.id.account_actions_text_view - ) - verifyTextOnAdministratorListItemAtPosition( - itemPosition = 4, - targetViewId = R.id.log_out_text_view, - stringIdToMatch = R.string.administrator_controls_log_out - ) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 3) + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 3, + targetView = R.id.app_information_text_view + ) + verifyTextOnAdministratorListItemAtPosition( + itemPosition = 3, + targetViewId = R.id.app_version_text_view, + stringIdToMatch = R.string.administrator_controls_app_version + ) + verifyItemDisplayedOnAdministratorControlListItem( + itemPosition = 4, + targetView = R.id.account_actions_text_view + ) + verifyTextOnAdministratorListItemAtPosition( + itemPosition = 4, + targetViewId = R.id.log_out_text_view, + stringIdToMatch = R.string.administrator_controls_log_out + ) } @Test fun testAdministratorControlsFragment_wifiSwitchIsUncheck_autoUpdateSwitchIsUncheck() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 + testCoroutineDispatchers.runCurrent() + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.topic_update_on_wifi_switch ) - ).use { - testCoroutineDispatchers.runCurrent() - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.topic_update_on_wifi_switch - ) - ).check(matches(not(isChecked()))) - scrollToPosition(position = 2) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.auto_update_topic_switch - ) - ).check(matches(not(isChecked()))) - } + ).check(matches(not(isChecked()))) + scrollToPosition(position = 2) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.auto_update_topic_switch + ) + ).check(matches(not(isChecked()))) } @Test fun testAdministratorControlsFragment_clickWifiSwitch_configChange_wifiSwitchIsChecked() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 2) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.topic_update_on_wifi_switch ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 2) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.topic_update_on_wifi_switch - ) - ).check(matches(not(isChecked()))) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.auto_update_topic_switch - ) - ).check(matches(not(isChecked()))) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.topic_update_on_wifi_switch - ) - ).perform(click()) - onView(isRoot()).perform(orientationLandscape()) - scrollToPosition(position = 2) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.topic_update_on_wifi_switch - ) - ).check(matches(isChecked())) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.auto_update_topic_switch - ) - ).check(matches(not(isChecked()))) - onView(isRoot()).perform(orientationPortrait()) - scrollToPosition(position = 2) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.topic_update_on_wifi_switch - ) - ).check(matches(isChecked())) - onView( - atPositionOnView( - R.id.administrator_controls_list, - 2, - R.id.auto_update_topic_switch - ) - ).check(matches(not(isChecked()))) - } + ).check(matches(not(isChecked()))) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.auto_update_topic_switch + ) + ).check(matches(not(isChecked()))) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.topic_update_on_wifi_switch + ) + ).perform(click()) + onView(isRoot()).perform(orientationLandscape()) + scrollToPosition(position = 2) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.topic_update_on_wifi_switch + ) + ).check(matches(isChecked())) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.auto_update_topic_switch + ) + ).check(matches(not(isChecked()))) + onView(isRoot()).perform(orientationPortrait()) + scrollToPosition(position = 2) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.topic_update_on_wifi_switch + ) + ).check(matches(isChecked())) + onView( + atPositionOnView( + R.id.administrator_controls_list, + 2, + R.id.auto_update_topic_switch + ) + ).check(matches(not(isChecked()))) } @Test fun testAdministratorControlsFragment_clickEditProfile_opensProfileListActivity() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.edit_profiles_text_view)).perform(click()) - intended(hasComponent(ProfileListActivity::class.java.name)) - } + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.edit_profiles_text_view)).perform(click()) + intended(hasComponent(ProfileListActivity::class.java.name)) } @Test fun testAdministratorControlsFragment_clickLogoutButton_logoutDialogIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 4) - onView(withId(R.id.log_out_text_view)).perform(click()) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_okay_button) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_cancel_button) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 4) + onView(withId(R.id.log_out_text_view)).perform(click()) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_okay_button) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_cancel_button) } @Test fun testAdministratorControlsFragment_configChange_clickLogout_logoutDialogIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 4) - onView(isRoot()).perform(orientationLandscape()) - scrollToPosition(position = 4) - onView(withId(R.id.log_out_text_view)).perform(click()) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_okay_button) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_cancel_button) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 4) + onView(isRoot()).perform(orientationLandscape()) + scrollToPosition(position = 4) + onView(withId(R.id.log_out_text_view)).perform(click()) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_okay_button) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_cancel_button) } // TODO(#762): Replace [ProfileChooserActivity] to [LoginActivity] once it is added. @Test fun testAdministratorControlsFragment_clickOkButtonInLogoutDialog_opensProfileChooserActivity() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 4) - onView(withId(R.id.log_out_text_view)).perform(click()) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) - onView(withText(R.string.log_out_dialog_okay_button)).perform(click()) - intended(hasComponent(ProfileChooserActivity::class.java.name)) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 4) + onView(withId(R.id.log_out_text_view)).perform(click()) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) + onView(withText(R.string.log_out_dialog_okay_button)).perform(click()) + intended(hasComponent(ProfileChooserActivity::class.java.name)) } @Test fun testAdministratorControlsFragment_clickCancelButtonInLogoutDialog_dialogIsDismissed() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 4) - onView(withId(R.id.log_out_text_view)).perform(click()) - verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) - onView(withText(R.string.log_out_dialog_cancel_button)).perform(click()) - onView(withId(R.id.log_out_text_view)).check(matches(isDisplayed())) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 4) + onView(withId(R.id.log_out_text_view)).perform(click()) + verifyTextInDialog(textInDialogId = R.string.log_out_dialog_message) + onView(withText(R.string.log_out_dialog_cancel_button)).perform(click()) + onView(withId(R.id.log_out_text_view)).check(matches(isDisplayed())) } @Test fun testAdministratorControlsFragment_clickAppVersion_opensAppVersionActivity() { - launch( - createAdministratorControlsActivityIntent( - profileId = 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - scrollToPosition(position = 3) - onView(withId(R.id.app_version_text_view)).perform(click()) - intended(hasComponent(AppVersionActivity::class.java.name)) - } + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 3) + onView(withId(R.id.app_version_text_view)).perform(click()) + intended(hasComponent(AppVersionActivity::class.java.name)) } @Test fun testAdministratorControls_selectAdminNavItem_adminControlsIsDisplayed() { - launch( - createAdministratorControlsActivityIntent( - 0 - ) - ).use { - it.openNavigationDrawer() - onView(withId(R.id.administrator_controls_linear_layout)).perform(nestedScrollTo()) - .perform(click()) - onView(withText(context.getString(R.string.administrator_controls_edit_account))) - .check(matches(isDisplayed())) - } + activityScenarioRule.openNavigationDrawer() + onView(withId(R.id.administrator_controls_linear_layout)).perform(nestedScrollTo()) + .perform(click()) + onView(withText(context.getString(R.string.administrator_controls_edit_account))).check( + matches(isDisplayed()) + ) } - private fun ActivityScenario.openNavigationDrawer() { + private fun ActivityScenarioRule.openNavigationDrawer() { onView(withContentDescription(R.string.drawer_open_content_description)) .check(matches(isCompletelyDisplayed())) .perform(click()) // Force the drawer animation to start. See https://github.com/oppia/oppia-android/pull/2204 for // background context. - onActivity { activity -> + scenario.onActivity { val drawerLayout = - activity.findViewById(R.id.administrator_controls_activity_drawer_layout) + it.findViewById(R.id.administrator_controls_activity_drawer_layout) // Note that this only initiates a single computeScroll() in Robolectric. Normally, Android // will compute several of these across multiple draw calls, but one seems sufficient for // Robolectric. Note that Robolectric is also *supposed* to handle the animation loop one call @@ -443,7 +388,7 @@ class AdministratorControlsActivityTest { private fun createAdministratorControlsActivityIntent(profileId: Int): Intent { return AdministratorControlsActivity.createAdministratorControlsActivityIntent( - context, + ApplicationProvider.getApplicationContext(), profileId ) } @@ -465,7 +410,7 @@ class AdministratorControlsActivityTest { try { val nestedScrollView = findFirstParentLayoutOfClass(view, NestedScrollView::class.java) as NestedScrollView - nestedScrollView.scrollTo(0, view.getTop()) + nestedScrollView.scrollTo(0, view.top) } catch (e: Exception) { throw PerformException.Builder() .withActionDescription(this.description) @@ -479,14 +424,14 @@ class AdministratorControlsActivityTest { } private fun findFirstParentLayoutOfClass(view: View, parentClass: Class): View { - var parent: ViewParent = FrameLayout(view.getContext()) + var parent: ViewParent = FrameLayout(view.context) lateinit var incrementView: ViewParent var i = 0 while (!(parent.javaClass === parentClass)) { - if (i == 0) { - parent = findParent(view) + parent = if (i == 0) { + findParent(view) } else { - parent = findParent(incrementView) + findParent(incrementView) } incrementView = parent i++ @@ -495,11 +440,11 @@ class AdministratorControlsActivityTest { } private fun findParent(view: View): ViewParent { - return view.getParent() + return view.parent } private fun findParent(view: ViewParent): ViewParent { - return view.getParent() + return view.parent } private fun verifyItemDisplayedOnAdministratorControlListItem( diff --git a/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt index 577a6c5c43a..95bf02c5045 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt @@ -4,25 +4,22 @@ import android.app.Application import android.content.Context import android.content.Intent import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.RecyclerView -import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.pressBack import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition import androidx.test.espresso.intent.Intents -import androidx.test.espresso.intent.Intents.intended -import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.isRoot +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat import dagger.Component import org.junit.After import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -85,6 +82,10 @@ import javax.inject.Singleton ) class AppVersionActivityTest { + @get:Rule + val activityScenarioRule: ActivityScenarioRule = + ActivityScenarioRule(createAppVersionActivityIntent()) + @Inject lateinit var context: Context @@ -115,82 +116,46 @@ class AppVersionActivityTest { } @Test - fun testAppVersionActivity_loadFragment_displaysAppVersion() { - launchAppVersionActivityIntent().use { - onView( - withText( - String.format( - context.resources.getString(R.string.app_version_name), - context.getVersionName() - ) - ) - ).check(matches(isDisplayed())) - onView( - withText( - String.format( - context.resources.getString(R.string.app_last_update_date), - lastUpdateDate - ) - ) - ).check( - matches(isDisplayed()) - ) + fun testAppVersionActivity_hasCorrectActivityLabel() { + activityScenarioRule.scenario.onActivity { + // Verify that the activity label is correct as a proxy to verify TalkBack will announce the + // correct string when it's read out. + assertThat(it.title).isEqualTo(context.getString(R.string.app_version_activity_title)) } } @Test - fun testAppVersionActivity_configurationChange_appVersionIsDisplayedCorrectly() { - launchAppVersionActivityIntent().use { - onView(isRoot()).perform(orientationLandscape()) - onView( - withId( - R.id.app_version_text_view - ) - ).check( - matches( - withText( - String.format( - context.resources.getString(R.string.app_version_name), - context.getVersionName() - ) - ) + fun testAppVersionActivity_loadFragment_backButtonContentDescriptionIsCorrect() { + onView(withContentDescription(R.string.navigate_up)).check(matches(isDisplayed())) + } + + @Test + fun testAppVersionActivity_loadFragment_displaysAppVersion() { + onView( + withText( + String.format( + context.resources.getString(R.string.app_version_name), + context.getVersionName() ) ) - onView( - withId( - R.id.app_last_update_date_text_view - ) - ).check( - matches( - withText( - String.format( - context.resources.getString(R.string.app_last_update_date), - lastUpdateDate - ) - ) + ).check(matches(isDisplayed())) + onView( + withText( + String.format( + context.resources.getString(R.string.app_last_update_date), + lastUpdateDate ) ) - } + ).check(matches(isDisplayed())) } @Test - fun testAppVersionActivity_loadFragment_onBackPressed_displaysAdministratorControlsActivity() { - ActivityScenario.launch( - launchAdministratorControlsActivityIntent( - 0 - ) - ).use { - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.administrator_controls_list)).perform( - scrollToPosition( - 3 - ) - ) - onView(withText(R.string.administrator_controls_app_version)).perform(click()) - intended(hasComponent(AppVersionActivity::class.java.name)) - onView(isRoot()).perform(pressBack()) - onView(withId(R.id.administrator_controls_list)).check(matches(isDisplayed())) - } + fun testAppVersionActivity_configurationChange_appVersionIsDisplayedCorrectly() { + onView(isRoot()).perform(orientationLandscape()) + onView(withId(R.id.app_version_text_view)).check(matches(withText(appVersionString()))) + onView(withId(R.id.app_last_update_date_text_view)).check( + matches(withText(lastDateUsedString())) + ) } private fun getDateTime(dateTimeTimestamp: Long): String? { @@ -201,17 +166,20 @@ class AppVersionActivityTest { ) } - private fun launchAppVersionActivityIntent(): ActivityScenario { - val intent = AppVersionActivity.createAppVersionActivityIntent( - ApplicationProvider.getApplicationContext() + private fun appVersionString(): String { + return String.format( + context.resources.getString(R.string.app_version_name), + context.getVersionName() ) - return ActivityScenario.launch(intent) } - private fun launchAdministratorControlsActivityIntent(profileId: Int): Intent { - return AdministratorControlsActivity.createAdministratorControlsActivityIntent( - ApplicationProvider.getApplicationContext(), - profileId + private fun lastDateUsedString(): String { + return String.format(context.resources.getString(R.string.app_last_update_date), lastUpdateDate) + } + + private fun createAppVersionActivityIntent(): Intent { + return AppVersionActivity.createAppVersionActivityIntent( + ApplicationProvider.getApplicationContext() ) } diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt index a2a2ef73048..bdb30180758 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt @@ -21,6 +21,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withParent import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.Component import org.hamcrest.Matchers.allOf @@ -29,6 +30,7 @@ import org.hamcrest.Matchers.instanceOf import org.hamcrest.Matchers.not import org.junit.After import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -117,6 +119,10 @@ class RecentlyPlayedFragmentTest { private lateinit var profileId: ProfileId + @get:Rule + val activityScenarioRule: ActivityScenarioRule = + ActivityScenarioRule(createRecentlyPlayedActivityIntent(internalProfileId)) + @Before fun setUp() { Intents.init() @@ -139,7 +145,7 @@ class RecentlyPlayedFragmentTest { private fun createRecentlyPlayedActivityIntent(profileId: Int): Intent { return RecentlyPlayedActivity.createRecentlyPlayedActivityIntent( - context, + ApplicationProvider.getApplicationContext(), profileId ) } @@ -185,23 +191,17 @@ class RecentlyPlayedFragmentTest { profileId, timestampOlderThanOneWeek = true ) - ActivityScenario.launch( - createRecentlyPlayedActivityIntent( - internalProfileId - ) - ).use { - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.ongoing_story_recycler_view)).perform( - scrollToPosition( - 0 - ) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.ongoing_story_recycler_view)).perform( + scrollToPosition( + 0 ) - onView( - atPositionOnView(R.id.ongoing_story_recycler_view, 0, R.id.divider_view) - ).check( - matches(not(isDisplayed())) - ) - } + ) + onView( + atPositionOnView(R.id.ongoing_story_recycler_view, 0, R.id.divider_view) + ).check( + matches(not(isDisplayed())) + ) } @Test diff --git a/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt index 797f22198f9..bbc14c332ab 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt @@ -12,6 +12,7 @@ import android.provider.MediaStore import android.view.View import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.test.core.app.ActivityScenario.launch import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView @@ -33,6 +34,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isEnabled import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.android.material.textfield.TextInputLayout import dagger.Component @@ -43,6 +45,7 @@ import org.hamcrest.Matchers.not import org.hamcrest.TypeSafeMatcher import org.junit.After import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.R @@ -101,6 +104,10 @@ import javax.inject.Singleton ) class AddProfileActivityTest { + @get:Rule + val activityScenarioRule: ActivityScenarioRule = + ActivityScenarioRule(createAddProfileActivityIntent()) + @Inject lateinit var context: Context @@ -1137,25 +1144,23 @@ class AddProfileActivityTest { @Test fun testAddProfileActivity_inputName_configChange_nameIsDisplayed() { - launch(AddProfileActivity::class.java).use { - onView( - allOf( - withId(R.id.add_profile_activity_user_name_edit_text), - isDescendantOfA(withId(R.id.add_profile_activity_user_name)) - ) - ).perform( - editTextInputAction.appendText("test"), - closeSoftKeyboard() - ) - onView(isRoot()).perform(orientationLandscape()) - onView( - allOf( - withId(R.id.add_profile_activity_user_name_edit_text), - isDescendantOfA(withId(R.id.add_profile_activity_user_name)) - ) - ).perform(scrollTo()) - .check(matches(withText("test"))) - } + onView( + allOf( + withId(R.id.add_profile_activity_user_name_edit_text), + isDescendantOfA(withId(R.id.add_profile_activity_user_name)) + ) + ).perform( + editTextInputAction.appendText("test"), + closeSoftKeyboard() + ) + onView(isRoot()).perform(orientationLandscape()) + onView( + allOf( + withId(R.id.add_profile_activity_user_name_edit_text), + isDescendantOfA(withId(R.id.add_profile_activity_user_name)) + ) + ).perform(scrollTo()) + .check(matches(withText("test"))) } @Test @@ -1530,6 +1535,16 @@ class AddProfileActivityTest { } } + private fun createAddProfileActivityIntent(): Intent { + return AddProfileActivity.createAddProfileActivityIntent( + ApplicationProvider.getApplicationContext(), + ContextCompat.getColor( + ApplicationProvider.getApplicationContext(), + R.color.avatar_background_1 + ) + ) + } + private fun hasErrorText(@StringRes expectedErrorTextId: Int): Matcher { return object : TypeSafeMatcher() { override fun matchesSafely(view: View): Boolean { diff --git a/app/src/sharedTest/java/org/oppia/android/app/profile/ProfileChooserFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/profile/ProfileChooserFragmentTest.kt index 8e60054a7af..fbfdf1395ad 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/profile/ProfileChooserFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/profile/ProfileChooserFragmentTest.kt @@ -128,7 +128,7 @@ class ProfileChooserFragmentTest { val title = activityTestRule.activity.title // Verify that the activity label is correct as a proxy to verify TalkBack will announce the // correct string when it's read out. - assertThat(title).isEqualTo(context.getString(R.string.profile_chooser_activity_label)) + assertThat(title).isEqualTo(context.getString(R.string.profile_chooser_activity_title)) } @Test