Skip to content

Commit

Permalink
Fix A11y tests for Nav Drawer Tests (oppia#3389)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajat Talesra <[email protected]>
  • Loading branch information
rt4914 and Rajat Talesra committed Jun 29, 2021
1 parent 10c3260 commit dc08959
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import org.oppia.android.R
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY
import org.oppia.android.app.home.HomeActivityPresenter
import org.oppia.android.app.home.RouteToRecentlyPlayedListener
import org.oppia.android.app.home.RouteToTopicListener
import org.oppia.android.app.home.RouteToTopicPlayStoryListener
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.topic.TopicActivity
import javax.inject.Inject

class NavigationDrawerTestActivity : InjectableAppCompatActivity(), RouteToTopicListener {
class NavigationDrawerTestActivity :
InjectableAppCompatActivity(),
RouteToTopicListener,
RouteToTopicPlayStoryListener,
RouteToRecentlyPlayedListener {
@Inject
lateinit var homeActivityPresenter: HomeActivityPresenter
private var internalProfileId: Int = -1
Expand Down Expand Up @@ -40,4 +47,24 @@ class NavigationDrawerTestActivity : InjectableAppCompatActivity(), RouteToTopic
override fun routeToTopic(internalProfileId: Int, topicId: String) {
startActivity(TopicActivity.createTopicActivityIntent(this, internalProfileId, topicId))
}

override fun routeToTopicPlayStory(internalProfileId: Int, topicId: String, storyId: String) {
startActivity(
TopicActivity.createTopicPlayStoryActivityIntent(
this,
internalProfileId,
topicId,
storyId
)
)
}

override fun routeToRecentlyPlayed() {
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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.AccessibilityTestRule
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.RunOn
import org.oppia.android.testing.TestLogReportingModule
Expand Down Expand Up @@ -120,6 +121,9 @@ import javax.inject.Singleton
)
class NavigationDrawerActivityTest {

@get:Rule
val accessibilityTestRule = AccessibilityTestRule()

@get:Rule
val oppiaTestRule = OppiaTestRule()

Expand Down Expand Up @@ -175,7 +179,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_openNavDrawer_navDrawerIsOpened() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withId(R.id.home_fragment_placeholder)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.home_activity_drawer_layout)).check(matches(isOpen()))
Expand All @@ -184,7 +190,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_openNavDrawer_configChange_navDrawerIsDisplayed() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.home_activity_drawer_layout)).check(matches(isOpen()))
Expand Down Expand Up @@ -737,7 +745,9 @@ class NavigationDrawerActivityTest {
@Test
@Ignore("My Downloads is removed until we have full download support.")
fun testNavDrawer_myDownloadsMenu_myDownloadsFragmentIsDisplayed() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_my_downloads)).perform(click())
intended(hasComponent(MyDownloadsActivity::class.java.name))
Expand All @@ -746,7 +756,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_switchProfileMenu_exitToProfileChooserDialogIsDisplayed() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message))
Expand All @@ -757,7 +769,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_switchProfileMenu_clickExit_opensProfileChooserActivity() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message))
Expand All @@ -773,7 +787,9 @@ class NavigationDrawerActivityTest {
@RunOn(TestPlatform.ESPRESSO)
@Test
fun testNavDrawer_openNavDrawerAndClose_navDrawerIsClosed() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
it.openNavigationDrawer()
onView(withId(R.id.home_activity_drawer_layout)).perform(close())
Expand All @@ -784,7 +800,9 @@ class NavigationDrawerActivityTest {
@RunOn(TestPlatform.ESPRESSO)
@Test
fun testNavDrawer_selectSwitchProfileMenu_clickCancel_navDrawerIsClosed() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message))
Expand All @@ -800,7 +818,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_selectSwitchProfile_configChange_dialogIsVisible() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_switch_profile)).perform(click())
onView(withText(R.string.home_activity_back_dialog_message))
Expand All @@ -813,7 +833,9 @@ class NavigationDrawerActivityTest {

@Test
fun testNavDrawer_openNavDrawer_selectHelpMenu_opensHelpActivity() {
launch(NavigationDrawerTestActivity::class.java).use {
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
it.openNavigationDrawer()
onView(withText(R.string.menu_help)).perform(click())
intended(hasComponent(HelpActivity::class.java.name))
Expand Down

0 comments on commit dc08959

Please sign in to comment.