-
-
Notifications
You must be signed in to change notification settings - Fork 803
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
Improve code coverage in src/components/UserPortal/Register/Register.tsx
#3248
base: develop-postgres
Are you sure you want to change the base?
Improve code coverage in src/components/UserPortal/Register/Register.tsx
#3248
Conversation
WalkthroughThis pull request focuses on improving code coverage for the Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
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
🧹 Nitpick comments (2)
src/components/UserPortal/Register/Register.spec.tsx (2)
Line range hint
32-57
: Consider adding TypeScript type for MOCKS array.Adding proper typing for the mock data would improve type safety and make the test suite more maintainable.
+type SignUpMock = { + request: { + query: typeof SIGNUP_MUTATION; + variables: { + firstName: string; + lastName: string; + email: string; + password: string; + }; + }; + result: { + data: { + signUp: { + user: { + _id: string; + }; + accessToken: string; + refreshToken: string; + }; + }; + }; +}; + -const MOCKS = [ +const MOCKS: SignUpMock[] = [
87-89
: Add JSDoc and consider extracting the magic number.The waitForAsync function would benefit from documentation and the timeout value should be extracted into a named constant.
+const ASYNC_TIMEOUT_MS = 100; + +/** + * Utility function to wait for async operations to complete in tests. + * Used to ensure state updates and effects have been processed. + * @returns Promise that resolves after ASYNC_TIMEOUT_MS milliseconds + */ async function waitForAsync(): Promise<void> { - await act(() => new Promise((resolve) => setTimeout(resolve, 100))); + await act(() => new Promise((resolve) => setTimeout(resolve, ASYNC_TIMEOUT_MS))); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/UserPortal/Register/Register.spec.tsx
(12 hunks)src/components/UserPortal/Register/Register.tsx
(0 hunks)
💤 Files with no reviewable changes (1)
- src/components/UserPortal/Register/Register.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test Application
- GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/components/UserPortal/Register/Register.spec.tsx (1)
Line range hint
91-270
: Consider refactoring common test setup and adding edge cases.The test suite has good coverage but could be improved in several ways:
- Extract common test setup to reduce duplication:
function renderRegister() { return render( <MockedProvider addTypename={false} link={link}> <BrowserRouter> <Provider store={store}> <I18nextProvider i18n={i18nForTest}> <Register {...props} /> </I18nextProvider> </Provider> </BrowserRouter> </MockedProvider> ); }
- Consider adding these edge cases:
- Email validation format
- Password complexity requirements
- Special characters in names
- Network error scenarios
- Loading states
- Enhance the success case test to verify:
- Form field clearing
- Loading state during submission
- Navigation after successful registration
Let me check if there are any password complexity or email validation requirements in the component:
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3248 +/- ##
=====================================================
+ Coverage 8.52% 90.17% +81.65%
=====================================================
Files 309 330 +21
Lines 7802 8488 +686
Branches 1729 1874 +145
=====================================================
+ Hits 665 7654 +6989
+ Misses 7063 604 -6459
- Partials 74 230 +156 ☔ View full report in Codecov by Sentry. |
@@ -76,7 +76,6 @@ export default function register(props: InterfaceRegisterProps): JSX.Element { | |||
toast.success(t('afterRegister') as string); // Success message |
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.
Good work @hars-21, but the acceptance criteria is to have 100% Code coverage for this file, From the screenshot that you have uploaded, it shows line 88 is not covered by tests, see if a meaningful error message can be shown for this error and write an adequate test for it
Re-request for review and update your PR description once it is done.
What kind of change does this PR introduce?
Improve code coverage in
src/components/UserPortal/Register/Register.tsx
Issue Number:
Fixes #3074
Snapshots/Videos:
If relevant, did you update the documentation?
No changes required
Summary
Removed
istanbul ignore next
Does this PR introduce a breaking change?
No
Checklist
CodeRabbit AI Review
Test Coverage
Other information
Passed all the test
Achieved 96% code coverage
Have you read the contributing guide?
Yes
Summary by CodeRabbit
Tests
Refactor