use of com.waz.zclient.pages.main.profile.views.GuidedEditText in project wire-android by wireapp.
the class CustomMatchers method guidedEditTextWithId.
/**
* Typing with regular {@link android.support.test.espresso.matcher.ViewMatchers#withId(int)} matchers won't work on a
* GuidedEditText (GET) because the GET hides the EditText which Espresso needs. This matcher searches for an edit
* text under a grandparent with the given id that has the type GET
* @param id the id of the GuidedEditText which we want to type (or perform other actions) into
* @return an Espresso compatible Matcher<View> for use in onView();
*/
public static Matcher<View> guidedEditTextWithId(final int id) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
@Override
public void describeTo(Description description) {
String idDescription = Integer.toString(id);
if (resources != null) {
try {
idDescription = resources.getResourceName(id);
} catch (Resources.NotFoundException e) {
// No big deal, will just use the int value.
idDescription = String.format("%s (resource name not found)", id);
}
}
description.appendText("with id: " + idDescription);
}
@Override
public boolean matchesSafely(View view) {
resources = view.getResources();
GuidedEditText grandParent = getGrandParent(view);
return grandParent != null && id == grandParent.getId() && view instanceof TypefaceEditText;
}
private GuidedEditText getGrandParent(View view) {
ViewParent parent = view.getParent();
if (!(parent instanceof FrameLayout)) {
return null;
}
ViewParent grandParent = parent.getParent();
if (!(grandParent instanceof GuidedEditText)) {
return null;
}
return (GuidedEditText) grandParent;
}
};
}
Aggregations