-
-
Notifications
You must be signed in to change notification settings - Fork 708
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 : Adding Vitest to Request Page #2652
Refactor : Adding Vitest to Request Page #2652
Conversation
WalkthroughThe changes in this pull request focus on refactoring the test file Changes
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.
Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.
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 (5)
src/screens/Requests/Requests.spec.tsx (5)
32-34
: Enhance window.location mock with additional propertiesThe window.location mock is missing some commonly used properties that might be needed in other tests. Consider adding pathname, search, and hash.
Object.defineProperty(window, 'location', { - value: { href: 'http://localhost/', assign: vi.fn(), reload: vi.fn() }, + value: { + href: 'http://localhost/', + pathname: '/', + search: '', + hash: '', + assign: vi.fn(), + reload: vi.fn() + }, });
25-34
: Consider moving mock setup to a shared test utility fileThe localStorage and window.location mocks could be useful across multiple test files. Consider extracting them to a shared test utility file (e.g.,
testUtils.ts
) to promote reusability and consistency.Example structure:
// src/utils/testUtils.ts import { vi } from 'vitest'; export function setupStorageMock() { vi.stubGlobal('localStorage', { getItem: vi.fn(), setItem: vi.fn(), clear: vi.fn(), removeItem: vi.fn(), }); } export function setupLocationMock() { Object.defineProperty(window, 'location', { value: { href: 'http://localhost/', pathname: '/', search: '', hash: '', assign: vi.fn(), reload: vi.fn() }, }); }
Line range hint
56-58
: Reset mock function state in afterEachWhile
localStorage.clear()
cleans the storage, it doesn't reset the mock function state. Consider addingvi.clearAllMocks()
to ensure mock function calls are reset between tests.afterEach(() => { localStorage.clear(); + vi.clearAllMocks(); });
Line range hint
47-53
: Replace custom wait function with Vitest utilitiesInstead of using a custom wait function, consider using Vitest's built-in timer utilities for better test reliability and maintainability.
-async function wait(ms = 100): Promise<void> { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - }); -}Replace wait() calls with:
await vi.advanceTimersByTimeAsync(100);Don't forget to add
vi.useFakeTimers()
in beforeEach andvi.useRealTimers()
in afterEach.
Line range hint
142-167
: Enhance search functionality test assertionsThe search functionality test could be improved with more specific assertions to verify the expected behavior after each search operation.
test('Testing Search requests functionality', async () => { render( // ... render code ... ); await wait(); const searchBtn = screen.getByTestId('searchButton'); const search1 = 'John'; userEvent.type(screen.getByTestId(/searchByName/i), search1); userEvent.click(searchBtn); await wait(); + expect(screen.getByText('John')).toBeInTheDocument(); const search2 = 'Pete{backspace}{backspace}{backspace}{backspace}'; userEvent.type(screen.getByTestId(/searchByName/i), search2); + await wait(); + expect(screen.queryByText('John')).not.toBeInTheDocument(); // ... rest of the test ... });
@shivasankaran18 Please fix the first comment so that each issue listed automatically closes. The PR_GUIDELINES.md file has details. Please also fix the failed tests. |
@palisadoes what changes should I do to make CI tests successfull ..could you please help me out? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #2652 +/- ##
=====================================================
- Coverage 94.55% 83.78% -10.77%
=====================================================
Files 295 312 +17
Lines 7036 8118 +1082
Branches 1516 1773 +257
=====================================================
+ Hits 6653 6802 +149
- Misses 177 1171 +994
+ Partials 206 145 -61 ☔ View full report in Codecov by Sentry. |
We have a policy of unassigning contributors who close PRs without getting validation from our reviewer team. This is because:
Please be considerate of our volunteers' limited time and our desire to improve our code base. This policy is stated as a pinned post in all our Talawa repositories. Our YouTube videos explain why this practice is not acceptable to our Community. Unfortunately, if this continues we will have to close the offending PR and unassign you from the issue. |
Refactor: Adding Vitest to Request Page
**Issue Number: #2569 **
**Did you add tests for your changes? Yes
**
**
**
Summary
Migrated the testing framework to Vitest.
Updated all test files and configurations to be compatible with Vitest's syntax and features.
Have you read the contributing guide? Yes
Summary by CodeRabbit
Bug Fixes
Tests