-
-
Notifications
You must be signed in to change notification settings - Fork 720
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
Create an Avatar Component with DiceBear Integration #1391
Comments
@rishav-jha-mech I would like to work on this |
@MahendraDani before opening the PR, you can ask all your doubts here |
Yes, I am first going through the library and its use cases in the project. I will ask the doubts here first |
I went through the codebase to find all the use cases of Components
Tests
My Approach
import { createAvatar } from '@dicebear/core';
import { initials } from '@dicebear/collection';
import { useMemo } from 'react';
export const AvatarDiceBear = () => {
const avatar = useMemo(() => {
return createAvatar(initials, {
size: 128,
seed: "Jhon Doe"
// ... other options
}).toDataUriSync();
}, []);
return <img src={avatar} alt="Avatar" />;
}
import React from 'react';
import { render, screen } from '@testing-library/react';
import Avatar from './Avatar';
test('renders AvatarDiceBear component', () => {
render(<AvatarDiceBear />);
// Check if the component renders without errors
const avatarElement = screen.getByAltText('Avatar');
expect(avatarElement).toBeInTheDocument();
const avatarImage = screen.getByRole('img');
expect(avatarImage).toHaveAttribute('src');
});
// Add more tests based on your specific use cases Doubts
@rishav-jha-mech |
@MahendraDani You should create a prop named "name", and just add a default customisable style to it, check for ChangeLanguageDropDown component, i have done the same thing there. Only Name and Style props are required. Once this PR #1291 gets merged, install the package using npm install |
Understood. |
I started working on the issues as the mentioned PR is now merged and I created the following component: import React from 'react';
import { createAvatar } from '@dicebear/core';
import { initials } from '@dicebear/collection';
import { useMemo } from 'react';
interface InterfaceAvatarProps {
name: string;
}
export const Avatar = ({ name }: InterfaceAvatarProps): JSX.Element => {
const avatar = useMemo(() => {
return createAvatar(initials, {
size: 128,
seed: name,
}).toDataUriSync();
}, []);
return <img src={avatar} alt="Avatar" />;
}; Then I created the test file import React from 'react';
import { screen } from '@testing-library/react';
import { Avatar } from './Avatar';
import { BrowserRouter } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
describe('Avatar component', () => {
it('renders with the correct alt text', () => {
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<Avatar name="Jhon Doe" />
</I18nextProvider>
</BrowserRouter>;
const avatarImage = screen.getByAltText('Avatar');
expect(avatarImage).toBeInTheDocument();
});
}); The component is working as expected but the test is failing and giving following error
@rishav-jha-mech Would you please guide me how can I mock the component for tests? |
@rishav-jha-mech Would please help me mocking the component for test? |
This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue. |
Unassigning due to inactivity |
Hii @palisadoes can I work on this? |
hey @rishav-jha-mech sir could you help me with this? i tried adding type:commonjs to tsconfig but still it didnt work ,also type:module is already added in package.json ! I am not getting why the problem is encountered while testing whereas everything is working fine! |
hey @Cioppolo14 i am unsassigning myself from this issue! |
I would like to work on this issue |
This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue. |
Is your feature request related to a problem? Please describe.
We are using Dicebear http api at many places in our code base, since it is not a good practice to load these avatars using the image tag like this
For 2 reasons:
Describe the solution you'd like
Describe alternatives you've considered
NA
Approach to be followed (optional)
NA
Additional context
Add any other context or screenshots about the feature request here.
Potential internship candidates
Please read this if you are planning to apply for a Palisadoes Foundation internship PalisadoesFoundation/talawa#359
The text was updated successfully, but these errors were encountered: