...
  View open merge request
Commits (1)
package eu.uwot.fabio.altcoinprices;
import android.os.SystemClock;
import android.support.test.espresso.DataInteraction;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.pressImeActionButton;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
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.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ManagePortfolioTest {
@Rule
public ActivityTestRule<LoadingActivity> mActivityTestRule = new ActivityTestRule<>(LoadingActivity.class);
@Test
public void loadingActivityTest2() {
SystemClock.sleep(3000);
onView(allOf(withId(R.id.action_addNew), isDisplayed())).perform(click());
onView(withId(R.id.amountBought_text)).perform(scrollTo(), replaceText("1"), closeSoftKeyboard());
onView(withId(R.id.unitPrice_text)).perform(scrollTo(), replaceText("6000"), closeSoftKeyboard());
onView(withId(R.id.currency_spinner)).perform(scrollTo(), click());
DataInteraction appCompatCheckedTextView = onData(anything())
.inAdapterView(childAtPosition(
withClassName(is("android.widget.PopupWindow$PopupBackgroundView")),
0))
.atPosition(1);
appCompatCheckedTextView.perform(click());
onView(allOf(withId(R.id.saveButton), withText("Save"), isDisplayed())).perform(click());
SystemClock.sleep(3000);
ViewInteraction viewGroup = onView(
allOf(childAtPosition(
childAtPosition(
withId(R.id.portfolioItems),
0),
0),
isDisplayed()));
viewGroup.check(matches(isDisplayed()));
viewGroup.perform(longClick());
onView(allOf(withId(R.id.tradingviewTradingPair), withText("Unit price (USD)"),
isDisplayed())).perform(closeSoftKeyboard());
onView(allOf(withId(R.id.amountBought_text))).perform(scrollTo(), replaceText("0.5"), closeSoftKeyboard());
onView(allOf(withId(R.id.saveButton), withText("Save"), isDisplayed())).perform(click());
ViewInteraction viewGroup2 = onView(
allOf(childAtPosition(
childAtPosition(
withId(R.id.portfolioItems),
0),
0),
isDisplayed()));
viewGroup2.check(matches(isDisplayed()));
viewGroup2.perform(longClick());
onView(allOf(withId(R.id.tradingviewTradingPair), withText("Unit price (USD)"),
isDisplayed())).perform(closeSoftKeyboard());
onView(allOf(withId(R.id.amountBought_text))).perform(pressImeActionButton());
onView(allOf(withId(R.id.removeButton), withText("Remove"), isDisplayed())).perform(click());
onView(allOf(withId(R.id.portfolioBalance), withText("0 €"), isDisplayed())).check(matches(withText("0 €")));
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}