Skip to content

Commit

Permalink
Offer ViewPagerActions instead of SwipeActions (#53)
Browse files Browse the repository at this point in the history
* Add an Activity with a ViewPager that contains five RecyclerViews with several fruits

* Reproduce the issue #49 with tests

* Remove all tests that are also tested on RecyclerViewTest to avoid testing same behavior multiple times

* Also reproduce the issue in the method that uses the ID, not the text

* Fix the issue reproduced by the tests

* Reformat code with SquareAndroid style to pass the checkstyle rule

* Fix a Findbugs violation making a inner class static

* Avoid taking in consideration the position of the item in the nested RecyclerView tests

* Use uppercase to showcase constants at code (thanks, Checkstyle!)

* Create Matchers that just match with displayed items

* Use the new matchers on all BaristaActions that interact only with the visible widgets

* Avoid inlining the annotations

* Reverse the calls to Espresso matchers to exactly meet the method name

* Remove uneeded imports

* Offer ViewPagerActions instead of SwipeActions, to meet Barista's naming

* Remove unneeded SwipeActions, added by a bad merge
  • Loading branch information
rocboronat authored May 10, 2017
1 parent 6f995ac commit 6d98b80
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ clickDialogNegativeButton();
// Scroll on scrolls and pagers
scrollTo(R.id.button);
scrollTo("A widget with this text");
swipePagerForward(R.id.pager);
swipePagerBack(R.id.pager);
swipeViewPagerForward(R.id.pager);
swipeViewPagerBack(R.id.pager);

// Interact with the navigation drawer
openDrawer(R.id.drawer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static com.schibsted.spain.barista.custom.DisplayedMatchers.displayedWithId;

public class BaristaSwipeActions {
public class BaristaViewPagerActions {

public static void swipePagerForward(@IdRes int id) {
public static void swipeViewPagerForward(@IdRes int id) {
onView(displayedWithId(id)).perform(swipeLeft());
}

public static void swipePagerBack(@IdRes int id) {
public static void swipeViewPagerBack(@IdRes int id) {
onView(displayedWithId(id)).perform(swipeRight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.junit.runner.RunWith;

import static com.schibsted.spain.barista.BaristaAssertions.assertDisplayed;
import static com.schibsted.spain.barista.BaristaSwipeActions.swipePagerBack;
import static com.schibsted.spain.barista.BaristaSwipeActions.swipePagerForward;
import static com.schibsted.spain.barista.BaristaViewPagerActions.swipeViewPagerBack;
import static com.schibsted.spain.barista.BaristaViewPagerActions.swipeViewPagerForward;

@RunWith(AndroidJUnit4.class)
public class ViewPagerTest {
Expand All @@ -19,30 +19,30 @@ public class ViewPagerTest {

@Test
public void checkSwipeForward() {
swipePagerForward(R.id.pager);
swipeViewPagerForward(R.id.pager);

assertDisplayed("2");
}

@Test
public void checkSwipeBack() {
swipePagerForward(R.id.pager);
swipePagerBack(R.id.pager);
swipeViewPagerForward(R.id.pager);
swipeViewPagerBack(R.id.pager);

assertDisplayed("1");
}

@Test
public void swipingBackInTheFirstPageDoesntCrash() {
swipePagerBack(R.id.pager);
swipeViewPagerBack(R.id.pager);

assertDisplayed("1");
}

@Test
public void swipingForwardInTheLastPageDoesntCrash() {
swipePagerForward(R.id.pager);
swipePagerForward(R.id.pager);
swipeViewPagerForward(R.id.pager);
swipeViewPagerForward(R.id.pager);

assertDisplayed("2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import static com.schibsted.spain.barista.BaristaScrollActions.scrollTo;
import static com.schibsted.spain.barista.BaristaSleepActions.sleep;
import static com.schibsted.spain.barista.BaristaSpinnerActions.clickSpinnerItem;
import static com.schibsted.spain.barista.BaristaSwipeActions.swipePagerBack;
import static com.schibsted.spain.barista.BaristaSwipeActions.swipePagerForward;
import static com.schibsted.spain.barista.BaristaViewPagerActions.swipeViewPagerBack;
import static com.schibsted.spain.barista.BaristaViewPagerActions.swipeViewPagerForward;
import static java.util.concurrent.TimeUnit.SECONDS;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -75,8 +75,8 @@ public void letsIntroduceBarista() {
// Scroll on scrolls and pagers
scrollTo(R.id.button);
scrollTo("A widget with this text");
swipePagerForward(R.id.pager);
swipePagerBack(R.id.pager);
swipeViewPagerForward(R.id.pager);
swipeViewPagerBack(R.id.pager);

// Interact with the navigation drawer
openDrawer(R.id.drawer);
Expand Down

0 comments on commit 6d98b80

Please sign in to comment.