Skip to content

Commit

Permalink
Add test for navigating to EventLogActivity from SplashActivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Sep 2, 2020
1 parent d097d12 commit 57d71cc
Showing 1 changed file with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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
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
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class SplashActivityToEventLogTest {
@Rule
@JvmField
var mActivityScenarioRule = ActivityScenarioRule(SplashActivity::class.java)

@Test
fun splashActivityToEventLogTest() {
val imageView = onView(
allOf(withId(R.id.logo), withContentDescription("Starting…"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
0),
isDisplayed()))
imageView.perform(longClick())

val textView = onView(
allOf(withId(R.id.refresh), withContentDescription("Refresh"),
childAtPosition(
childAtPosition(
withId(R.id.action_bar),
2),
0),
isDisplayed()))
textView.check(matches(isDisplayed()))

val textView2 = onView(
allOf(withId(R.id.email_to), withContentDescription("Send as Email"),
childAtPosition(
childAtPosition(
withId(R.id.action_bar),
2),
1),
isDisplayed()))
textView2.check(matches(isDisplayed()))

val textView3 = onView(
allOf(withId(R.id.copy), withContentDescription("Copy to Clipboard"),
childAtPosition(
childAtPosition(
withId(R.id.action_bar),
2),
2),
isDisplayed()))
textView3.check(matches(isDisplayed()))

val textView4 = onView(
allOf(withText("CLIENT MESSAGES"),
childAtPosition(
childAtPosition(
IsInstanceOf.instanceOf(androidx.appcompat.widget.LinearLayoutCompat::class.java),
0),
0),
isDisplayed()))
textView4.check(matches(withText("CLIENT MESSAGES")))

val textView5 = onView(
allOf(withText("GUI MESSAGES"),
childAtPosition(
childAtPosition(
IsInstanceOf.instanceOf(androidx.appcompat.widget.LinearLayoutCompat::class.java),
1),
0),
isDisplayed()))
textView5.check(matches(withText("GUI MESSAGES")))
}

private fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> {
return object : TypeSafeMatcher<View>() {
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)
}
}
}
}

0 comments on commit 57d71cc

Please sign in to comment.