|
| 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 | +} |
0 commit comments