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

Introduce a central utility for matching item in RecyclerView [Testing] #2536

Closed
anandwana001 opened this issue Jan 22, 2021 · 10 comments · Fixed by #5391
Closed

Introduce a central utility for matching item in RecyclerView [Testing] #2536

anandwana001 opened this issue Jan 22, 2021 · 10 comments · Fixed by #5391
Assignees
Labels
enhancement End user-perceivable enhancements. Impact: Low Low perceived user impact (e.g. edge cases). Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@anandwana001
Copy link
Contributor

Is your feature request related to a problem? Please describe.
While writing test cases in the app module for testing, if the item matches the RecyclerView's item, we use atPositionOnView heavily.

Describe the solution you'd like
Create a central utility which we can directly use in our test files.
As for this issue, after creating this central utility, use it in the AdministratorControlsActivityTest only.

Additional context
In some of the file, we had created helper functions,
example - verifyItemDisplayedOnAdministratorControlListItem in AdministratorControlsActivityTest

@anandwana001 anandwana001 added Type: Improvement good first issue This item is good for new contributors to make their pull request. labels Jan 22, 2021
@ayan-biswas0412
Copy link

@anandwana001 Can you elaborate more ? I want to work in this issue . this seems interesting but don't know how to proceed

@anandwana001 anandwana001 changed the title Introduce a central utility for matching item in RecyclerView [Testing] [BLOCKED] Introduce a central utility for matching item in RecyclerView [Testing] Feb 8, 2021
@anandwana001
Copy link
Contributor Author

Thanks @ayan-biswas0412 for showing interest.
Please complete the onboarding and installation steps before starting
https://github.com/oppia/oppia-android/wiki

If you see test files in the app Module, one file referenced in the description above, we use to test alot about if the item is visible on the particular index in RecyclerView. So instead of writing this multiple times, we need a new file, a central utility, something like EditTextInputAction, where we can put our main function of checking items in RecyclerView, and just use it wherever required.

@ayan-biswas0412
Copy link

Thanks @ayan-biswas0412 for showing interest.
Please complete the onboarding and installation steps before starting
https://github.com/oppia/oppia-android/wiki

If you see test files in the app Module, one file referenced in the description above, we use to test alot about if the item is visible on the particular index in RecyclerView. So instead of writing this multiple times, we need a new file, a central utility, something like EditTextInputAction, where we can put our main function of checking items in RecyclerView, and just use it wherever required.

sure I will complete the onboarding first

@anandwana001 anandwana001 removed the good first issue This item is good for new contributors to make their pull request. label Mar 16, 2021
@Sparsh1212
Copy link
Contributor

Sparsh1212 commented Mar 16, 2021

I would love to work on this. @anandwana001 Shall I assign this to myself ?

@Sparsh1212
Copy link
Contributor

Sparsh1212 commented Mar 16, 2021

@anandwana001 As per what I have understood, I am required to shift this helper function to a new file and make it generic to use the id of any RecyclerView. If I have misinterpreted, then please correct me.

Helper Function in AdministratorControlsActivityTest

  private fun verifyItemDisplayedOnAdministratorControlListItem(
    itemPosition: Int,
    targetView: Int
  ) {
    onView(
      atPositionOnView(
        recyclerViewId = R.id.administrator_controls_list,
        position = itemPosition,
        targetViewId = targetView
      )
    ).check(matches(isDisplayed()))
  }

Generalize this to: in a new central utility file

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

@Sparsh1212
Copy link
Contributor

@anandwana001 Please confirm this.

@anandwana001
Copy link
Contributor Author

Sounds good to me @Sparsh1212

@Sparsh1212
Copy link
Contributor

Sparsh1212 commented Mar 18, 2021

@anandwana001 I am facing problem while importing atPositionOnView when shifting the function to the central utility.

import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView

And I think its not a gradle sync issue, do we have to add any dependency in the build.gradle and BUILD.bazel files of the testing module in order to use atPositionOnView? Please guide me on this.

@anandwana001
Copy link
Contributor Author

Yes, as testing is a new module so you have to check if the required dependency is already there or not, if not we have to add it.

@Sparsh1212 Sparsh1212 removed their assignment Jun 9, 2021
@Broppia Broppia added issue_type_infrastructure Impact: Low Low perceived user impact (e.g. edge cases). labels Jul 29, 2022
@BenHenning BenHenning added Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. Z-ibt Temporary label for Ben to keep track of issues he's triaged. issue_user_developer labels Sep 15, 2022
@seanlip seanlip added enhancement End user-perceivable enhancements. and removed issue_type_infrastructure labels Mar 28, 2023
@MohitGupta121 MohitGupta121 added the Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. label Jun 16, 2023
@deonwaju
Copy link
Collaborator

deonwaju commented Apr 10, 2024

Hi @adhiamboperes,
I worked on the below functions renaming the title and adding an argument for the recyclerviewId to each function to make it reusable, I also added kdocs to help understand the functions.
P.S:- I created the functions in the RecyclerviewMatcher class.

Please check the below screenshots if they align with the specifications so I can go ahead and continue with other functions and then make a PR.

Before
Screenshot 2024-04-10 at 14 07 44

Screenshot 2024-04-10 at 14 07 51

After
Screenshot 2024-04-10 at 13 17 38

Screenshot 2024-04-10 at 13 18 00

Screenshot 2024-04-10 at 13 17 53

adhiamboperes pushed a commit that referenced this issue May 8, 2024
…iew (#5391)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fix #2536

I worked on the below functions renaming the title and adding an
argument for the recyclerviewId to each function to make it reusable, I
also added kdocs to help understand the functions.
P.S:- I created the functions in the RecyclerviewMatcher class.
 
![Screenshot 2024-04-30 at 01 24
45](https://github.com/oppia/oppia-android/assets/54560535/6a0464e0-e72f-4516-83e1-3a53d2025a6b)

![Screenshot 2024-04-30 at 01 24
26](https://github.com/oppia/oppia-android/assets/54560535/34332586-e082-4991-9b6b-b8f8c647e7d0)

![Screenshot 2024-04-30 at 01 24
57](https://github.com/oppia/oppia-android/assets/54560535/7090b959-fb45-4787-9957-7e182d47a042)


## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement End user-perceivable enhancements. Impact: Low Low perceived user impact (e.g. edge cases). Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
8 participants