diff --git a/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/BOINCActivityTest.kt b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/BOINCActivityTest.kt new file mode 100644 index 00000000000..97fee1a4ddb --- /dev/null +++ b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/BOINCActivityTest.kt @@ -0,0 +1,152 @@ +/* + * This file is part of BOINC. + * http://boinc.berkeley.edu + * Copyright (C) 2020 University of California + * + * BOINC is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * BOINC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with BOINC. If not, see . + */ +package edu.berkeley.boinc + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.hamcrest.Matchers.allOf +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class BOINCActivityTest { + @Rule + @JvmField + var mActivityScenarioRule = ActivityScenarioRule(BOINCActivity::class.java) + + @Test + fun boincActivityTest() { + val appCompatImageButton = onView( + allOf(withContentDescription("Navigate up"), + childAtPosition( + allOf(withId(R.id.action_bar), + childAtPosition( + withId(R.id.action_bar_container), + 0)), + 1), + isDisplayed())) + appCompatImageButton.perform(click()) + + val textView = onView( + allOf(withId(R.id.title), withText("Tasks"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 0)), + 1), + isDisplayed())) + textView.check(matches(withText("Tasks"))) + + val textView2 = onView( + allOf(withId(R.id.title), withText("Notices"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 1)), + 1), + isDisplayed())) + textView2.check(matches(withText("Notices"))) + + val textView3 = onView( + allOf(withId(R.id.title), withText("Projects"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 2)), + 1), + isDisplayed())) + textView3.check(matches(withText("Projects"))) + + val textView4 = onView( + allOf(withId(R.id.title), withText("Add project"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 3)), + 1), + isDisplayed())) + textView4.check(matches(withText("Add project"))) + + val textView5 = onView( + allOf(withId(R.id.title), withText("Preferences"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 4)), + 1), + isDisplayed())) + textView5.check(matches(withText("Preferences"))) + + val textView6 = onView( + allOf(withId(R.id.title), withText("Help"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 5)), + 1), + isDisplayed())) + textView6.check(matches(withText("Help"))) + + val textView7 = onView( + allOf(withId(R.id.title), withText("Report Issue"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 6)), + 1), + isDisplayed())) + textView7.check(matches(withText("Report Issue"))) + + val textView8 = onView( + allOf(withId(R.id.title), withText("About"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 7)), + 1), + isDisplayed())) + textView8.check(matches(withText("About"))) + + val textView9 = onView( + allOf(withId(R.id.title), withText("Event Log"), + childAtPosition( + allOf(withId(R.id.listitem), + childAtPosition( + withId(R.id.list_slidermenu), + 8)), + 1), + isDisplayed())) + textView9.check(matches(withText("Event Log"))) + } +} diff --git a/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt index aab615aea97..8e37cf4bf13 100644 --- a/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt +++ b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt @@ -1,7 +1,23 @@ +/* + * This file is part of BOINC. + * http://boinc.berkeley.edu + * Copyright (C) 2020 University of California + * + * BOINC is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * BOINC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with BOINC. If not, see . + */ package edu.berkeley.boinc -import android.view.View -import android.view.ViewGroup import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.assertion.ViewAssertions.matches @@ -9,10 +25,7 @@ import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest -import org.hamcrest.Description -import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf -import org.hamcrest.TypeSafeMatcher import org.hamcrest.core.IsInstanceOf import org.junit.Rule import org.junit.Test @@ -87,19 +100,4 @@ class SplashActivityToEventLogTest { isDisplayed())) textView5.check(matches(withText("GUI MESSAGES"))) } - - private fun childAtPosition(parentMatcher: Matcher, position: Int): Matcher { - return object : TypeSafeMatcher() { - override fun describeTo(description: Description) { - description.appendText("Child at position $position in parent ") - parentMatcher.describeTo(description) - } - - public override fun matchesSafely(view: View): Boolean { - val parent = view.parent - return parent is ViewGroup && parentMatcher.matches(parent) - && view == parent.getChildAt(position) - } - } - } } diff --git a/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/TestUtils.kt b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/TestUtils.kt new file mode 100644 index 00000000000..5a50e6c079c --- /dev/null +++ b/android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/TestUtils.kt @@ -0,0 +1,40 @@ +/* + * This file is part of BOINC. + * http://boinc.berkeley.edu + * Copyright (C) 2020 University of California + * + * BOINC is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * BOINC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with BOINC. If not, see . + */ +package edu.berkeley.boinc + +import android.view.View +import android.view.ViewGroup +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.TypeSafeMatcher + +fun childAtPosition(parentMatcher: Matcher, position: Int): Matcher { + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } +}