-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes click on RecyclerView when ItemView is wrapped (#48)
* Reproduce the performClick issue with a test (espresso version) This test proves that click() and clickUsingPerformClick() have different behaviors when clicking the parent (wrapper) of a view. * Make recyclerview tests less flaky Tests are passing even though the feature is broken. \o/ * Fixed recyclerview code The click listener should be on the row (itemView), not in the label (textView). Otherwise clicking the row won't open the next activity. * Only use performClick() when the view is clickable. Otherwise use espresso's click action (which simulates a tap) * Fix test naming style * Extract method for helping readability
- Loading branch information
Showing
7 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sample/src/androidTest/java/com/schibsted/spain/barista/sample/WrappedViewClickTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.schibsted.spain.barista.sample; | ||
|
||
import android.support.test.rule.ActivityTestRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static com.schibsted.spain.barista.BaristaAssertions.assertDisplayed; | ||
import static com.schibsted.spain.barista.custom.PerformClickAction.clickUsingPerformClick; | ||
|
||
public class WrappedViewClickTest { | ||
|
||
@Rule | ||
public ActivityTestRule<WrappedViewActivity> activityTestRule = | ||
new ActivityTestRule<>(WrappedViewActivity.class); | ||
|
||
@Test | ||
public void clickOnButton() throws Exception { | ||
onView(withId(R.id.button)).perform(click()); | ||
|
||
assertDisplayed("Clicked"); | ||
} | ||
|
||
@Test | ||
public void clickOnButtonWithCustomAction() throws Exception { | ||
onView(withId(R.id.button)).perform(clickUsingPerformClick()); | ||
|
||
assertDisplayed("Clicked"); | ||
} | ||
|
||
@Test | ||
public void clickOnButtonWrapper() throws Exception { | ||
onView(withId(R.id.button_wrapper)).perform(click()); | ||
|
||
assertDisplayed("Clicked"); | ||
} | ||
|
||
@Test | ||
public void clickOnButtonWrapperWithCustomAction() throws Exception { | ||
onView(withId(R.id.button_wrapper)).perform(clickUsingPerformClick()); | ||
|
||
assertDisplayed("Clicked"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
sample/src/main/java/com/schibsted/spain/barista/sample/WrappedViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.schibsted.spain.barista.sample; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
|
||
public class WrappedViewActivity extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_wrapped_view); | ||
|
||
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
findViewById(R.id.text).setVisibility(View.VISIBLE); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
> | ||
|
||
|
||
<FrameLayout | ||
android:id="@+id/button_wrapper" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
> | ||
<Button | ||
android:id="@+id/button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Wrapped button" | ||
/> | ||
</FrameLayout> | ||
|
||
<TextView | ||
android:id="@+id/text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Clicked" | ||
android:visibility="gone" | ||
tools:visibility="visible" | ||
/> | ||
|
||
|
||
</FrameLayout> |