test(avatar): add testcase

This commit is contained in:
unix
2020-04-15 16:36:59 +08:00
parent 359959bd25
commit 0ebcadf900
2 changed files with 1784 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
import React from 'react'
import { mount, render, shallow } from 'enzyme'
import { Avatar } from '../../index'
describe('Avatar', () => {
it('should support square and circle', () => {
const circle = shallow(<Avatar />)
expect(() => circle.unmount()).not.toThrow()
const square = shallow(<Avatar isSquare />)
expect(() => square.unmount()).not.toThrow()
})
it('should render text element', () => {
const imageAvatar = render(<Avatar />)
expect(imageAvatar).toMatchSnapshot()
const textAvatar = render(<Avatar text="text" />)
expect(textAvatar).toMatchSnapshot()
})
it('should omit long chars automatically', () => {
const avatar = mount(<Avatar text="texttexttexttext"/>)
const text = avatar.find('.avatar-text').text()
expect(text.length).toBeLessThan(4)
})
it('stacked should be work', () => {
const avatar = shallow(<Avatar src="https://zeit.co/api/www/avatar/?u=evilrabbit&s=160" stacked />)
expect(() => avatar.unmount()).not.toThrow()
})
it('should render component of a specified size', () => {
const avatar = render(<Avatar size={20} />)
expect(avatar).toMatchSnapshot()
})
it('group component should render all children', () => {
const group = mount(
<Avatar.Group>
<Avatar />
<Avatar />
</Avatar.Group>
)
expect(group.find('.avatar')).toHaveLength(2)
})
it('should stacked when avatars are in a group', () => {
const group = render(
<Avatar.Group>
<Avatar />
<Avatar />
</Avatar.Group>
)
expect(group).toMatchSnapshot()
})
it('should show count in group', () => {
const count = 20
const group = shallow(<Avatar.Group count={count} />)
const text = group.find('.count').text()
expect(text).toContain(count)
})
})