-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
Avatar migration to vitest #2589
Avatar migration to vitest #2589
Conversation
Signed-off-by: NishantSinghhhhh <[email protected]>
Signed-off-by: NishantSinghhhhh <[email protected]>
WalkthroughThe pull request introduces several updates to the Changes
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Warning Rate limit exceeded@NishantSinghhhhh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 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: 3
🧹 Outside diff range and nitpick comments (5)
vitest.config.js (1)
14-34
: Consider adding minimum coverage thresholdsThe test configuration is well-structured, but could benefit from defining minimum coverage thresholds to maintain code quality standards.
Add coverage thresholds to ensure maintaining test coverage:
coverage: { enabled: true, provider: 'istanbul', reportsDirectory: './coverage/vitest', + thresholds: { + lines: 80, + functions: 80, + branches: 80, + statements: 80 + }, exclude: [src/components/Avatar/Avatar.tsx (1)
Line range hint
18-31
: Update JSDoc to include new propertiesThe component's JSDoc comments are missing documentation for the new
customUrl
andloading
properties.Add documentation for new props:
/** * A component that generates and displays an avatar based on the provided name. * The avatar is generated using the DiceBear library with the initials style. * * @param name - The name used to generate the avatar. * @param alt - Alternative text for the avatar image. * @param size - Size of the avatar image. * @param avatarStyle - Custom CSS class for the avatar image. * @param dataTestId - Data-testid attribute for testing purposes. * @param radius - Radius of the avatar corners. + * @param customUrl - Optional URL to use instead of generating an avatar + * @param loading - Optional loading state for the avatar * * @returns JSX.Element - The rendered avatar image component. */package.json (1)
Line range hint
116-158
: Ensure test dependencies are in syncThe testing-related dependencies look good, but there are some considerations:
@testing-library/react
is pinned to version^16.0.1
which is quite old@types/jest
is still included despite migrating to VitestConsider these updates:
- "@testing-library/react": "^16.0.1", + "@testing-library/react": "^14.0.0", - "@types/jest": "^26.0.24",src/components/Avatar/Avatar.spec.tsx (2)
37-90
: Consider adding snapshot testsWhile the current tests cover functionality well, adding snapshot tests would help catch unintended visual changes.
Add this test:
test('matches snapshot', () => { const { container } = render( <MockedProvider addTypename={false} link={link}> <BrowserRouter> <Provider store={store}> <I18nextProvider i18n={i18nForTest}> <Avatar name="John Doe" size={64} /> </I18nextProvider> </Provider> </BrowserRouter> </MockedProvider> ); expect(container).toMatchSnapshot(); });
129-138
: Add specific size validation testsThe invalid sizes test could be more specific about the expected fallback size.
- expect(avatarElement).toHaveAttribute('width'); // Expect the fallback size of 128 - expect(avatarElement).toHaveAttribute('height'); // Expect the fallback size of 128 + const defaultSize = '128'; + expect(avatarElement).toHaveAttribute('width', defaultSize); + expect(avatarElement).toHaveAttribute('height', defaultSize);
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (5)
package.json
(5 hunks)src/components/Avatar/Avatar.spec.tsx
(1 hunks)src/components/Avatar/Avatar.tsx
(3 hunks)tsconfig.json
(1 hunks)vitest.config.js
(1 hunks)
🔇 Additional comments (7)
tsconfig.json (1)
21-22
: LGTM! Appropriate TypeScript exclusions
The exclusions are well-configured for the Vitest migration, properly excluding build artifacts and test configuration.
vitest.config.js (1)
7-13
: LGTM! Well-configured plugins for React testing
The plugin configuration is appropriate for React testing with Vitest:
- React plugin for JSX support
- Minimal node polyfills (events only)
- TypeScript path resolution
src/components/Avatar/Avatar.tsx (1)
65-66
: LGTM! Good accessibility improvement
Adding explicit height and width attributes helps prevent layout shifts and improves accessibility.
package.json (2)
78-80
: LGTM: Test scripts properly configured
The new Vitest scripts are well-structured:
test:vitest
: For CI/CD pipelinestest:vitest:watch
: For developmenttest:vitest:coverage
: For coverage reporting
Line range hint 20-43
: Verify version compatibility of core dependencies
The changes include version updates and new dependencies. Some concerns:
- Downgrading
@mui/x-date-pickers
from^7.22.1
to^7.18.0
might introduce compatibility issues - Adding
chart.js
and@pdfme/generator
increases the bundle size significantly
src/components/Avatar/Avatar.spec.tsx (2)
1-35
: LGTM: Well-structured test setup
The test setup is comprehensive with proper mocking of dependencies and store.
92-114
: LGTM: Good error handling test coverage
The helper function and error handling tests are well implemented.
Signed-off-by: NishantSinghhhhh <[email protected]>
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: 2
🧹 Outside diff range and nitpick comments (3)
src/components/Avatar/Avatar.tsx (1)
45-52
: Fix indentation in customUrl validation blockThe indentation in the customUrl validation block is inconsistent.
if (customUrl) { try { new URL(customUrl); return customUrl; } catch (e) { console.warn('Invalid custom URL provided to Avatar component'); } }🧰 Tools
🪛 eslint
[error] 46-46: Delete
···
(prettier/prettier)
[error] 47-47: Delete
··
(prettier/prettier)
[error] 48-48: Replace
············
with········
(prettier/prettier)
[error] 49-49: Delete
··
(prettier/prettier)
[error] 49-49: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 50-50: Delete
··
(prettier/prettier)
src/components/Avatar/Avatar.spec.tsx (2)
93-105
: Add return type to renderAvatar helper functionThe helper function lacks a TypeScript return type annotation.
- const renderAvatar = (props = {}) => { + const renderAvatar = (props = {}): ReturnType<typeof render> => {🧰 Tools
🪛 eslint
[error] 93-93: Missing return type on function.
(@typescript-eslint/explicit-function-return-type)
[error] 95-95: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 96-96: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 97-97: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 98-98: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 99-99: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
129-138
: Enhance invalid size test assertionsThe invalid size tests could be more specific about the expected fallback behavior.
test(`falls back to default size when invalid size ${size} is provided`, () => { renderAvatar({ name: 'Test User', size }); const avatarElement = screen.getByAltText('Dummy Avatar'); - expect(avatarElement).toHaveAttribute('width'); - expect(avatarElement).toHaveAttribute('height'); + expect(avatarElement).toHaveAttribute('width', '128'); + expect(avatarElement).toHaveAttribute('height', '128'); });
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (2)
src/components/Avatar/Avatar.spec.tsx
(1 hunks)src/components/Avatar/Avatar.tsx
(3 hunks)
🧰 Additional context used
🪛 eslint
src/components/Avatar/Avatar.spec.tsx
[error] 46-46: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 47-47: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 48-48: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 49-49: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 50-50: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 70-70: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 71-71: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 72-72: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 73-73: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 74-78: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 93-93: Missing return type on function.
(@typescript-eslint/explicit-function-return-type)
[error] 95-95: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 96-96: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 97-97: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 98-98: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 99-99: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 170-170: Delete ··
(prettier/prettier)
[error] 172-172: Delete ··
(prettier/prettier)
[error] 175-175: Delete ··
(prettier/prettier)
[error] 178-180: Delete ⏎··⏎··
(prettier/prettier)
src/components/Avatar/Avatar.tsx
[error] 40-41: Delete ⏎
(prettier/prettier)
[error] 41-41: 'src' is assigned a value but never used.
(@typescript-eslint/no-unused-vars)
[error] 41-41: 'setSrc' is assigned a value but never used.
(@typescript-eslint/no-unused-vars)
[error] 46-46: Delete ···
(prettier/prettier)
[error] 47-47: Delete ··
(prettier/prettier)
[error] 48-48: Replace ············
with ········
(prettier/prettier)
[error] 49-49: Delete ··
(prettier/prettier)
[error] 49-49: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 50-50: Delete ··
(prettier/prettier)
🔇 Additional comments (1)
src/components/Avatar/Avatar.spec.tsx (1)
164-178
: LGTM! Good implementation of network error handling test
The test case properly simulates network errors and verifies the fallback behavior.
🧰 Tools
🪛 eslint
[error] 170-170: Delete ··
(prettier/prettier)
[error] 172-172: Delete ··
(prettier/prettier)
[error] 175-175: Delete ··
(prettier/prettier)
Signed-off-by: NishantSinghhhhh <[email protected]>
Signed-off-by: NishantSinghhhhh <[email protected]>
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 (2)
src/components/Avatar/Avatar.tsx (1)
43-50
: Enhance error handling for invalid custom URLsThe URL validation is good, but consider:
- Adding error details to the warning message
- Potentially notifying parent components of validation failures
if (customUrl) { try { new URL(customUrl); return customUrl; } catch (e) { - console.warn('Invalid custom URL provided to Avatar component'); + console.warn(`Invalid custom URL provided to Avatar component: ${customUrl}`, e); + // Consider adding: onError?.(e); } }🧰 Tools
🪛 eslint
[error] 44-44: Delete
···
(prettier/prettier)
[error] 45-45: Delete
··
(prettier/prettier)
[error] 46-46: Replace
············
with········
(prettier/prettier)
[error] 47-47: Delete
··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete
··
(prettier/prettier)
src/components/Avatar/Avatar.spec.tsx (1)
134-136
: Enhance size fallback testsThe test should assert the specific fallback size value instead of just checking for the presence of width/height attributes.
- expect(avatarElement).toHaveAttribute('width'); // Expect the fallback size of 128 - expect(avatarElement).toHaveAttribute('height'); // Expect the fallback size of 128 + const expectedFallback = '128'; + expect(avatarElement).toHaveAttribute('width', expectedFallback); + expect(avatarElement).toHaveAttribute('height', expectedFallback);
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
src/components/Avatar/Avatar.spec.tsx
(1 hunks)src/components/Avatar/Avatar.tsx
(3 hunks)
🧰 Additional context used
🪛 eslint
src/components/Avatar/Avatar.spec.tsx
[error] 46-46: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 47-47: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 48-48: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 49-49: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 50-50: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 70-70: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 71-71: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 72-72: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 73-73: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 74-78: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 93-93: Missing return type on function.
(@typescript-eslint/explicit-function-return-type)
[error] 95-95: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 96-96: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 97-97: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 98-98: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 99-99: 'React' must be in scope when using JSX
(react/react-in-jsx-scope)
[error] 163-166: Delete ⏎⏎··⏎
(prettier/prettier)
src/components/Avatar/Avatar.tsx
[error] 40-41: Delete ⏎··
(prettier/prettier)
[error] 44-44: Delete ···
(prettier/prettier)
[error] 45-45: Delete ··
(prettier/prettier)
[error] 46-46: Replace ············
with ········
(prettier/prettier)
[error] 47-47: Delete ··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete ··
(prettier/prettier)
🔇 Additional comments (3)
src/components/Avatar/Avatar.tsx (1)
53-56
: Add fallback for undefined size
The size prop is used directly without a fallback value, which could cause rendering issues when size is undefined.
src/components/Avatar/Avatar.spec.tsx (2)
1-35
: LGTM! Well-structured test setup
The test setup is comprehensive with proper mocking of dependencies and providers.
153-162
: Add network error handling tests
The custom URL tests should include network error scenarios.
Signed-off-by: NishantSinghhhhh <[email protected]>
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 (3)
src/components/Avatar/Avatar.tsx (3)
43-50
: Fix formatting issues.The indentation is inconsistent in the customUrl handling block.
if (customUrl) { try { new URL(customUrl); - return customUrl; + return customUrl; } catch (e) { console.warn('Invalid custom URL provided to Avatar component'); } }🧰 Tools
🪛 eslint
[error] 44-44: Delete
···
(prettier/prettier)
[error] 45-45: Delete
··
(prettier/prettier)
[error] 46-46: Replace
············
with········
(prettier/prettier)
[error] 47-47: Delete
··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete
··
(prettier/prettier)
43-50
: Enhance error handling for customUrl validation.The current error handling could be more informative and provide better debugging context.
if (customUrl) { try { new URL(customUrl); return customUrl; } catch (e) { - console.warn('Invalid custom URL provided to Avatar component'); + console.warn(`Invalid custom URL provided to Avatar component: ${customUrl}`, e); } }🧰 Tools
🪛 eslint
[error] 44-44: Delete
···
(prettier/prettier)
[error] 45-45: Delete
··
(prettier/prettier)
[error] 46-46: Replace
············
with········
(prettier/prettier)
[error] 47-47: Delete
··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete
··
(prettier/prettier)
Missing dependencies in useMemo hook
The
useMemo
hook's dependency array is missingcustomUrl
andradius
which are used within the memoized function. Looking at other usages ofuseMemo
across the codebase, all dependencies used within the memoized functions are consistently included in their respective dependency arrays.- }, [name, size]); + }, [name, size, customUrl, radius]);🔗 Analysis chain
Line range hint
42-57
: Verify memoization dependencies.The
useMemo
hook's dependency array only includes[name, size]
, butcustomUrl
andradius
are also used within the memoized function.- }, [name, size]); + }, [name, size, customUrl, radius]);🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other usages of useMemo in the codebase to verify consistency ast-grep --pattern 'useMemo($_, [$_])'Length of output: 12640
🧰 Tools
🪛 eslint
[error] 40-41: Delete
⏎··
(prettier/prettier)
[error] 44-44: Delete
···
(prettier/prettier)
[error] 45-45: Delete
··
(prettier/prettier)
[error] 46-46: Replace
············
with········
(prettier/prettier)
[error] 47-47: Delete
··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete
··
(prettier/prettier)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
src/components/Avatar/Avatar.tsx
(3 hunks)
🧰 Additional context used
🪛 eslint
src/components/Avatar/Avatar.tsx
[error] 40-41: Delete ⏎··
(prettier/prettier)
[error] 44-44: Delete ···
(prettier/prettier)
[error] 45-45: Delete ··
(prettier/prettier)
[error] 46-46: Replace ············
with ········
(prettier/prettier)
[error] 47-47: Delete ··
(prettier/prettier)
[error] 47-47: 'e' is defined but never used.
(@typescript-eslint/no-unused-vars)
[error] 48-48: Delete ··
(prettier/prettier)
🔇 Additional comments (2)
src/components/Avatar/Avatar.tsx (2)
31-31
: LGTM! Props handling looks good.
The default value for the optional name
prop and the addition of customUrl
are well implemented.
Also applies to: 38-38
68-69
: LGTM! Consistent size handling.
The explicit height and width attributes with fallbacks match the avatar creation size, ensuring consistent rendering.
The base branch was changed.
@palisadoes , I just wanted to ask , if I can add few tests that i feel will be good |
Closing. You need to be making your changes using the most current version of the |
What kind of change does this PR introduce?
Feature/Refactoring Avatar component
Issue Number : #2492
Did you add tests for your changes?
Yes
Snapshots/Videos:
Screencast.from.2024-12-02.18-44-06.webm
Summary
Does this PR introduce a breaking change?
NO
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
Release Notes
New Features
Avatar
component with optionalname
andcustomUrl
properties for greater flexibility.Bug Fixes
Avatar
component to gracefully manage invalid inputs.Documentation
Chores