Skip to content

Commit cc6e86a

Browse files
Add test for BOINCActivity and its fragments.
1 parent 57d71cc commit cc6e86a

File tree

3 files changed

+166
-20
lines changed

3 files changed

+166
-20
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package edu.berkeley.boinc
2+
3+
import androidx.test.espresso.Espresso.onView
4+
import androidx.test.espresso.action.ViewActions.click
5+
import androidx.test.espresso.assertion.ViewAssertions.matches
6+
import androidx.test.espresso.matcher.ViewMatchers.*
7+
import androidx.test.ext.junit.rules.ActivityScenarioRule
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import androidx.test.filters.LargeTest
10+
import org.hamcrest.Matchers.allOf
11+
import org.hamcrest.core.IsInstanceOf
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
// Disable BOINC notifications (or just the main channel on Oreo and higher) before running this test, as
17+
// the client notification can cover the hamburger button during test execution and cause the test to fail.
18+
@LargeTest
19+
@RunWith(AndroidJUnit4::class)
20+
class BOINCActivityTest {
21+
@Rule
22+
@JvmField
23+
var mActivityScenarioRule = ActivityScenarioRule(BOINCActivity::class.java)
24+
25+
@Test
26+
fun boincActivityTest() {
27+
val textView = onView(
28+
allOf(withText(R.string.tab_tasks),
29+
withParent(allOf(withId(R.id.action_bar),
30+
withParent(withId(R.id.action_bar_container)))),
31+
isDisplayed()))
32+
textView.check(matches(withText(R.string.tab_tasks)))
33+
34+
val appCompatImageButton = onView(
35+
allOf(withContentDescription("BOINC"),
36+
childAtPosition(
37+
allOf(withId(R.id.action_bar),
38+
childAtPosition(
39+
withId(R.id.action_bar_container),
40+
0)),
41+
1),
42+
isDisplayed()))
43+
appCompatImageButton.perform(click())
44+
45+
val viewInteraction = onView(allOf(withText(R.string.tab_notices), isDisplayed()))
46+
viewInteraction.perform(click())
47+
48+
val textView2 = onView(
49+
allOf(withText(R.string.tab_notices),
50+
withParent(allOf(withId(R.id.action_bar),
51+
withParent(withId(R.id.action_bar_container)))),
52+
isDisplayed()))
53+
textView2.check(matches(withText(R.string.tab_notices)))
54+
55+
appCompatImageButton.perform(click())
56+
57+
val viewInteraction2 = onView(allOf(withText(R.string.tab_projects), isDisplayed()))
58+
viewInteraction2.perform(click())
59+
60+
val textView3 = onView(
61+
allOf(withText(R.string.tab_projects),
62+
withParent(allOf(withId(R.id.action_bar),
63+
withParent(withId(R.id.action_bar_container)))),
64+
isDisplayed()))
65+
textView3.check(matches(withText(R.string.tab_projects)))
66+
67+
appCompatImageButton.perform(click())
68+
69+
val viewInteraction3 = onView(allOf(withText(R.string.tab_preferences), isDisplayed()))
70+
viewInteraction3.perform(click())
71+
72+
val textView4 = onView(
73+
allOf(withText(R.string.tab_preferences),
74+
withParent(allOf(withId(R.id.action_bar),
75+
withParent(withId(R.id.action_bar_container)))),
76+
isDisplayed()))
77+
textView4.check(matches(withText(R.string.tab_preferences)))
78+
79+
appCompatImageButton.perform(click())
80+
81+
val viewInteraction4 = onView(allOf(withText(R.string.menu_about), isDisplayed()))
82+
viewInteraction4.perform(click())
83+
84+
val textView5 = onView(
85+
allOf(withId(R.id.title), withText(R.string.menu_about),
86+
withParent(withParent(withId(android.R.id.content))),
87+
isDisplayed()))
88+
textView5.check(matches(withText(R.string.menu_about)))
89+
90+
val appCompatButton = onView(
91+
allOf(withId(R.id.returnB), withText(R.string.about_button),
92+
childAtPosition(
93+
childAtPosition(
94+
withId(android.R.id.content),
95+
0),
96+
6),
97+
isDisplayed()))
98+
appCompatButton.perform(click())
99+
100+
appCompatImageButton.perform(click())
101+
102+
val viewInteraction5 = onView(allOf(withText(R.string.menu_eventlog), isDisplayed()))
103+
viewInteraction5.perform(click())
104+
105+
val textView6 = onView(
106+
allOf(withText(R.string.menu_eventlog),
107+
withParent(allOf(withId(R.id.action_bar),
108+
withParent(withId(R.id.action_bar_container)))),
109+
isDisplayed()))
110+
textView6.check(matches(withText(R.string.menu_eventlog)))
111+
112+
val textView7 = onView(
113+
allOf(withText(R.string.eventlog_client_header),
114+
withParent(allOf(withContentDescription(R.string.eventlog_client_header),
115+
withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout::class.java)))),
116+
isDisplayed()))
117+
textView7.check(matches(withText(R.string.eventlog_client_header)))
118+
119+
val textView8 = onView(
120+
allOf(withText(R.string.eventlog_gui_header),
121+
withParent(allOf(withContentDescription(R.string.eventlog_gui_header),
122+
withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout::class.java)))),
123+
isDisplayed()))
124+
textView8.check(matches(withText(R.string.eventlog_gui_header)))
125+
126+
val appCompatImageButton2 = onView(
127+
allOf(withContentDescription("Navigate up"),
128+
childAtPosition(
129+
allOf(withId(R.id.action_bar),
130+
childAtPosition(
131+
withId(R.id.action_bar_container),
132+
0)),
133+
1),
134+
isDisplayed()))
135+
appCompatImageButton2.perform(click())
136+
137+
val textView9 = onView(
138+
allOf(withText(R.string.tab_tasks),
139+
withParent(allOf(withId(R.id.action_bar),
140+
withParent(withId(R.id.action_bar_container)))),
141+
isDisplayed()))
142+
textView9.check(matches(withText(R.string.tab_tasks)))
143+
}
144+
}

