From 191a499a04acf9ced91779d7da0f11ed21ce9f4c Mon Sep 17 00:00:00 2001 From: Joachim Dunant Date: Thu, 12 Mar 2020 17:36:57 +0100 Subject: [PATCH] Added tests for the settings UI --- .../java/com/h/pixeldroid/SettingsTest.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/com/h/pixeldroid/SettingsTest.kt b/app/src/androidTest/java/com/h/pixeldroid/SettingsTest.kt index 8ba6984f..8a1fc3f9 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/SettingsTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/SettingsTest.kt @@ -2,11 +2,8 @@ package com.h.pixeldroid import android.view.Gravity import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.ViewAction -import androidx.test.espresso.action.CoordinatesProvider -import androidx.test.espresso.action.GeneralClickAction -import androidx.test.espresso.action.Press -import androidx.test.espresso.action.Tap +import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.DrawerActions import androidx.test.espresso.contrib.DrawerMatchers.isClosed @@ -32,7 +29,7 @@ class SettingsTest { .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. .perform(DrawerActions.open()); // Open Drawer - // Start the screen of your activity. + // Start the screen of the activity. onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_settings)) // Check that settings activity was opened. @@ -46,10 +43,26 @@ class SettingsTest { .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. .perform(DrawerActions.open()); // Open Drawer - // Start the screen of your activity. + // Start the screen of the activity. onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_account)) // Check that profile activity was opened. onView(withId(R.id.posts)).check(matches(withText("Posts"))) } + + @Test + fun testOnBackPressed() { + // Open Drawer to click on navigation. + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + // Start the screen of your activity. + onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_settings)) + + onView(withId(R.id.settings)).perform(ViewActions.pressBack()) + + // Check that profile activity was opened. + onView(withId(R.id.button_start_login)).check(matches(withText("start login"))) + } } \ No newline at end of file