Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/uiw-react/uiw
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 17, 2017
2 parents 315cedf + 4cf8d63 commit fac3701
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/button/__test__/Button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { mount } from 'enzyme';
import Button from '../';

describe('<Button>', () => {
const Component = mount(<Button icon="arrow-down"> Normal</Button >)

it('The name of module must be "Button"', () => {
expect(Component.name()).toBe('Button')
});

it('The props size should be one of ["large","default","small","mini"]', () => {
expect(["large", "default", "small", "mini"]).toContain(Component.prop('size'))
});

it('The props type should be one of ["default", "primary", "success", "info", "warn", "error", "danger", "link"]', () => {
expect(["default", "primary", "success", "info", "warn", "error", "danger", "link"]).toContain(Component.prop('type'))
});

it('The props htmlType should be one of ["submit","reset","button"]', () => {
expect(["submit", "reset", "button"]).toContain(Component.prop('htmlType'))
});

it('Should an `icon` can be found in button', () => {
expect(Component.find('.w-icon-arrow-down')).toHaveLength(1)
});

it('Should class `block` can be found in button', () => {
Component.setProps({ block: true })
expect(Component.find('button.w-btn').hasClass('block')).toBe(true)
Component.setProps({ block: false })
});

it('Button can\'t be Click when props disabled or loading is true', () => {
let shouldBeFalse = false;
Component.setProps({
disabled: true,
onClick: () => {
shouldBeFalse = true;
}
})
expect(Component.prop('disabled')).toBe(true)
Component.find('button').simulate('click')
expect(shouldBeFalse).toBe(false)

Component.setProps({
disabled: false,
loading: true
})
Component.find('button').simulate('click')
expect(shouldBeFalse).toBe(false)
});
});
4 changes: 4 additions & 0 deletions src/button/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
cursor: @cursor-disabled;
opacity: .75;
box-shadow: none;
color:#bfbfbf;
&:hover{
color:#bfbfbf;
}
}
&.block {
display: block;
Expand Down
30 changes: 30 additions & 0 deletions src/loading/__test__/Loading.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { mount } from 'enzyme';
import { Loading } from '../../../src';


describe('<Loading>', () => {
var wrapper = mount(<Loading></Loading>);

it('Test the default props and node.',() => {
expect(wrapper.name()).toBe('Loading');
// 默认值测试
expect(wrapper.find('.w-loading')).toHaveLength(1);
expect(wrapper.type()).toEqual(Loading);
expect(wrapper.at(0).prop('prefixCls')).toBe('w-loading');
expect(wrapper.at(0).prop('loading')).toBe(true);
expect(wrapper.at(0).prop('size')).toBe('default');
})

it('Test size attributes.', () => {
wrapper.setProps({ size: 'large' });
expect(wrapper.find('.w-loading').at(0).prop('className')).toBe('w-loading w-loading-large');
});

it('Test tip attributes.', () => {
wrapper.setProps({ tip: '正在哈哈哈' });
let loading = wrapper.find('.w-loading').at(0);
expect(loading.html()).toContain('<div class="w-loading w-loading-large"><div class="w-loading-tips"><div class="w-loading-tips-nested"><div class="w-loading-icon"></div>正在哈哈哈</div></div></div>');
});

})

0 comments on commit fac3701

Please sign in to comment.