android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
package edu.berkeley.boinc
22

3-
import android.view.View
4-
import android.view.ViewGroup
53
import androidx.test.espresso.Espresso.onView
64
import androidx.test.espresso.action.ViewActions.longClick
75
import androidx.test.espresso.assertion.ViewAssertions.matches
86
import androidx.test.espresso.matcher.ViewMatchers.*
97
import androidx.test.ext.junit.rules.ActivityScenarioRule
108
import androidx.test.ext.junit.runners.AndroidJUnit4
119
import androidx.test.filters.LargeTest
12-
import org.hamcrest.Description
13-
import org.hamcrest.Matcher
1410
import org.hamcrest.Matchers.allOf
15-
import org.hamcrest.TypeSafeMatcher
1611
import org.hamcrest.core.IsInstanceOf
1712
import org.junit.Rule
1813
import org.junit.Test
@@ -87,19 +82,4 @@ class SplashActivityToEventLogTest {
8782
isDisplayed()))
8883
textView5.check(matches(withText("GUI MESSAGES")))
8984
}
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-
}
10585
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package edu.berkeley.boinc
2+
3+
import android.view.View
4+
import android.view.ViewGroup
5+
import org.hamcrest.Description
6+
import org.hamcrest.Matcher
7+
import org.hamcrest.TypeSafeMatcher
8+
9+
fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> {
10+
return object : TypeSafeMatcher<View>() {
11+
override fun describeTo(description: Description) {
12+
description.appendText("Child at position $position in parent ")
13+
parentMatcher.describeTo(description)
14+
}
15+
16+
public override fun matchesSafely(view: View): Boolean {
17+
val parent = view.parent
18+
return parent is ViewGroup && parentMatcher.matches(parent)
19+
&& view == parent.getChildAt(position)
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)