Skip to content

Commit

Permalink
different checks for visible and currently display
Browse files Browse the repository at this point in the history
  • Loading branch information
nenick committed Mar 26, 2016
1 parent 9388b56 commit bcaa3f8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

elements

* EspView - assertions for displayed on screen / state is visible, hidden, gone
* EspEditText - assertion for hint text
* EspAdapterView - click / count / assert list items
* EspListView - click / count / assert list items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ public void testAssertions() {

espView.assertIsVisible();
espView.assertIsEnabled();
espView.assertIsDisplayedOnScreen();

givenViewIsDisabled();
espView.assertIsDisabled();

givenViewIsHidden();
givenViewIsInvisible();
espView.assertIsHidden();

givenViewIsGone();
espView.assertIsHidden();
}

@Test
public void testAssertIsDisplayedOnScreenFailure() {
givenViewOutsideOfScreen(android.R.id.text2);
EspView.byId(android.R.id.text2).assertIsVisible();

exception.expect(AssertionError.class);
EspView.byId(android.R.id.text2).assertIsDisplayedOnScreen();
}

@Test
Expand Down Expand Up @@ -68,7 +81,7 @@ public void testClickSelectsOnlyVisibleView() {
espTextView.assertTextIs(VIEW_WAS_CLICKED_MESSAGE);
}

private void givenViewIsHidden() {
private void givenViewIsInvisible() {
performOnUiThread(new Runnable() {
@Override
public void run() {
Expand All @@ -77,6 +90,15 @@ public void run() {
});
}

private void givenViewIsGone() {
performOnUiThread(new Runnable() {
@Override
public void run() {
view.setVisibility(View.GONE);
}
});
}

private void givenViewIsDisabled() {
performOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -104,4 +126,14 @@ private void givenClickFeedbackTextView() {
messageView.setId(messageViewId);
addViewToActivity(messageView, BaseActivity.rootLayout);
}

private void givenViewOutsideOfScreen(int id) {
TextView textView = new TextView(getActivity());
textView.setHeight(5000);
addViewToActivity(textView, BaseActivity.rootLayout);

textView = new TextView(getActivity());
textView.setId(id);
addViewToActivity(textView, BaseActivity.rootLayout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;

import org.hamcrest.Matcher;
Expand All @@ -12,10 +13,13 @@
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.not;

public class EspView {
Expand All @@ -34,12 +38,18 @@ public EspView(Matcher<View> baseMatcher) {
this.baseMatcher = baseMatcher;
}

public void assertIsDisplayedOnScreen() {
findView().check(matches(isCompletelyDisplayed()));
}

public void assertIsVisible() {
findView().check(matches(isDisplayed()));
findView().check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
}

public void assertIsHidden() {
findView().check(matches(not(isDisplayed())));
findView().check(matches(anyOf(
withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE),
withEffectiveVisibility(ViewMatchers.Visibility.GONE))));
}

public void assertNotExist() {
Expand Down

0 comments on commit bcaa3f8

Please sign in to comment.