|
| 1 | +package it.feio.android.omninotes; |
| 2 | + |
| 3 | + |
| 4 | +import android.support.test.espresso.ViewInteraction; |
| 5 | +import android.support.test.rule.ActivityTestRule; |
| 6 | +import android.support.test.runner.AndroidJUnit4; |
| 7 | +import android.test.suitebuilder.annotation.LargeTest; |
| 8 | +import android.view.View; |
| 9 | +import android.view.ViewGroup; |
| 10 | +import android.view.ViewParent; |
| 11 | + |
| 12 | +import org.hamcrest.Description; |
| 13 | +import org.hamcrest.Matcher; |
| 14 | +import org.hamcrest.TypeSafeMatcher; |
| 15 | +import org.hamcrest.core.IsInstanceOf; |
| 16 | +import org.junit.Rule; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.runner.RunWith; |
| 19 | + |
| 20 | +import static android.support.test.espresso.Espresso.onView; |
| 21 | +import static android.support.test.espresso.action.ViewActions.click; |
| 22 | +import static android.support.test.espresso.action.ViewActions.scrollTo; |
| 23 | +import static android.support.test.espresso.assertion.ViewAssertions.matches; |
| 24 | +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
| 25 | +import static android.support.test.espresso.matcher.ViewMatchers.withId; |
| 26 | +import static android.support.test.espresso.matcher.ViewMatchers.withParent; |
| 27 | +import static android.support.test.espresso.matcher.ViewMatchers.withText; |
| 28 | +import static org.hamcrest.Matchers.allOf; |
| 29 | +import static org.hamcrest.Matchers.startsWith; |
| 30 | + |
| 31 | +@LargeTest |
| 32 | +@RunWith(AndroidJUnit4.class) |
| 33 | +public class RemindersLifecycleTest { |
| 34 | + |
| 35 | + @Rule |
| 36 | + public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class); |
| 37 | + |
| 38 | + @Test |
| 39 | + public void remindersLifecycle() { |
| 40 | + ViewInteraction viewInteraction = onView( |
| 41 | + allOf(withId(R.id.fab_expand_menu_button), |
| 42 | + withParent(withId(R.id.fab)), |
| 43 | + isDisplayed())); |
| 44 | + viewInteraction.perform(click()); |
| 45 | + |
| 46 | + ViewInteraction floatingActionButton = onView( |
| 47 | + allOf(withId(R.id.fab_note), |
| 48 | + withParent(withId(R.id.fab)), |
| 49 | + isDisplayed())); |
| 50 | + floatingActionButton.perform(click()); |
| 51 | + |
| 52 | + ViewInteraction linearLayout = onView( |
| 53 | + withId(R.id.reminder_layout)); |
| 54 | + linearLayout.perform(scrollTo(), click()); |
| 55 | + |
| 56 | + ViewInteraction appCompatButton = onView( |
| 57 | + allOf(withId(R.id.done), withText("Done"), isDisplayed())); |
| 58 | + appCompatButton.perform(click()); |
| 59 | + |
| 60 | + ViewInteraction appCompatButton2 = onView( |
| 61 | + allOf(withId(R.id.done_button), withText("Done"), isDisplayed())); |
| 62 | + appCompatButton2.perform(click()); |
| 63 | + |
| 64 | + ViewInteraction appCompatButton3 = onView( |
| 65 | + allOf(withId(R.id.done), withText("Done"), isDisplayed())); |
| 66 | + appCompatButton3.perform(click()); |
| 67 | + |
| 68 | + ViewInteraction textView = onView(withId(R.id.datetime)); |
| 69 | + textView.check(matches(withText(startsWith("Reminder set for")))); |
| 70 | + } |
| 71 | + |
| 72 | + private static Matcher<View> childAtPosition( |
| 73 | + final Matcher<View> parentMatcher, final int position) { |
| 74 | + |
| 75 | + return new TypeSafeMatcher<View>() { |
| 76 | + @Override |
| 77 | + public void describeTo(Description description) { |
| 78 | + description.appendText("Child at position " + position + " in parent "); |
| 79 | + parentMatcher.describeTo(description); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public boolean matchesSafely(View view) { |
| 84 | + ViewParent parent = view.getParent(); |
| 85 | + return parent instanceof ViewGroup && parentMatcher.matches(parent) |
| 86 | + && view.equals(((ViewGroup) parent).getChildAt(position)); |
| 87 | + } |
| 88 | + }; |
| 89 | + } |
| 90 | +} |
0 commit comments