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

refactor: jest to vitest of OrganizationActionItems : fixes #2557 #2773

Conversation

bandhan-majumder
Copy link
Contributor

@bandhan-majumder bandhan-majumder commented Dec 24, 2024

What kind of change does this PR introduce?

Refactoring

Issue Number:

There are multiple test files in this directory. So it needs multiple PRs to close the issue. This PR fixes one such file inside that directory OrganizationActionItems.spec.tsx

Fixes #2557

Snapshots/Videos:

image

Summary

Refactored the OrganizationActionItems.tsx tests from jest to vitest in OrganizationActionItems.spec.tsx

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Introduced a new variable, eventId, in various GraphQL request scenarios for action items.
  • Bug Fixes

    • Improved error handling and filtering conditions in action items queries.
  • Tests

    • Added a comprehensive test suite for the OrganizationActionItems component covering rendering, sorting, filtering, and modal interactions.
    • Removed the previous test file for the OrganizationActionItems component, impacting overall test coverage.

Not all the params were being mocked properly. As a result of not getting the expected response, useQuery was returning error in actionItemsError. This is fixed now
Migrated to vitest with functionalities
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request involves modifications to the OrganizationActionItems testing suite, focusing on migrating from Jest to Vitest. The changes include adding an eventId to mock GraphQL requests in the OrganizationActionItem.mocks.ts file, creating a new test specification file OrganizationActionItems.spec.tsx, and removing the existing OrganizationActionItems.test.tsx file.

Changes

File Change Summary
src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts Added eventId to GraphQL request variables in MOCKS, MOCKS_ERROR, and MOCKS_EMPTY arrays
src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx New test specification file created with comprehensive test suite using Vitest and React Testing Library
src/screens/OrganizationActionItems/OrganizationActionItems.test.tsx Existing test file removed

Assessment against linked issues

