-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for navigating to EventLogActivity from SplashActivity.
- Loading branch information
1 parent
d097d12
commit 57d71cc
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |