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: Add central testing utility for RecyclerView #2965

Closed
wants to merge 13 commits into from
Closed

Fix #2536: Add central testing utility for RecyclerView #2965

wants to merge 13 commits into from

Conversation

Sparsh1212
Copy link
Contributor

@Sparsh1212 Sparsh1212 commented Mar 22, 2021

Explanation

Fixes #2536:

  1. Shift RecyclerViewMatcher to testing module and update the corresponding imports.
  2. Add a central testing utility for RecyclerView

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The PR follows the style guide.
  • The PR does not contain any unnecessary auto-generated code from Android Studio.
  • The PR is made from a branch that's not called "develop".
  • The PR is made from a branch that is up-to-date with "develop".
  • The PR's branch is based on "develop" and not on any other branch.
  • The PR is assigned to an appropriate reviewer in both the Assignees and the Reviewers sections.

@Sparsh1212
Copy link
Contributor Author

Sparsh1212 commented Mar 22, 2021

@anandwana001 Changes done as per the discussion. PTAL.
The gradle build seems to be working fine, but the Bazel tests are failing, can you please guide me, where else should I make the corrections in the BUILD.bazel files if any.

@Sparsh1212 Sparsh1212 changed the title Fix #2536: Add RecyclerView Central Testing Utility Fix #2536: Add central testing utility for RecyclerView Mar 22, 2021
@anandwana001
Copy link
Contributor

Looks like as the file is no more in the app module, we need some update around BUILD files.

"src/sharedTest/java/org/oppia/android/app/recyclerview/RecyclerViewMatcher.kt",

@Sparsh1212
Copy link
Contributor Author

@anandwana001 PTAL.

@anandwana001 anandwana001 self-assigned this Mar 23, 2021
Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

@anandwana001 anandwana001 removed their assignment Mar 23, 2021
Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

As we had shifted the RecyclerViewMatcher from app module to Testing module, we can remove the companion object and use it as we are using other functions in the testing module.

@Sparsh1212
Copy link
Contributor Author

As we had shifted the RecyclerViewMatcher from app module to Testing module, we can remove the companion object and use it as we are using other functions in the testing module.

For doing this, I have to inject RecyclerViewMatcher in all the files, that were earlier using it as a companion object. Am I thinking right? Just wanted to confirm this, because this will involve changing approx 30-33 files.

@anandwana001
Copy link
Contributor

As we had shifted the RecyclerViewMatcher from app module to Testing module, we can remove the companion object and use it as we are using other functions in the testing module.

For doing this, I have to inject RecyclerViewMatcher in all the files, that were earlier using it as a companion object. Am I thinking right? Just wanted to confirm this, because this will involve changing approx 30-33 files.

Yes

@anandwana001 anandwana001 removed their assignment Mar 24, 2021
@Sparsh1212
Copy link
Contributor Author

As we had shifted the RecyclerViewMatcher from app module to Testing module, we can remove the companion object and use it as we are using other functions in the testing module.

For doing this, I have to inject RecyclerViewMatcher in all the files, that were earlier using it as a companion object. Am I thinking right? Just wanted to confirm this, because this will involve changing approx 30-33 files.

Yes

Done

Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

Our function verifyItemDisplayedOnRecyclerView is using atPositionOnView and there is also one function atPositionOnView.

Could you check what's the difference between them and when to use which function?

@Sparsh1212
Copy link
Contributor Author

Sparsh1212 commented Mar 24, 2021

Our function verifyItemDisplayedOnRecyclerView is using atPositionOnView and there is also one function atPositionOnView.

Could you check what's the difference between them and when to use which function?

The purpose of atPositionOnView in the RecycleViewMatcher is to return a Matcher for a specific view within the item inside RecyclerView from a specified position.
The purpose of our function verifyItemDisplayedOnRecyclerView is that: by using this atPositionOnView, it first gets the matcher of that specific view and then verifies that it is displayed on the screen or not.
Hence, if we want just the Matcher, of a specific view inside RecyclerView then use atPositionOnView.
But, if we want to verify that a specific view inside the RecycleView is displayed or not, then one should use verifyItemDisplayedOnRecyclerView.

The two atPositionOnView (one that our function is using, and the one which is present in RecyclerViewMatcher are the same) Our function is just making use of that.

I hope that I got the question correctly, if you think that there is some misinterpretation here, then please let me know.

@anandwana001
Copy link
Contributor

I Will take a look at this tomorrow, might look into some concise solution.

Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

Thanks, @Sparsh1212
This is something cleaning up by shifting the RecyclerViewMatcher to the testing module.

Earlier I suggested, we can drop using companion object because I thought we might need context or testCoroutineDispatchers to inject in the class, but now as I looked more closely at it, I think we don't need any of them.
So, what I suggest here that we can use the companion object back. Sorry for this extra trouble, but I think this will going to be much cleaner.
Let me know your thoughts on this.

@@ -56,6 +55,7 @@ import org.oppia.android.domain.oppialogger.loguploader.LogUploadWorkerModule
import org.oppia.android.domain.oppialogger.loguploader.WorkManagerConfigurationModule
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.testing.RecyclerViewMatcher.Companion.atPositionOnView
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing the failure. Please check my above comment. I think I missed something earlier and need revert.

@Sparsh1212
Copy link
Contributor Author

Thanks, @Sparsh1212
This is something cleaning up by shifting the RecyclerViewMatcher to the testing module.

Earlier I suggested, we can drop using companion object because I thought we might need context or testCoroutineDispatchers to inject in the class, but now as I looked more closely at it, I think we don't need any of them.
So, what I suggest here that we can use the companion object back. Sorry for this extra trouble, but I think this will going to be much cleaner.
Let me know your thoughts on this.

No worries Sir, I will revert back the changes made for the companion object. But just for the sake of knowledge can you please let me know, why we won't be requiring context or testCoroutineDispatchers to inject in this class anytime in the future.

@anandwana001
Copy link
Contributor

We cannot confirm whether we will be requiring this in future or not, but as it seems, currently there is no requirement of context or testCoroutineDispatchers in our utility class.

@Sparsh1212 Sparsh1212 closed this Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce a central utility for matching item in RecyclerView [Testing]
2 participants