Added tests for the settings UI

This commit is contained in:
Joachim Dunant 2020-03-12 17:36:57 +01:00
parent 26427d5377
commit 191a499a04
1 changed files with 20 additions and 7 deletions

View File

@ -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")))
}
}