diff --git a/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaClickInteractions.kt b/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaClickInteractions.kt
index dc3bac132..4d534c04a 100644
--- a/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaClickInteractions.kt
+++ b/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaClickInteractions.kt
@@ -3,18 +3,23 @@ package com.schibsted.spain.barista.interaction
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.Espresso.pressBack
import android.support.test.espresso.ViewAction
-import android.support.test.espresso.action.ViewActions.*
-import android.support.test.espresso.matcher.ViewMatchers.*
+import android.support.test.espresso.action.ViewActions.click
+import android.support.test.espresso.action.ViewActions.longClick
+import android.support.test.espresso.action.ViewActions.scrollTo
+import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom
+import android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA
+import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
+import android.support.test.espresso.matcher.ViewMatchers.withText
import android.support.v4.widget.NestedScrollView
import android.view.View
+import android.widget.AbsListView
import android.widget.HorizontalScrollView
-import android.widget.ListView
import android.widget.ScrollView
-import com.schibsted.spain.barista.internal.matcher.DisplayedMatchers.displayedAnd
-import com.schibsted.spain.barista.internal.viewaction.NestedEnabledScrollToAction.nestedScrollToAction
import com.schibsted.spain.barista.internal.failurehandler.SpyFailureHandler
import com.schibsted.spain.barista.internal.failurehandler.description
+import com.schibsted.spain.barista.internal.matcher.DisplayedMatchers.displayedAnd
import com.schibsted.spain.barista.internal.util.resourceMatcher
+import com.schibsted.spain.barista.internal.viewaction.NestedEnabledScrollToAction.nestedScrollToAction
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.anyOf
@@ -75,7 +80,7 @@ object BaristaClickInteractions {
anyOf(
isAssignableFrom(ScrollView::class.java),
isAssignableFrom(HorizontalScrollView::class.java),
- isAssignableFrom(ListView::class.java),
+ isAssignableFrom(AbsListView::class.java),
isAssignableFrom(NestedScrollView::class.java)
)
))
diff --git a/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaListInteractions.kt b/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaListInteractions.kt
index a45dc81fd..8a5fa57fb 100644
--- a/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaListInteractions.kt
+++ b/library/src/main/java/com/schibsted/spain/barista/interaction/BaristaListInteractions.kt
@@ -12,15 +12,19 @@ import android.support.test.espresso.action.ViewActions.scrollTo
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
import android.support.test.espresso.contrib.RecyclerViewActions.scrollToPosition
-import android.support.test.espresso.matcher.ViewMatchers.*
+import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom
+import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
+import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.RecyclerView.ViewHolder
-import android.widget.ListView
+import android.widget.AbsListView
import com.schibsted.spain.barista.internal.failurehandler.SpyFailureHandler
import com.schibsted.spain.barista.internal.failurehandler.withFailureHandler
import com.schibsted.spain.barista.internal.viewaction.ClickChildAction.clickChildWithId
import com.schibsted.spain.barista.internal.viewaction.PerformClickAction.clickUsingPerformClick
-import org.hamcrest.Matchers.*
+import org.hamcrest.Matchers.allOf
+import org.hamcrest.Matchers.anyOf
+import org.hamcrest.Matchers.anything
object BaristaListInteractions {
@@ -101,8 +105,8 @@ object BaristaListInteractions {
}
private fun findListViewMatcher(@IdRes id: Int?) = when (id) {
- null -> allOf(isDisplayed(), isAssignableFrom(ListView::class.java))
- else -> allOf(isDisplayed(), isAssignableFrom(ListView::class.java), withId(id))
+ null -> allOf(isDisplayed(), isAssignableFrom(AbsListView::class.java))
+ else -> allOf(isDisplayed(), isAssignableFrom(AbsListView::class.java), withId(id))
}
private fun resourceName(resId: Int) = InstrumentationRegistry.getTargetContext().resources.getResourceName(resId)
diff --git a/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsChildClickTest.java b/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsChildClickTest.java
index 6f6a53d7e..29c3abbe8 100644
--- a/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsChildClickTest.java
+++ b/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsChildClickTest.java
@@ -47,6 +47,17 @@ public void clickListViewItemChild() throws Exception {
assertResult("yes");
}
+
+ @Test
+ public void clickGridViewItemChild() throws Exception {
+ openActivity(ListsActivity.buildIntent()
+ .withComplexGrids(R.id.gridview)
+ );
+
+ clickListItemChild(20, R.id.yes);
+
+ assertResult("yes");
+ }
@Test
public void clickMultipleRecyclerItemChild_byId() throws Exception {
openActivity(ListsActivity.buildIntent()
@@ -69,6 +80,17 @@ public void clickMultipleListViewItemChild_byId() throws Exception {
assertResult("yes");
}
+ @Test
+ public void clickMultipleGridViewItemChild_byId() throws Exception {
+ openActivity(ListsActivity.buildIntent()
+ .withComplexGrids(R.id.gridview, R.id.gridview2)
+ );
+
+ clickListItemChild(R.id.gridview, 20, R.id.yes);
+
+ assertResult("yes");
+ }
+
@Test(expected = PerformException.class)
public void fails_whenListViewChildNotExist() throws Exception {
openActivity(ListsActivity.buildIntent()
@@ -80,6 +102,17 @@ public void fails_whenListViewChildNotExist() throws Exception {
assertResult("");
}
+ @Test(expected = PerformException.class)
+ public void fails_whenGridViewChildNotExist() throws Exception {
+ openActivity(ListsActivity.buildIntent()
+ .withComplexGrids(R.id.gridview)
+ );
+
+ clickListItemChild(20, R.id.unknown);
+
+ assertResult("");
+ }
+
private void openActivity(IntentBuilder intentBuilder) {
activity.launchActivity(intentBuilder.build(InstrumentationRegistry.getTargetContext()));
}
diff --git a/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsClickTest.java b/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsClickTest.java
index 7c6414539..396d3cfad 100644
--- a/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsClickTest.java
+++ b/sample/src/androidTest/java/com/schibsted/spain/barista/sample/ListsClickTest.java
@@ -81,6 +81,39 @@ public void clickMultipleListView_byId() throws Exception {
assertResult(getSimpleListViewTextAt(20));
}
+ @Test
+ public void clickSimpleGridView() throws Exception {
+ launchTestActivity(ListsActivity.buildIntent()
+ .withSimpleGrids(R.id.gridview)
+ );
+
+ clickListItem(20);
+
+ assertResult(getSimpleListViewTextAt(20));
+ }
+
+ @Test
+ public void clickComplexGridView() throws Exception {
+ launchTestActivity(ListsActivity.buildIntent()
+ .withComplexGrids(R.id.gridview)
+ );
+
+ clickListItem(20);
+
+ assertResult(getComplexListViewTextAt(20));
+ }
+
+ @Test
+ public void clickMultipleGridView_byId() throws Exception {
+ launchTestActivity(ListsActivity.buildIntent()
+ .withSimpleLists(R.id.gridview, R.id.gridview2)
+ );
+ clickListItem(R.id.gridview, 20);
+
+ assertResult(getSimpleListViewTextAt(20));
+ }
+
+
@Test(expected = BaristaException.class)
public void fail_whenNoViewFound() throws Exception {
launchTestActivity(ListsActivity.buildIntent());
@@ -106,11 +139,21 @@ public void fail_whenMultipleListsViews_withoutId() throws Exception {
clickListItem(20);
}
+ @Test(expected = BaristaException.class)
+ public void fail_whenMultipleGridViews_withoutId() throws Exception {
+ launchTestActivity(ListsActivity.buildIntent()
+ .withSimpleGrids(R.id.gridview, R.id.gridview2)
+ );
+
+ clickListItem(20);
+ }
+
@Test(expected = BaristaException.class)
public void fail_whenRecyclerAndListView_withoutId() throws Exception {
launchTestActivity(ListsActivity.buildIntent()
.withRecyclers(R.id.recycler)
.withSimpleLists(R.id.listview)
+ .withSimpleGrids(R.id.gridview)
);
clickListItem(20);
diff --git a/sample/src/main/java/com/schibsted/spain/barista/sample/ListsActivity.java b/sample/src/main/java/com/schibsted/spain/barista/sample/ListsActivity.java
index 6fe2e8637..617e41288 100644
--- a/sample/src/main/java/com/schibsted/spain/barista/sample/ListsActivity.java
+++ b/sample/src/main/java/com/schibsted/spain/barista/sample/ListsActivity.java
@@ -10,6 +10,7 @@
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
@@ -23,6 +24,8 @@ public class ListsActivity extends AppCompatActivity {
private static final String EXTRA_SIMPLE_LISTS = "simpleLists";
private static final String EXTRA_COMPLEX_LISTS = "complexLists";
private static final String EXTRA_RECYCLERS = "recyclers";
+ private static final String EXTRA_SIMPLE_GRIDS = "simpleGrids";
+ private static final String EXTRA_COMPLEX_GRIDS = "complexGrids";
static final String[] FRUITS = new String[] {
"Apple", "Apricot", "Avocado", "Banana", "Bilberry", "Blackberry", "Blackcurrant",
@@ -75,6 +78,14 @@ protected void onCreate(Bundle savedInstanceState) {
for (int id : getIntent().getIntArrayExtra(EXTRA_RECYCLERS)) {
addRecyclerView(id);
}
+
+ for (int id : getIntent().getIntArrayExtra(EXTRA_SIMPLE_GRIDS)) {
+ addSimpleGridView(id);
+ }
+
+ for (int id : getIntent().getIntArrayExtra(EXTRA_COMPLEX_GRIDS)) {
+ addComplexGridView(id);
+ }
}
private void addSimpleListView(int id) {
@@ -108,6 +119,26 @@ private void addRecyclerView(int id) {
addList(recyclerView);
}
+ private void addSimpleGridView(int id) {
+ GridView gridView = new GridView(this);
+ gridView.setId(id);
+ gridView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, FRUITS));
+ gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ clickedResult.setText(getSimpleListViewTextAt(position));
+ }
+ });
+ addList(gridView);
+ }
+
+ private void addComplexGridView(int id) {
+ GridView gridView = new GridView(this);
+ gridView.setId(id);
+ gridView.setAdapter(new TextListViewAdapter(this, FRUITS, clickedResult));
+ addList(gridView);
+ }
+
private void addList(View listView) {
listsContainer.addView(listView,
new LinearLayout.LayoutParams(
@@ -121,6 +152,8 @@ public static class IntentBuilder {
private int[] simpleListViewIds = {};
private int[] complexListViewIds = {};
private int[] recyclerViewIds = {};
+ private int[] simpleGridViewIds = {};
+ private int[] complexGridViewIds = {};
public IntentBuilder withSimpleLists(int... ids) {
simpleListViewIds = ids;
@@ -137,11 +170,23 @@ public IntentBuilder withRecyclers(int... ids) {
return this;
}
+ public IntentBuilder withSimpleGrids(int... ids) {
+ simpleGridViewIds = ids;
+ return this;
+ }
+
+ public IntentBuilder withComplexGrids(int... ids) {
+ complexGridViewIds = ids;
+ return this;
+ }
+
public Intent build(Context context) {
Intent intent = new Intent(context, ListsActivity.class);
intent.putExtra(EXTRA_SIMPLE_LISTS, simpleListViewIds);
intent.putExtra(EXTRA_COMPLEX_LISTS, complexListViewIds);
intent.putExtra(EXTRA_RECYCLERS, recyclerViewIds);
+ intent.putExtra(EXTRA_SIMPLE_GRIDS, simpleGridViewIds);
+ intent.putExtra(EXTRA_COMPLEX_GRIDS, complexGridViewIds);
return intent;
}
}
diff --git a/sample/src/main/res/values/ids.xml b/sample/src/main/res/values/ids.xml
index d9d0624c3..e00da4b62 100644
--- a/sample/src/main/res/values/ids.xml
+++ b/sample/src/main/res/values/ids.xml
@@ -4,5 +4,7 @@
+
+
\ No newline at end of file