Use Espresso-Intents to check started Activities
This commit is contained in:
@@ -71,7 +71,9 @@ dependencies {
|
||||
|
||||
// Testing-only dependencies
|
||||
androidTestCompile 'com.android.support.test:runner:0.3'
|
||||
androidTestCompile 'com.android.support.test:rules:0.3'
|
||||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
|
||||
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
|
||||
}
|
||||
|
||||
dependencyVerification {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package i2p.bote.android;
|
||||
|
||||
import android.support.test.espresso.NoMatchingViewException;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.espresso.intent.matcher.IntentMatchers;
|
||||
import android.support.test.espresso.intent.rule.IntentsTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
|
||||
@@ -10,20 +11,20 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import i2p.bote.android.config.SettingsActivity;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
||||
import static android.support.test.espresso.Espresso.pressBack;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeDown;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeRight;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.intent.Intents.intended;
|
||||
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@@ -31,7 +32,7 @@ import static org.hamcrest.Matchers.not;
|
||||
public class EmailListActivityTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<EmailListActivity> mActivityRule = new ActivityTestRule<>(EmailListActivity.class);
|
||||
public IntentsTestRule<EmailListActivity> mActivityRule = new IntentsTestRule<>(EmailListActivity.class);
|
||||
|
||||
@Before
|
||||
public void closeIntro() {
|
||||
@@ -45,21 +46,6 @@ public class EmailListActivityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openActionMenuItems() {
|
||||
// Open settings menu
|
||||
openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());
|
||||
onView(withText(R.string.action_settings)).perform(click());
|
||||
onView(allOf(withParent(withId(R.id.main_toolbar)), withText(R.string.action_settings))).check(matches(isDisplayed()));
|
||||
pressBack();
|
||||
|
||||
// Open help menu
|
||||
openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());
|
||||
onView(withText(R.string.help)).perform(click());
|
||||
onView(allOf(withParent(withId(R.id.main_toolbar)), withText(R.string.help))).check(matches(isDisplayed()));
|
||||
pressBack();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkEmailFromActionMenuWhenNotConnected() {
|
||||
openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());
|
||||
@@ -72,4 +58,24 @@ public class EmailListActivityTest {
|
||||
onView(withId(R.id.swipe_refresh)).perform(swipeDown());
|
||||
onView(withText(R.string.bote_needs_to_be_connected)).inRoot(withDecorView(not(mActivityRule.getActivity().getWindow().getDecorView()))) .check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newEmail() {
|
||||
onView(withId(R.id.promoted_action)).perform(click());
|
||||
intended(IntentMatchers.hasComponent(NewEmailActivity.class.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSettings() {
|
||||
openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());
|
||||
onView(withText(R.string.action_settings)).perform(click());
|
||||
intended(IntentMatchers.hasComponent(SettingsActivity.class.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openHelp() {
|
||||
openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());
|
||||
onView(withText(R.string.help)).perform(click());
|
||||
intended(IntentMatchers.hasComponent(HelpActivity.class.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user