From 18e123beb489639ef17ff63edd857caeb27607a0 Mon Sep 17 00:00:00 2001 From: "xing.he" <1245036094@qq.com> Date: Thu, 16 Nov 2017 06:44:12 -0600 Subject: [PATCH] Add test cases of module `Affix` and `Breadcrumb` (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * input test (#8) * Update README.md * TagGroup 动态添加数据 点击删除无法获取相应数据问题 * Update README.md * input test * 合并 * input test2 (#9) * Update README.md * TagGroup 动态添加数据 点击删除无法获取相应数据问题 * Update README.md * input test * 合并 * input test2 * Adding default value of porps size on module Avatar and some test cases. * fix(affix): Fix bug where body.scrollTop is 0. * InputNumber add defaultValue (#11) InputNumber add defaultValue, add test case. * Remove extraneous props `status` from doc and add test cases. * Add test cases of Breadcrumb * Add test cases of Affix * Remove console log --- src/affix/__test__/Affix.test.js | 19 +++++++++++ src/breadcrumb/__test__/Breadcrumb.test.js | 34 +++++++++++++++++++ src/input-number/__test__/InputNumber.test.js | 15 ++++---- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/affix/__test__/Affix.test.js create mode 100644 src/breadcrumb/__test__/Breadcrumb.test.js diff --git a/src/affix/__test__/Affix.test.js b/src/affix/__test__/Affix.test.js new file mode 100644 index 0000000000..2ff3c584e2 --- /dev/null +++ b/src/affix/__test__/Affix.test.js @@ -0,0 +1,19 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Affix from '../'; + + +describe('', () => { + const Component = mount() + + it('The name of module must be "Affix"', () => { + expect(Component.name()).toBe('Affix') + }); + + it('The default performance should be fixed at top 0', () => { + Component.setState({ position: 'fixed', top: 0 }) + expect(Component.state().position).toBe('fixed') + expect(Component.state().top).toEqual(0) + Component.setState({ position: null, top: null }) + }); +}); diff --git a/src/breadcrumb/__test__/Breadcrumb.test.js b/src/breadcrumb/__test__/Breadcrumb.test.js new file mode 100644 index 0000000000..bad71f341c --- /dev/null +++ b/src/breadcrumb/__test__/Breadcrumb.test.js @@ -0,0 +1,34 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Breadcrumb from '../'; + + +describe('', () => { + const Component = mount( + 首页 + 活动管理 + 活动列表 + 活动详情 + ) + + it('The name of module must be "Breadcrumb"', () => { + expect(Component.name()).toBe('Breadcrumb') + }); + + it('The length of breadcrumb item should be 4', () => { + expect(Component.find('.w-breadcrumb-item')).toHaveLength(4) + }); + + it('The separator should be charactor "@"', () => { + Component.setProps({ separator: '@' }) + expect(Component.find('.w-breadcrumb-item-separator').at(0).text()).toBe('@') + }); + + it('The item separator should be charactor "#"', () => { + expect(Component.find('.w-breadcrumb-item-separator').at(1).text()).toBe('#') + }); + + it('The href of item first should be "https://uiw-react.github.io"', () => { + expect(Component.find('.w-breadcrumb-item a').prop('href')).toEqual('https://uiw-react.github.io') + }); +}); diff --git a/src/input-number/__test__/InputNumber.test.js b/src/input-number/__test__/InputNumber.test.js index e27bcacd62..2cc83aa0f8 100644 --- a/src/input-number/__test__/InputNumber.test.js +++ b/src/input-number/__test__/InputNumber.test.js @@ -2,18 +2,17 @@ import React from 'react'; import { mount } from 'enzyme'; import { InputNumber } from '../../../src'; -describe('',()=>{ +describe('', () => { const wrapperState = { - value:0, + value: 0, } var wrapper = mount({ - console.log('value:',value) - wrapperState.value=value + onChange={(e, value) => { + wrapperState.value = value }} - >); + >); - it('Test the default props and node.',() => { + it('Test the default props and node.', () => { expect(wrapper.name()).toBe('InputNumber') // 默认值测试 expect(wrapper.find('.w-input-number')).toHaveLength(1); @@ -23,7 +22,7 @@ describe('',()=>{ expect(wrapper.find('.w-input').type()).toBe('div'); }) - it('Test onChange attributes.', () => { + it('Test onChange attributes.', () => { wrapper.setProps({ step: 2 }); let push = wrapper.find('.w-input-number-push').at(0) push.simulate('click');