Objective Addressed Explanation
Replace Jest-specific functions with Vitest equivalents [#2557]
Ensure tests pass using npm run test:vitest [#2557] Requires full test run verification.
Maintain 100% test coverage [#2557] The removal of the existing test file may impact coverage.

Possibly related issues

Suggested labels

refactor

Suggested reviewers

  • palisadoes

Poem

🐰 Hopping through code with glee,
Vitest tests now run so free!
Mocks and queries, all aligned,
Testing magic, brilliantly designed!
A rabbit's leap to testing delight! 🧪


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9501f8 and 9bd2b55.

📒 Files selected for processing (1)
  • src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts (1)

27-27: Consider extracting eventId into a shared constant.

Repeatedly specifying "eventId" might introduce duplication. Additionally, if the eventId is intended to vary, centralizing its management can ensure consistency for future updates or different testing scenarios.

Also applies to: 51-51, 69-69, 87-87, 105-105, 124-124, 143-143, 161-161, 418-418, 486-486

src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx (1)

1-13: Adopt @apollo/client/testing if possible.

Currently, we import MockedProvider from @apollo/react-testing, which is deprecated in some versions of Apollo. Consider switching to @apollo/client/testing if your Apollo version supports it, ensuring long-term compatibility and community support.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c14708f and c9501f8.

📒 Files selected for processing (3)
  • src/screens/OrganizationActionItems/OrganizationActionItem.mocks.ts (10 hunks)
  • src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx (1 hunks)
  • src/screens/OrganizationActionItems/OrganizationActionItems.test.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • src/screens/OrganizationActionItems/OrganizationActionItems.test.tsx
🧰 Additional context used
📓 Learnings (1)
src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx (1)
Learnt from: Chaitanya1672
PR: PalisadoesFoundation/talawa-admin#2049
File: src/screens/OrganizationActionItems/ActionItemUpdateModal.tsx:112-138
Timestamp: 2024-11-12T10:40:58.654Z
Learning: The `istanbul ignore next` comments in the `ActionItemUpdateModal.tsx` file were added as part of a commit that introduced tests for the `ActionItemUpdateModal` component. Removing these comments and writing tests to cover the previously ignored lines is recommended to ensure code integrity and improve test coverage.
🔇 Additional comments (19)
src/screens/OrganizationActionItems/OrganizationActionItems.spec.tsx (19)

22-27: Mock logger usage looks good.

Mocking react-toastify is a neat approach for controlling side effects in tests.


29-35: Ensure consistent mocking of date pickers.

Using DesktopDateTimePicker for the DateTimePicker mock is fine. Verify that any date-time-specific formatting or handling in your tests aligns with this approach.


50-56: Well-structured debounce helper.

The debounceWait helper function is essential for controlling async behavior in UI tests. No issues found.


58-68: Good setup for Vitest environment.

The creation of the test suite, plus beforeAll and afterAll hooks, matches good practice.


70-97: URL parameter fallback handling.

The redirect logic upon missing route parameters appears correct. Great job covering edge cases.


99-128: Comprehensive rendering test.

These lines ensure that the base elements (e.g., search bar) appear for the user, validating essential UI behavior.


130-174: Sorting action items descending.

The test thoroughly checks sorting functionality by due date and includes relevant assertions. This helps ensure correctness of the UI state after user interactions.


176-220: Sorting action items ascending.

Similarly, verifying ascending sort is important for completeness. Good coverage.


222-282: Filtering by status (All/Pending).

These tests demonstrate robust coverage for the filter feature. Combining user interactions (click events) and async checks (waitFor) provides confidence in the final behavior.


284-327: Filtering by status (Completed).

Continuing the filter coverage, ensuring separate test coverage for each status helps isolate potential bugs.


329-364: Modal toggling: create action item.

The test verifies that modals appear and dismiss correctly, an important UI detail.


366-401: Modal toggling: view action item.

Same approach as create. Checks are clear, ensuring consistent user experience for the view functionality.


403-438: Modal toggling: edit action item.

Ensuring the update flow is tested prevents regressions in editing features.


440-475: Modal toggling: delete action item.

Tests the deletion flow in a similar manner, maintaining UI consistency.


477-512: Modal toggling: update status of action item.

Ensures that changing an item’s status triggers the expected UI.


514-558: Search by assignee coverage.

Properly verifies the correctness of the search functionality. Good usage of debounceWait.


560-604: Search by category coverage.

Similarly, verifies the category search functionality. Reaffirms robust coverage of search flows.


606-633: Empty action items scenario.

Confirming that an empty state is handled gracefully is vital for user experience.


635-661: Error scenario coverage.

Testing error states ensures the UI displays appropriate feedback to the user.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 24, 2024
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.27%. Comparing base (c14708f) to head (9bd2b55).
Report is 1 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #2773       +/-   ##
=====================================================
+ Coverage             71.94%   87.27%   +15.32%     
=====================================================
  Files                   296      313       +17     
  Lines                  7358     8204      +846     
  Branches               1606     1848      +242     
=====================================================
+ Hits                   5294     7160     +1866     
+ Misses                 1804      859      -945     
+ Partials                260      185       -75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bandhan-majumder
Copy link
Contributor Author

bandhan-majumder commented Dec 24, 2024

Hi @palisadoes . With this PR, the issue #2557 can be closed as all the test files inside that directory will be successfully migrated to vitest. It took total 5 PRs to close the issue. Thank you.

@palisadoes palisadoes merged commit 8ec66ea into PalisadoesFoundation:develop-postgres Dec 24, 2024
13 checks passed
@bandhan-majumder
Copy link
Contributor Author

bandhan-majumder commented Dec 24, 2024

Hi @palisadoes . As all the issues are already assigned, I was looking for more test files that are not issued to be migrated to vitest. I have made a list which can be found here : https://bandhanmajumder.notion.site/All-test-issues-1666c9979ab38069bbbde2f2b61b8b7c
all the files name without the ✅ emoji are needed to be listed in issues. Can I go and create the issues for the files which are not issued til now? I will make sure that I avoid creating duplicate issues. It will help others to solve new issues t0o. Please let me know.

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.

2 participants