-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from XiaoMi/develop
release:2.1.0
- Loading branch information
Showing
49 changed files
with
2,982 additions
and
1,346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react' | ||
import { mount, shallow } from 'enzyme' | ||
import { spy, fake } from 'sinon' | ||
import Alert from '../alert' | ||
|
||
describe('Alert', () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers() | ||
}) | ||
afterAll(() => { | ||
jest.useRealTimers() | ||
}) | ||
|
||
describe('Lifecycle', () => { | ||
it('componentDidMount', () => { | ||
const componentDidMountSpy = spy(Alert.prototype, 'componentDidMount') | ||
const wrapper = mount(<Alert />) | ||
|
||
expect(wrapper.instance()).toBeInstanceOf(Alert) | ||
|
||
expect(componentDidMountSpy.callCount).toEqual(1) | ||
componentDidMountSpy.restore() | ||
|
||
expect(wrapper.find('.icon-info-circle-o')).toHaveLength(1) | ||
expect(wrapper.find('.close-btn')).toHaveLength(1) | ||
}) | ||
}) | ||
|
||
describe('PropTypes', () => { | ||
it('type', () => { | ||
const wrapper = mount( | ||
<div> | ||
<Alert type='info' /> | ||
<Alert type='error' /> | ||
<Alert type='success' /> | ||
<Alert type='warning' /> | ||
</div> | ||
) | ||
|
||
// NOTE 缺少 type 对应唯一标识 | ||
expect(wrapper.find('.icon-info-circle-o')).toHaveLength(2) | ||
expect(wrapper.find('.icon-close-circle-o')).toHaveLength(1) | ||
expect(wrapper.find('.icon-check-circle-o')).toHaveLength(1) | ||
}) | ||
|
||
it('onClose', () => { | ||
const callback = fake() | ||
const wrapper = shallow( | ||
<Alert onClose={callback} /> | ||
) | ||
|
||
wrapper.find('.close-btn').first().simulate('click') | ||
expect(callback.callCount).toEqual(1) | ||
}) | ||
|
||
it('content', () => { | ||
const content = 'text-content' | ||
const wrapper = shallow( | ||
<Alert {...{content}} /> | ||
) | ||
|
||
expect(wrapper.text()).toEqual(expect.stringMatching(content)) | ||
}) | ||
|
||
it('title', () => { | ||
const title = 'text-title' | ||
const wrapper = shallow( | ||
<Alert {...{title}} /> | ||
) | ||
|
||
expect(wrapper.text()).toEqual(expect.stringMatching(title)) | ||
}) | ||
|
||
it('duration', () => { | ||
const duration = 100 | ||
const wrapper = shallow( | ||
<Alert {...{duration}} /> | ||
) | ||
const handleCloseSpy = spy(Alert.prototype, 'handleClose') | ||
|
||
expect(handleCloseSpy.callCount).toEqual(0) | ||
expect(setTimeout).toHaveBeenCalledTimes(1); | ||
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), duration) | ||
|
||
jest.runAllTimers() | ||
expect(handleCloseSpy.callCount).toEqual(1) | ||
handleCloseSpy.restore() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react' | ||
import { mount, shallow } from 'enzyme' | ||
import Badge from '../Badge' | ||
|
||
describe('Badge', () => { | ||
describe('Lifecycle', () => { | ||
// FIXME #34 typeof +content === 'number' always be true | ||
it('componentDidMount', () => { | ||
const wrapper = mount(<Badge />) | ||
|
||
expect(wrapper.instance()).toBeInstanceOf(Badge) | ||
|
||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-base`)).toHaveLength(1) | ||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-value`)).toHaveLength(1) | ||
}) | ||
}) | ||
|
||
describe('PropTypes', () => { | ||
it('type', () => { | ||
const wrapper = mount( | ||
<div> | ||
<Badge type='bubble' /> | ||
<Badge type='dot' /> | ||
</div> | ||
) | ||
|
||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-dot`)).toHaveLength(1) | ||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-value`)).toHaveLength(1) | ||
}) | ||
|
||
it('content', () => { | ||
const content = 'test-content' | ||
const contentNumber1 = 1 | ||
const contentNumber2 = 100 | ||
const wrapper = shallow( | ||
<Badge {...{content}} /> | ||
) | ||
|
||
expect(wrapper.text()).toEqual(expect.stringMatching(content)) | ||
|
||
wrapper.setProps({ content: contentNumber1 }) | ||
expect(wrapper.text()).toEqual(expect.stringMatching(`${contentNumber1}`)) | ||
|
||
wrapper.setProps({ content: contentNumber2 }) | ||
expect(wrapper.text()).toEqual(expect.stringMatching(`${Badge.defaultProps.max}+`)) | ||
}) | ||
|
||
it('max', () => { | ||
const props = { | ||
max: 33, | ||
content: 1 | ||
} | ||
const wrapper = shallow( | ||
<Badge {...props} /> | ||
) | ||
|
||
expect(wrapper.text()).toEqual(expect.stringMatching(`${props.content}`)) | ||
|
||
wrapper.setProps({ content: 34 }) | ||
expect(wrapper.text()).toEqual(expect.stringMatching(`${props.max}+`)) | ||
}) | ||
|
||
it('visible', () => { | ||
const wrapper = mount( | ||
<div> | ||
<Badge type='bubble' visible={false} /> | ||
<Badge type='dot' visible={false} /> | ||
</div> | ||
) | ||
|
||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-dot.hi-hide`)).toHaveLength(1) | ||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-value.hi-hide`)).toHaveLength(1) | ||
}) | ||
|
||
it('style', () => { | ||
const style = { | ||
color: '#ffff00' | ||
} | ||
const wrapper = shallow( | ||
<Badge {...{style}} /> | ||
) | ||
|
||
expect(wrapper.find(`.${Badge.defaultProps.prefixCls}-base`).prop('style')).toMatchObject(style) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import Icon from '../icon' | ||
import './style/index' | ||
|
||
class Breadcrumb extends Component { | ||
render () { | ||
const { separator, data, onClick } = this.props | ||
return <div className='hi-breadcrumb'> | ||
{ | ||
data.map((item, index) => { | ||
return <span key={index} className='hi-breadcrumb__item'> | ||
<span className='hi-breadcrumb__content' onClick={() => { onClick(item.path) }}>{item.icon && <Icon name={item.icon} />}{item.content}</span> | ||
<span className='hi-breadcrumb__separator'>{separator}</span> | ||
</span> | ||
}) | ||
} | ||
</div> | ||
} | ||
} | ||
|
||
Breadcrumb.propTypes = { | ||
separator: PropTypes.string, | ||
data: PropTypes.array, | ||
onClick: PropTypes.func | ||
} | ||
Breadcrumb.defaultProps = { | ||
separator: '|', | ||
data: [], | ||
onClick: () => {} | ||
} | ||
export default Breadcrumb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './index.scss' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.hi-breadcrumb { | ||
color: rgba(153, 153, 153, 1); | ||
|
||
&__content { | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: #4284f5; | ||
} | ||
|
||
.hi-icon { | ||
margin: 0 4px; | ||
} | ||
} | ||
|
||
&__separator { | ||
margin: 0 10px; | ||
} | ||
|
||
&__item:last-child { | ||
.hi-breadcrumb__content { | ||
cursor: text; | ||
|
||
&:hover { | ||
color: rgba(153, 153, 153, 1); | ||
} | ||
} | ||
|
||
.hi-breadcrumb__separator { | ||
display: none; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.