|
| 1 | +package edu.berkeley.boinc |
| 2 | + |
| 3 | +import android.view.View |
| 4 | +import android.view.ViewGroup |
| 5 | +import androidx.test.espresso.Espresso.onView |
| 6 | +import androidx.test.espresso.action.ViewActions.longClick |
| 7 | +import androidx.test.espresso.assertion.ViewAssertions.matches |
| 8 | +import androidx.test.espresso.matcher.ViewMatchers.* |
| 9 | +import androidx.test.ext.junit.rules.ActivityScenarioRule |
| 10 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 11 | +import androidx.test.filters.LargeTest |
| 12 | +import org.hamcrest.Description |
| 13 | +import org.hamcrest.Matcher |
| 14 | +import org.hamcrest.Matchers.allOf |
| 15 | +import org.hamcrest.TypeSafeMatcher |
| 16 | +import org.hamcrest.core.IsInstanceOf |
| 17 | +import org.junit.Rule |
| 18 | +import org.junit.Test |
| 19 | +import org.junit.runner.RunWith |
| 20 | + |
| 21 | +@LargeTest |
| 22 | +@RunWith(AndroidJUnit4::class) |
| 23 | +class SplashActivityToEventLogTest { |
| 24 | + @Rule |
| 25 | + @JvmField |
| 26 | + var mActivityScenarioRule = ActivityScenarioRule(SplashActivity::class.java) |
| 27 | + |
| 28 | + @Test |
| 29 | + fun splashActivityToEventLogTest() { |
| 30 | + val imageView = onView( |
| 31 | + allOf(withId(R.id.logo), withContentDescription("Starting…"), |
| 32 | + childAtPosition( |
| 33 | + childAtPosition( |
| 34 | + withId(android.R.id.content), |
| 35 | + 0), |
| 36 | + 0), |
| 37 | + isDisplayed())) |
| 38 | + imageView.perform(longClick()) |
| 39 | + |
| 40 | + val textView = onView( |
| 41 | + allOf(withId(R.id.refresh), withContentDescription("Refresh"), |
| 42 | + childAtPosition( |
| 43 | + childAtPosition( |
| 44 | + withId(R.id.action_bar), |
| 45 | + 2), |
| 46 | + 0), |
| 47 | + isDisplayed())) |
| 48 | + textView.check(matches(isDisplayed())) |
| 49 | + |
| 50 | + val textView2 = onView( |
| 51 | + allOf(withId(R.id.email_to), withContentDescription("Send as Email"), |
| 52 | + childAtPosition( |
| 53 | + childAtPosition( |
| 54 | + withId(R.id.action_bar), |
| 55 | + 2), |
| 56 | + 1), |
| 57 | + isDisplayed())) |
| 58 | + textView2.check(matches(isDisplayed())) |
| 59 | + |
| 60 | + val textView3 = onView( |
| 61 | + allOf(withId(R.id.copy), withContentDescription("Copy to Clipboard"), |
| 62 | + childAtPosition( |
| 63 | + childAtPosition( |
| 64 | + withId(R.id.action_bar), |
| 65 | + 2), |
| 66 | + 2), |
| 67 | + isDisplayed())) |
| 68 | + textView3.check(matches(isDisplayed())) |
| 69 | + |
| 70 | + val textView4 = onView( |
| 71 | + allOf(withText("CLIENT MESSAGES"), |
| 72 | + childAtPosition( |
| 73 | + childAtPosition( |
| 74 | + IsInstanceOf.instanceOf(androidx.appcompat.widget.LinearLayoutCompat::class.java), |
| 75 | + 0), |
| 76 | + 0), |
| 77 | + isDisplayed())) |
| 78 | + textView4.check(matches(withText("CLIENT MESSAGES"))) |
| 79 | + |
| 80 | + val textView5 = onView( |
| 81 | + allOf(withText("GUI MESSAGES"), |
| 82 | + childAtPosition( |
| 83 | + childAtPosition( |
| 84 | + IsInstanceOf.instanceOf(androidx.appcompat.widget.LinearLayoutCompat::class.java), |
| 85 | + 1), |
| 86 | + 0), |
| 87 | + isDisplayed())) |
| 88 | + textView5.check(matches(withText("GUI MESSAGES"))) |
| 89 | + } |
| 90 | + |
| 91 | + private fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> { |
| 92 | + return object : TypeSafeMatcher<View>() { |
| 93 | + override fun describeTo(description: Description) { |
| 94 | + description.appendText("Child at position $position in parent ") |
| 95 | + parentMatcher.describeTo(description) |
| 96 | + } |
| 97 | + |
| 98 | + public override fun matchesSafely(view: View): Boolean { |
| 99 | + val parent = view.parent |
| 100 | + return parent is ViewGroup && parentMatcher.matches(parent) |
| 101 | + && view == parent.getChildAt(position) |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments