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

Migrated src/components/EventManagement/* from Jest to Vitest #2915

Conversation

PratapRathi
Copy link
Contributor

@PratapRathi PratapRathi commented Dec 26, 2024

What kind of change does this PR introduce?

This PR will migrate following files from Jest to Vitest

Files:

1.  `src/components/EventManagement/Dashboard/EventDashboard.test.tsx` 
2.  `src/components/EventManagement/EventAgendaItems/EventAgendaItems.test.tsx` 
3.  `src/components/EventManagement/EventAttendance/AttendedEventList.test.tsx`
4.  `src/components/EventManagement/EventAttendance/EventAttendance.test.tsx` 
5.  `src/components/EventManagement/EventAttendance/EventStatistics.test.tsx` 

Issue Number:

Fixes #2793

Did you add tests for your changes?

Yes

Snapshots/Videos:

Screenshot 2024-12-26 at 13 11 15

If relevant, did you update the documentation?
No

Summary
No

Other information
N/A

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features

    • Transitioned testing framework from Jest to Vitest across multiple components, enhancing testing capabilities.
  • Bug Fixes

    • Ensured that mock implementations and test structures remain intact while updating to the new framework.
  • Documentation

    • Updated import statements and mocking methods to align with Vitest's syntax.
  • Tests

    • Replaced test with it for defining test cases, maintaining clarity and consistency in test descriptions.

Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

This pull request focuses on migrating test files within the src/components/EventManagement directory from Jest to Vitest. The changes involve replacing Jest-specific functions and mocks with their Vitest equivalents across multiple test files, including EventDashboard.spec.tsx, EventAgendaItems.spec.tsx, AttendedEventList.spec.tsx, EventAttendance.spec.tsx, and EventStatistics.spec.tsx. The modifications primarily include updating import statements, mocking methods, and test function syntax while maintaining the original test logic and structure.

Changes

File Change Summary
src/components/EventManagement/Dashboard/EventDashboard.spec.tsx Replaced Jest imports with Vitest, updated mocking method from jest.mock to vi.mock, changed test method from test to it
src/components/EventManagement/EventAgendaItems/EventAgendaItems.spec.tsx Migrated from Jest to Vitest, updated module mocking and test function syntax
src/components/EventManagement/EventAttendance/AttendedEventList.spec.tsx Added Vitest imports, replaced test with it
src/components/EventManagement/EventAttendance/EventAttendance.spec.tsx Transitioned to Vitest, updated mocking and test cleanup methods
src/components/EventManagement/EventAttendance/EventStatistics.spec.tsx Migrated to Vitest, updated import statements and mocking functions

Assessment against linked issues

Objective Addressed Explanation
Replace Jest-specific functions with Vitest equivalents [#2793]
Rename test files from .test.* to .spec.* [#2793]
Ensure tests pass using npm run test:vitest [#2793] Requires actual test run verification
Maintain 100% test coverage [#2793] Requires coverage report verification

Possibly related issues

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

🐰 Hopping through test files with glee,
Jest to Vitest, a testing spree!
Mocks and imports, now brand new,
Code coverage shining true blue!
Rabbit's testing dance is done! 🧪


📜 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 35cce16 and 877fe6b.

📒 Files selected for processing (5)
  • src/components/EventManagement/Dashboard/EventDashboard.spec.tsx (4 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.spec.tsx (5 hunks)
  • src/components/EventManagement/EventAttendance/AttendedEventList.spec.tsx (4 hunks)
  • src/components/EventManagement/EventAttendance/EventAttendance.spec.tsx (8 hunks)
  • src/components/EventManagement/EventAttendance/EventStatistics.spec.tsx (9 hunks)
🧰 Additional context used
📓 Learnings (5)
📓 Common learnings
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
src/components/EventManagement/EventAttendance/EventAttendance.spec.tsx (1)
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
src/components/EventManagement/EventAttendance/EventStatistics.spec.tsx (1)
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
src/components/EventManagement/EventAgendaItems/EventAgendaItems.spec.tsx (1)
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
src/components/EventManagement/Dashboard/EventDashboard.spec.tsx (1)
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
🔇 Additional comments (28)
src/components/EventManagement/EventAttendance/AttendedEventList.spec.tsx (2)

10-10: Transition from Jest to Vitest imports looks correct.
No leftover references to Jest were found. This aligns with the PR’s objective of migrating tests to Vitest.


55-55: Migration from test to it is consistent and valid.
All calls to define test blocks now use Vitest’s it function as expected in each changed segment.

Also applies to: 75-75, 103-103

src/components/EventManagement/Dashboard/EventDashboard.spec.tsx (3)

16-16: Vitest import and usage confirmed.
Importing vi, expect, it, and describe from Vitest is correct for this file’s test suite.


42-43: Mocking with vi.mock confirmed.
Switching from jest.mock to vi.mock is valid given the framework migration.


66-66: it usage for test blocks is properly applied.
Replacing test with it fully aligns with Vitest’s syntax. No issues noted.

Also applies to: 87-87, 95-95

src/components/EventManagement/EventAttendance/EventAttendance.spec.tsx (5)

20-20: Use of Vitest in place of Jest.
The import statement and references to vi, describe, beforeEach, afterEach, expect, and it confirm a proper transition to Vitest.


29-29: vi.mock usage is correct.
Mocking react-chartjs-2 as vi.mock is appropriate for Vitest.


Line range hint 42-43: vi.mock('react-router-dom') usage.
This properly replaces jest.mock with vi.mock for router mocking.


51-52: vi.mock setup and cleanup process.
Using vi.mock in the beforeEach block and vi.clearAllMocks() in the afterEach block is valid for Vitest.

Also applies to: 57-57


61-61: it usage for test cases is aligned with Vitest standards.
All references to test blocks use it without any leftover Jest calls, preserving test logic.

Also applies to: 73-73, 86-86, 100-100, 115-115, 127-127

src/components/EventManagement/EventAgendaItems/EventAgendaItems.spec.tsx (6)

21-21: Successful transition to Vitest imports.
Switching to vi, describe, expect, it, and beforeEach matches Vitest’s API.


29-29: Mocking with vi.mock and vi.fn.
Usage of vi.mock('react-toastify', ...) and vi.fn() is correct and replaces Jest equivalents.

Also applies to: 31-32


36-37: Router mocking with vi.mock.
Replacing jest.mock('react-router-dom') with vi.mock('react-router-dom') is consistent with the migration.


42-42: vi.spyOn(console, 'error'): valid approach.
This snippet properly intercepts console errors for the test environment.


78-86: beforeEach for simulating window.location.
Defining location.href and reload via Object.defineProperty is valid for testing navigational features.


88-88: it usage consistently replaces Jest’s test.
The migration to Vitest for these blocks is correctly integrated, preserving test functionality.

Also applies to: 108-108, 130-130, 163-163

src/components/EventManagement/EventAttendance/EventStatistics.spec.tsx (12)

8-8: Good transition from Jest import to Vitest.
Importing from vitest directly is correct and aligns with the migration objective from Jest to Vitest.


12-13: Proper usage of vi.mock.
This is a valid approach to mock react-chartjs-2 with Vitest.


18-19: Mocking react-router-dom with Vitest.
The asynchronous import spread (await vi.importActual(...)) is neat and consistent with Vitest.


25-27: Mocking utils/chartToPdf with Vitest.
Switching from Jest mock to vi.mock maintains the same functionality with Vitest.


147-147: Accurate usage of it.
Replacing test with it works well in Vitest. No issues with the test logic itself.


167-167: Use of it for test naming.
This line confirms the consistent convention from Jest to Vitest. Looks good.


194-196: Correctly mocking and implementing exportToCSV.
The vi.fn() usage and casting to Mock is a valid approach in Vitest.


228-230: Another correct mock for exportToCSV.
This replicates the same good practice as above: using vi.fn() and vi.importActual(...).


263-263: Consistent test structure.
No issues with the new test style in Vitest so far.


280-280: Continued alignment with Vitest.
Maintaining the same functionality for pagination testing is appropriate.


321-321: Maintaining consistency with Vitest’s it.
Ensures the recurring events view test remains functional.


343-344: Correctly migrating closing logic handling.
The mocking of handleClose with vi.fn() fits perfectly with Vitest’s API.


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

codecov bot commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.03%. Comparing base (35cce16) to head (877fe6b).
Report is 5 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #2915       +/-   ##
=====================================================
+ Coverage             58.52%   88.03%   +29.50%     
=====================================================
  Files                   299      316       +17     
  Lines                  7414     8265      +851     
  Branches               1621     1866      +245     
=====================================================
+ Hits                   4339     7276     +2937     
+ Misses                 2828      778     -2050     
+ Partials                247      211       -36     

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

@palisadoes palisadoes merged commit f0dadfd into PalisadoesFoundation:develop-postgres Dec 26, 2024
13 checks passed
@PratapRathi PratapRathi deleted the Migrate-src/components/EventManagement-from-Jest-to-Vitest branch December 26, 2024 13:07
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