test: add tests for user-avatar

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-05-21 20:27:20 +02:00 committed by Tilman Vatteroth
parent f557901944
commit d3c133ced3
2 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,106 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UserAvatar adds additionalClasses props to wrapping span 1`] = `
<div>
<span
class="d-inline-flex align-items-center testClass"
>
<img
alt="common.avatarOf"
class="rounded user-image"
height="20"
src="https://example.com/test.png"
title="Boaty McBoatFace"
width="20"
/>
<span
class="ml-2 mr-1 user-line-name"
>
Boaty McBoatFace
</span>
</span>
</div>
`;
exports[`UserAvatar does not show names if showName prop is false 1`] = `
<div>
<span
class="d-inline-flex align-items-center "
>
<img
alt="common.avatarOf"
class="rounded user-image"
height="20"
src="https://example.com/test.png"
title="Boaty McBoatFace"
width="20"
/>
</span>
</div>
`;
exports[`UserAvatar renders the user avatar correctly 1`] = `
<div>
<span
class="d-inline-flex align-items-center "
>
<img
alt="common.avatarOf"
class="rounded user-image"
height="20"
src="https://example.com/test.png"
title="Boaty McBoatFace"
width="20"
/>
<span
class="ml-2 mr-1 user-line-name"
>
Boaty McBoatFace
</span>
</span>
</div>
`;
exports[`UserAvatar renders the user avatar in size lg 1`] = `
<div>
<span
class="d-inline-flex align-items-center "
>
<img
alt="common.avatarOf"
class="rounded user-image"
height="30"
src="https://example.com/test.png"
title="Boaty McBoatFace"
width="30"
/>
<span
class="ml-2 mr-1 user-line-name"
>
Boaty McBoatFace
</span>
</span>
</div>
`;
exports[`UserAvatar renders the user avatar in size sm 1`] = `
<div>
<span
class="d-inline-flex align-items-center "
>
<img
alt="common.avatarOf"
class="rounded user-image"
height="16"
src="https://example.com/test.png"
title="Boaty McBoatFace"
width="16"
/>
<span
class="ml-2 mr-1 user-line-name"
>
Boaty McBoatFace
</span>
</span>
</div>
`;

View file

@ -0,0 +1,39 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { UserAvatar } from './user-avatar'
import { render } from '@testing-library/react'
import type { UserInfo } from '../../../api/users/types'
describe('UserAvatar', () => {
const user: UserInfo = {
username: 'boatface',
displayName: 'Boaty McBoatFace',
photo: 'https://example.com/test.png'
}
it('renders the user avatar correctly', () => {
const view = render(<UserAvatar user={user} />)
expect(view.container).toMatchSnapshot()
})
describe('renders the user avatar in size', () => {
it('sm', () => {
const view = render(<UserAvatar user={user} size={'sm'} />)
expect(view.container).toMatchSnapshot()
})
it('lg', () => {
const view = render(<UserAvatar user={user} size={'lg'} />)
expect(view.container).toMatchSnapshot()
})
})
it('adds additionalClasses props to wrapping span', () => {
const view = render(<UserAvatar user={user} additionalClasses={'testClass'} />)
expect(view.container).toMatchSnapshot()
})
it('does not show names if showName prop is false', () => {
const view = render(<UserAvatar user={user} showName={false} />)
expect(view.container).toMatchSnapshot()
})
})