-
Notifications
You must be signed in to change notification settings - Fork 529
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
Fix #2209: Create a Helper class to provide methos for [RecyclerViewActions] scrolling actions #2451
Fix #2209: Create a Helper class to provide methos for [RecyclerViewActions] scrolling actions #2451
Changes from 5 commits
a9c115f
6970f58
cc047e1
a55bff3
49ba036
2ff6ad3
0a53294
2061f10
9644374
b1b0817
775da5d
77477f1
640b947
d38595b
15ff6da
68e102e
d8c6a1c
8aa16a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,10 @@ dependencies { | |
implementation( | ||
'androidx.annotation:annotation:1.1.0', | ||
'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03', | ||
'androidx.recyclerview:recyclerview:1.0.0', | ||
'androidx.test.espresso:espresso-core:3.2.0', | ||
'androidx.test.espresso:espresso-contrib:3.2.0', | ||
'androidx.test.espresso:espresso-intents:3.1.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the intents library needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intents library is not required in the |
||
'androidx.test:runner:1.2.0', | ||
'com.google.dagger:dagger:2.24', | ||
'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2', | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||
package org.oppia.android.testing | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import androidx.recyclerview.widget.RecyclerView | ||||||||||||||||||||||||||||||
import androidx.test.espresso.Espresso.onView | ||||||||||||||||||||||||||||||
import androidx.test.espresso.action.ViewActions.scrollTo | ||||||||||||||||||||||||||||||
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition | ||||||||||||||||||||||||||||||
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition | ||||||||||||||||||||||||||||||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||||||||||||||||||||||||||||||
import javax.inject.Inject | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Provides the different scrolling options for RecyclerView | ||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||
* This is needed because few Roboelectric tests require different scrolling actions for the tests | ||||||||||||||||||||||||||||||
* to be successful. | ||||||||||||||||||||||||||||||
* See https://github.com/oppia/oppia-android/issues/2209 for more information. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(May need line wrapping--you should ensure the KDocs lines take up as much space in the 100 character column limit). Note that I rephrased this slightly to try and clarify the meaning. Note also that we can just reference issues within our repository directly by '#'--that's conventional on the team so others will understand what that means when they come across it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. Updated the changes. |
||||||||||||||||||||||||||||||
class RecyclerViewScrollingActions @Inject constructor( | ||||||||||||||||||||||||||||||
val testCoroutineDispatchers: TestCoroutineDispatchers | ||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Returns a [ViewAction] which scrolls RecyclerView to a position | ||||||||||||||||||||||||||||||
* Usage : TODO | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
fun scrollToPosition(viewId: Int, position: Int) { | ||||||||||||||||||||||||||||||
onView(withId(viewId)).perform( | ||||||||||||||||||||||||||||||
scrollToPosition<RecyclerView.ViewHolder>( | ||||||||||||||||||||||||||||||
position | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
testCoroutineDispatchers.runCurrent() | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Performs a [ViewAction] on a view at position. | ||||||||||||||||||||||||||||||
* 1) Scroll RecyclerView to position | ||||||||||||||||||||||||||||||
* 2) Perform an action on the view at position | ||||||||||||||||||||||||||||||
* Usage : TODO | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some thoughts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. KDoc for latest changes implemented with these changes. |
||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
fun scrollToPositionWithCompleteDisplayForAction(viewId: Int, position: Int) { | ||||||||||||||||||||||||||||||
onView(withId(viewId)).perform( | ||||||||||||||||||||||||||||||
actionOnItemAtPosition<RecyclerView.ViewHolder>( | ||||||||||||||||||||||||||||||
position, | ||||||||||||||||||||||||||||||
scrollTo() | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
testCoroutineDispatchers.runCurrent() | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} |
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.
When using literals, prefer to add named arguments to provide context to readers on the value. Ditto elsewhere in this PR.
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.
Noted. Done.
Also created #2515 as a good-first-issue for such changes elsewhere in the codebase.
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.
This change will be handled in an independent PR, as planned, migration for positional use case will be handled independently for the entire codebase.