-
-
Notifications
You must be signed in to change notification settings - Fork 756
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:src/screens/UserPortal/Events from Jest to Vitest #2639
Refactor:src/screens/UserPortal/Events from Jest to Vitest #2639
Conversation
WalkthroughThe pull request focuses on refactoring the Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (2)
src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx (1)
93-99
: Consider using async setup in beforeAll.The async mock setup in
beforeAll
could potentially cause race conditions. Consider using a more explicit setup.beforeAll(() => { - vi.mock('react-router-dom', async () => { - const actual = await vi.importActual('react-router-dom'); - return { - ...actual, - useParams: () => ({ orgId: 'orgId' }), - }; - }); + vi.mock('react-router-dom', () => { + return { + ...vi.importActual('react-router-dom'), + useParams: () => ({ orgId: 'orgId' }), + }; + }); });src/screens/UserPortal/Events/Events.spec.tsx (1)
271-279
: Consider extracting matchMedia mock.The matchMedia mock could be moved to a shared test utilities file for reuse across test suites.
Consider creating a
testUtils.ts
file:// testUtils.ts export const setupMatchMedia = () => { Object.defineProperty(window, 'matchMedia', { writable: true, value: vi.fn().mockImplementation((query) => ({ matches: false, media: query, onchange: null, addListener: vi.fn(), removeListener: vi.fn(), addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn(), })), }); };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
src/screens/UserPortal/Events/Events.spec.tsx
(8 hunks)src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx
(2 hunks)
🔇 Additional comments (5)
src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx (2)
24-24
: LGTM! Well-documented test suite.
The added documentation clearly describes the purpose and scope of the test suite.
Also applies to: 26-32
34-38
: LGTM! Clean migration to Vitest mocking.
The toast mock has been correctly migrated from Jest to Vitest.
src/screens/UserPortal/Events/Events.spec.tsx (3)
24-30
: LGTM! Comprehensive documentation.
The added documentation clearly outlines the test suite's purpose and scenarios.
34-66
: LGTM! Well-structured mock setup.
The mock setup for various dependencies is clean and follows Vitest best practices.
450-454
: LGTM! Dynamic date handling.
The hardcoded dates have been replaced with dynamic dates using toLocaleDateString()
, which aligns with the PR objectives.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #2639 +/- ##
====================================================
- Coverage 88.35% 85.04% -3.31%
====================================================
Files 295 312 +17
Lines 7048 8130 +1082
Branches 1521 1778 +257
====================================================
+ Hits 6227 6914 +687
- Misses 617 1045 +428
+ Partials 204 171 -33 ☔ View full report in Codecov by Sentry. |
|
@abbi4code: I will review the changes. ✅ Actions performedReview triggered.
|
@CodeRabbit start review |
@abbi4code: I will start a full review of your PR. ✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx (1)
107-107
: Consider enhancing mock cleanupWhile
vi.clearAllMocks()
is correct, consider addingvi.restoreAllMocks()
to ensure all mocks are properly restored to their original state.- vi.clearAllMocks(); + vi.clearAllMocks(); + vi.restoreAllMocks();src/screens/UserPortal/Events/Events.spec.tsx (2)
271-279
: Consider moving matchMedia mock to test utilsThe window.matchMedia mock implementation is correctly migrated to Vitest, but it could be moved to a shared test utils file since it's likely needed across multiple test files.
Consider creating a
src/utils/testUtils.ts
:export const setupMatchMedia = () => { Object.defineProperty(window, 'matchMedia', { writable: true, value: vi.fn().mockImplementation((query) => ({ matches: false, media: query, onchange: null, addListener: vi.fn(), removeListener: vi.fn(), addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn(), })), }); };
Line range hint
413-417
: Remove or restore commented test codeThe commented-out test code should either be removed if it's no longer needed or restored if it's required for testing the calendar view functionality.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/screens/UserPortal/Events/Events.spec.tsx
(8 hunks)src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx
(2 hunks)
🔇 Additional comments (2)
src/screens/UserPortal/Volunteer/UpcomingEvents/UpcomingEvents.spec.tsx (2)
26-32
: Well-documented test suite!
The documentation header clearly describes the purpose and scope of the tests.
34-39
: Correctly migrated mocks to Vitest!
The mock implementations have been properly migrated:
- Replaced jest.mock with vi.mock
- Using vi.fn() for mock functions
- Correctly importing actual router implementation with vi.importActual
Also applies to: 93-99
Please make the appropriate changes so that coderabbit.ai approves your PR |
consistent behavior
@CodeRabbit start review |
@abbi4code: I will start a full review of your PR. ✅ Actions performedFull review triggered. |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
|
What kind of change does this PR introduce?
This PR migrates the test cases in src/screens/UserPortal/Events from Jest to Vitest, ensuring compatibility with Vitest .
✅ Replace Jest-specific functions and mocks with Vitest equivalents
✅ Ensure all tests in src/screens/UserPortal/Events pass after migration using npm run test:vitest
✅ Maintain the test coverage for the file as 100% after migration
✅ Upload a video or photo for this specific file coverage is 100% in the PR description
Issue Number:
Fixes #2574
Did you add tests for your changes?
Yes
Snapshots/Videos:
Other information
Replaced hardcoded date strings
With dynamic dates using new Date().toLocaleDateString() to ensure the test uses the current date.
Updated hardcoded startTime and endTime values from '02:00 PM' and '06:00 PM' to '08:00 AM' and '10:00 AM'
To align with the default values set in Events.tsx
Summary by CodeRabbit
test
toit
and adding clarifying comments.