-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qianxu.ljj
committed
Jan 4, 2018
1 parent
a5ff00d
commit bc64e4c
Showing
3 changed files
with
63 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ spm_modules | |
dist | ||
build | ||
assets/**/*.css | ||
coverage |
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 |
---|---|---|
@@ -1,9 +1,67 @@ | ||
import expect from 'expect.js'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import TestUtils, { Simulate } from 'react-addons-test-utils'; | ||
import Collapse from '../src'; | ||
import PropTypes from 'prop-types'; | ||
import Enzyme, { mount, shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-15'; | ||
import Collapse, {Panel} from '../src'; | ||
import { setTimeout } from 'timers'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Collapse', () => { | ||
it('Collapse has correct propTypes', () => { | ||
expect(Collapse.propTypes.prefixCls).to.be(PropTypes.string) | ||
expect(Collapse.propTypes.className).to.be(PropTypes.string) | ||
expect(Collapse.propTypes.activeKey).to.be.ok() | ||
expect(Collapse.propTypes.defaultActiveKey).to.be.ok() | ||
expect(Collapse.propTypes.onChange).to.be(PropTypes.func) | ||
expect(Collapse.propTypes.accordion).to.be(PropTypes.bool) | ||
expect(Collapse.propTypes.children).to.be(PropTypes.any) | ||
}) | ||
|
||
it('Panel has correct propTypes', () => { | ||
expect(Panel.propTypes.prefixCls).to.be(PropTypes.string) | ||
expect(Panel.propTypes.header).to.be.ok() | ||
expect(Panel.propTypes.isActive).to.be(PropTypes.bool) | ||
expect(Panel.propTypes.onItemClick).to.be(PropTypes.func) | ||
expect(Panel.propTypes.children).to.be(PropTypes.any) | ||
}) | ||
|
||
let wrapper = mount( | ||
<Collapse defaultActiveKey={['1']} accordion={false}> | ||
<Panel header={'This is panel header 1'} key="1"> | ||
<p>1</p> | ||
</Panel> | ||
<Panel header={'This is panel header 2'} key="2"> | ||
<p>2</p> | ||
</Panel> | ||
<Panel header={'This is panel header 3'} key="3"> | ||
<p>3</p> | ||
</Panel> | ||
</Collapse> | ||
) | ||
|
||
it('has correct defaultActiveKey', () => { | ||
expect(wrapper.state('activeKey')).to.eql(['1']) | ||
}) | ||
|
||
it('has correct activeKey', () => { | ||
wrapper.setProps({ | ||
activeKey: ['2'] | ||
}) | ||
expect(wrapper.state('activeKey')).to.eql(['2']) | ||
}) | ||
|
||
it('has correct accordion', () => { | ||
wrapper.setProps({ | ||
accordion: true | ||
}) | ||
expect(wrapper.prop('accordion')).to.be(true) | ||
}) | ||
|
||
}); | ||
it('has correct click', () => { | ||
wrapper.find('.kuma-collapse-header').at(2).simulate('click') | ||
expect(wrapper.state('activeKey')).to.be('3') | ||
}) | ||
}); |