From bc64e4ca16e19a5000fc0dadcfc06e02b3d9b8fe Mon Sep 17 00:00:00 2001 From: "qianxu.ljj" Date: Thu, 4 Jan 2018 14:51:10 +0800 Subject: [PATCH] =?UTF-8?q?[MOD]=20=E6=96=B0=E5=A2=9E=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C=E8=A6=86=E7=9B=96=E7=8E=87=E8=BE=BE?= =?UTF-8?q?=E5=88=B090%=E4=BB=A5=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/Collapse.js | 2 +- tests/Collapse.spec.js | 64 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 372e187..81e7cb2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ spm_modules dist build assets/**/*.css +coverage \ No newline at end of file diff --git a/src/Collapse.js b/src/Collapse.js index 1266c55..5224159 100644 --- a/src/Collapse.js +++ b/src/Collapse.js @@ -18,7 +18,7 @@ export default class Collapse extends Component { static propTypes = { prefixCls: PropTypes.string, - className: React.PropTypes.string, + className: PropTypes.string, activeKey: PropTypes.oneOfType([ PropTypes.string, PropTypes.arrayOf(PropTypes.string), diff --git a/tests/Collapse.spec.js b/tests/Collapse.spec.js index 7eb25eb..cef4f43 100644 --- a/tests/Collapse.spec.js +++ b/tests/Collapse.spec.js @@ -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( + + +

1

+
+ +

2

+
+ +

3

+
+
+ ) + + 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') + }) +}); \ No newline at end of file