use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.
the class TabLayoutTest method testSetScrollPosition.
private void testSetScrollPosition(final boolean isLtr) throws Throwable {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activityTestRule.getActivity().setContentView(R.layout.design_tabs_fixed_width);
}
});
final TabLayout tabs = (TabLayout) activityTestRule.getActivity().findViewById(R.id.tabs);
assertEquals(TabLayout.MODE_SCROLLABLE, tabs.getTabMode());
final TabLayoutScrollIdlingResource idler = new TabLayoutScrollIdlingResource(tabs);
Espresso.registerIdlingResources(idler);
// We're going to call setScrollPosition() incrementally, as if scrolling between one tab
// and the next. Use the middle tab for best results. The positionOffsets should be in the
// range [0, 1), so the final call will wrap to 0 but use the next tab's position.
final int middleTab = tabs.getTabCount() / 2;
final int[] positions = { middleTab, middleTab, middleTab, middleTab, middleTab + 1 };
final float[] positionOffsets = { 0f, .25f, .5f, .75f, 0f };
// Set layout direction
onView(withId(R.id.tabs)).perform(setLayoutDirection(isLtr ? ViewCompat.LAYOUT_DIRECTION_LTR : ViewCompat.LAYOUT_DIRECTION_RTL));
// Make sure it's scrolled all the way to the start
onView(withId(R.id.tabs)).perform(selectTab(0));
// Perform a series of setScrollPosition() calls
final AtomicInteger lastScrollX = new AtomicInteger(tabs.getScrollX());
for (int i = 0; i < positions.length; i++) {
onView(withId(R.id.tabs)).perform(setScrollPosition(positions[i], positionOffsets[i])).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException notFoundException) {
if (view == null) {
throw notFoundException;
}
// Verify increasing or decreasing scroll X values
int sx = view.getScrollX();
assertTrue(isLtr ? sx > lastScrollX.get() : sx < lastScrollX.get());
lastScrollX.set(sx);
}
});
}
Espresso.unregisterIdlingResources(idler);
}
use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testInvisibleThenVisible.
@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
// The bottom sheet is initially invisible
getBottomSheet().setVisibility(View.INVISIBLE);
// Then it becomes visible when the CoL is touched
getCoordinatorLayout().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
getBottomSheet().setVisibility(View.VISIBLE);
return true;
}
return false;
}
});
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
});
// Drag over the CoL
Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
// The bottom sheet should not react to the touch events
assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
});
}
use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.
the class BottomSheetBehaviorTouchTest method testTouchCoordinatorLayout.
@Test
public void testTouchCoordinatorLayout() {
final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
mDown = false;
Espresso.onView(sameInstance((View) activity.mCoordinatorLayout)).perform(// Click outside the bottom sheet
ViewActions.click()).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
assertThat(e, is(nullValue()));
assertThat(view, is(notNullValue()));
// Check that the touch event fell through to the container
assertThat(mDown, is(true));
}
});
}
use of android.support.test.espresso.NoMatchingViewException in project wire-android by wireapp.
the class UsernameEditFragmentTest method assertShortUsernameShowsError.
@Test
public void assertShortUsernameShowsError() throws InterruptedException {
String currentUsername = "";
attachFragment(ChangeUsernamePreferenceDialogFragment.newInstance(currentUsername, true), ChangeUsernamePreferenceDialogFragment.TAG);
Thread.sleep(400);
onView(withId(R.id.acet__change_username)).perform(typeTextIntoFocusedView("1"));
Thread.sleep(400);
onView(withId(R.id.til__change_username)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CharSequence error = ((TextInputLayout) view).getError();
if (error == null || error.length() == 0) {
throw new AssertionFailedError("Error field is empty");
}
}
});
}
use of android.support.test.espresso.NoMatchingViewException in project wire-android by wireapp.
the class UsernameEditFragmentTest method assertInvalidUsernameCantBeSet.
@Test
public void assertInvalidUsernameCantBeSet() throws InterruptedException {
String currentUsername = "";
attachFragment(ChangeUsernamePreferenceDialogFragment.newInstance(currentUsername, true), ChangeUsernamePreferenceDialogFragment.TAG);
Thread.sleep(400);
onView(withId(R.id.acet__change_username)).perform(typeTextIntoFocusedView("1"));
Thread.sleep(400);
onView(withId(R.id.til__change_username)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (!view.isEnabled()) {
throw new AssertionFailedError("View is enabled");
}
}
});
}
Aggregations