mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-24 04:15:54 +08:00
test(avatar): add testcase
This commit is contained in:
1722
components/avatar/__tests__/__snapshots__/index.test.tsx.snap
Normal file
1722
components/avatar/__tests__/__snapshots__/index.test.tsx.snap
Normal file
File diff suppressed because it is too large
Load Diff
62
components/avatar/__tests__/index.test.tsx
Normal file
62
components/avatar/__tests__/index.test.tsx
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user