feature: add identicon generation to users without photo

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-10-07 13:45:24 +02:00
parent 55398e2428
commit a8b3b117dc
17 changed files with 210 additions and 23 deletions

View file

@ -7,12 +7,20 @@ import type { UserInfo } from '../../../api/users/types'
import { mockI18n } from '../../../test-utils/mock-i18n'
import { UserAvatarForUser } from './user-avatar-for-user'
import { render } from '@testing-library/react'
import { UserAvatar } from './user-avatar'
jest.mock('@dicebear/identicon', () => null)
jest.mock('@dicebear/core', () => ({
createAvatar: jest.fn(() => ({
toDataUriSync: jest.fn(() => 'data:image/x-other,identicon-mock')
}))
}))
describe('UserAvatar', () => {
const user: UserInfo = {
username: 'boatface',
displayName: 'Boaty McBoatFace',
photo: 'https://example.com/test.png'
photoUrl: 'https://example.com/test.png'
}
beforeEach(async () => {
@ -41,4 +49,14 @@ describe('UserAvatar', () => {
const view = render(<UserAvatarForUser user={user} showName={false} />)
expect(view.container).toMatchSnapshot()
})
it('uses identicon when no photoUrl is given', () => {
const view = render(<UserAvatar displayName={'test'} />)
expect(view.container).toMatchSnapshot()
})
it('uses identicon when empty photoUrl is given', () => {
const view = render(<UserAvatar displayName={'test'} photoUrl={''} />)
expect(view.container).toMatchSnapshot()
})
})