-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable custom list child interactions #314
Open
gdomingues
wants to merge
13
commits into
AdevintaSpain:master
Choose a base branch
from
gdomingues:enable_custom_list_child_interactions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
72984a6
Separate and generalize actions for child views
gdomingues 9aa19dc
Add method that allow custom actions on list items child
gdomingues 8e1ef81
Add EditText to list item in order to test custom actions
gdomingues f40c5c1
Add TextView to hold typed text that will be asserted on tests
gdomingues 3398dd3
Set typed text to result field whenever EditText content changes
gdomingues f20c9d7
Add tests for custom actions on list item child
gdomingues 911675d
Add example to README file of custom action on list item child
gdomingues fa6bb08
Merge branch 'master' into enable_custom_list_child_interactions
gdomingues 703e6a6
Merge branch 'master' into enable_custom_list_child_interactions
rocboronat 403bf7c
Merge branch 'master' into enable_custom_list_child_interactions
Sloy c86ad3c
Merge branch 'master' into enable_custom_list_child_interactions
Sloy 1dbe487
Merge branch 'master' into enable_custom_list_child_interactions
Sloy 5e48870
Merge branch 'master' into enable_custom_list_child_interactions
Sloy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
56 changes: 56 additions & 0 deletions
56
library/src/main/java/com/adevinta/android/barista/internal/viewaction/ChildActions.kt
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,56 @@ | ||
package com.adevinta.android.barista.internal.viewaction | ||
|
||
import android.view.View | ||
import androidx.annotation.IdRes | ||
import androidx.test.espresso.PerformException | ||
import androidx.test.espresso.UiController | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.util.HumanReadables | ||
import com.adevinta.android.barista.internal.failurehandler.description | ||
import com.adevinta.android.barista.internal.util.ViewTreeAnalyzer | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers.allOf | ||
|
||
object ChildActions { | ||
|
||
@JvmStatic | ||
fun onChildWithId(@IdRes childId: Int, viewAction: ViewAction): ViewAction { | ||
return onChildWithMatcher(withId(childId), viewAction) | ||
} | ||
|
||
@JvmStatic | ||
fun onChildWithMatcher(childMatcher: Matcher<View>, viewAction: ViewAction): ViewAction { | ||
return object : ViewAction { | ||
override fun getConstraints(): Matcher<View> { | ||
return allOf<View>(isDisplayed(), hasDescendant(childMatcher)) | ||
} | ||
|
||
override fun getDescription(): String { | ||
return "Perform " + viewAction.description + " on a child view " + childMatcher.description() | ||
} | ||
|
||
override fun perform(uiController: UiController, view: View) { | ||
var foundTarget = false | ||
|
||
for (child in ViewTreeAnalyzer.getAllChildren(view)) { | ||
if (childMatcher.matches(child)) { | ||
foundTarget = true | ||
viewAction.perform(uiController, child) | ||
break | ||
} | ||
} | ||
|
||
if (!foundTarget) { | ||
throw PerformException.Builder() | ||
.withActionDescription(description) | ||
.withViewDescription(HumanReadables.describe(view)) | ||
.withCause(IllegalArgumentException("Didn't find any view " + childMatcher.description())) | ||
.build() | ||
} | ||
} | ||
} | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
library/src/main/java/com/adevinta/android/barista/internal/viewaction/ClickChildAction.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this functionality. As a user, what if I wanted to identify the child view using a ViewMatcher? Perhaps this function should use
onChildWithMatcher
instead ofonChildWithId
for greater flexibility from an end-user perspective?