Skip to content
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 #2536: Introduce a central utility for matching item in RecyclerView #2957

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.oppia.android.testing

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandwana001 I am facing trouble while importing this. Please guide me on what changes should I make in build.gradle file so that the RecyclerViewMatcher could be imported. I tried adding the app module to the testing module, but that doesn't seem to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can shift RecyclerViewMatcher to the testing module.
Waiting for @rt4914 confirmation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will do that after the confirmation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to him, yes we are good to shift it.

Copy link
Contributor Author

@Sparsh1212 Sparsh1212 Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I update the overall codebase to use this new central utility of RecyclerViewTest or only update the AdministratorControlsActivityTest ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will require updating all the files which are using RecyclerViewMatcher, as the import path will going to change for all.

Check all the files using it and try to have a successful Gradle build.


class VerifyItemDisplayedInRecyclerView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check EditTextInputAction for reference.

We can make this class all about RecyclerView testing. So, it's not only about testing item at the position. In future, we can have things like item string checking or anything that comes up we can use this class as a central utility for all types of testing for RecyclerView.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here.

companion object {
private fun verifyItemDisplayedOnRecyclerView(
recyclerView: Int,
itemPosition: Int,
targetView: Int
) {
onView(
atPositionOnView(
recyclerViewId = recyclerView,
position = itemPosition,
targetViewId = targetView
)
).check(matches(isDisplayed()))
}
}
}