mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-31 23:28:34 -04:00
feature: add identicon generation to users without photo
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
55398e2428
commit
a8b3b117dc
17 changed files with 210 additions and 23 deletions
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue