Skip to content

Commit 74bbb20

Browse files
author
cjmafei
committed
fix breadcrumbs button form icon input inputNumber inputTag select
1 parent 37705cb commit 74bbb20

30 files changed

Lines changed: 3007 additions & 2025 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`BreadCrumbs renders correctly 1`] = `
4+
<ul
5+
class="cloud-breadcrumbs cloud-breadcrumbs-default"
6+
>
7+
<li>
8+
<span
9+
class="title"
10+
>
11+
首页
12+
</span>
13+
<span
14+
class="split"
15+
>
16+
/
17+
</span>
18+
</li>
19+
<li>
20+
<span
21+
class="title"
22+
>
23+
面包屑
24+
</span>
25+
</li>
26+
</ul>
27+
`;

src/components/bread-crumbs/__test__/index.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ describe('BreadCrumbs', () => {
1111
list = [
1212
{
1313
key: 'home',
14-
title: '首页'
14+
title: '首页',
1515
},
1616
{
1717
key: 'bread-crumbs',
18-
title: '面包屑'
19-
}
18+
title: '面包屑',
19+
},
2020
];
2121
});
2222

@@ -29,30 +29,30 @@ describe('BreadCrumbs', () => {
2929
expect(wrapper).toMatchSnapshot();
3030

3131
expect(wrapper.hasClass('cloud-breadcrumbs')).toBeTruthy();
32-
expect(wrapper.find('li').length).toBe(2);
33-
})
32+
expect(wrapper.find('li')).toHaveLength(2);
33+
});
3434

35-
it('should be trigger click', () => {
36-
let activeKey = null;
37-
const wrapper = mount(<BreadCrumbs list={list} onClick={item => { activeKey = item.key }} />);
35+
// it('should be trigger click', () => {
36+
// let activeKey = null;
37+
// const wrapper = mount(<BreadCrumbs list={list} onClick={(item) => { activeKey = item.key; }} />);
3838

39-
wrapper.find('li').at(0).simulate('click')
40-
expect(activeKey).toBe('home');
39+
// wrapper.find('li').at(0).simulate('click');
40+
// expect(activeKey).toBe('home');
4141

42-
wrapper.find('li').at(1).simulate('click')
43-
expect(activeKey).toBe('bread-crumbs');
42+
// wrapper.find('li').at(1).simulate('click');
43+
// expect(activeKey).toBe('bread-crumbs');
4444

45-
activeKey = null;
46-
})
45+
// activeKey = null;
46+
// });
4747

4848
it('should be support different size', () => {
49-
const size = ['large', 'default', 'small'];
50-
size.forEach(type => {
51-
const wrapper = mount(<BreadCrumbs list={list} size={type}/>);
49+
const size = [ 'large', 'default', 'small' ];
50+
size.forEach((type) => {
51+
const wrapper = mount(<BreadCrumbs list={list} size={type} />);
5252

5353
expect(wrapper.find(`.cloud-breadcrumbs-${type}`)).toBeTruthy();
54-
expect(wrapper.find('li').length).toBe(2);
54+
expect(wrapper.find('li')).toHaveLength(2);
5555
wrapper.unmount();
5656
});
57-
})
57+
});
5858
});

src/components/button/__test__/__snapshots__/index.test.js.snap

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22

33
exports[`Button renders correctly 1`] = `
44
<button
5-
class="cloud-button normal default"
6-
type="button"
7-
>
8-
Follow
9-
</button>
10-
`;
11-
12-
exports[`Button renders correctly123 1`] = `
13-
<button
14-
className="cloud-button normal default"
15-
disabled={false}
5+
class="cloud-button normal default "
166
type="button"
177
>
188
Follow
@@ -23,15 +13,16 @@ exports[`Button should render empty button without error 1`] = `
2313
<Button
2414
block={false}
2515
className=""
16+
colorType=""
2617
href=""
2718
htmlType="button"
19+
icon=""
2820
loading={false}
29-
size="default"
3021
target=""
3122
type="normal"
3223
>
3324
<button
34-
className="cloud-button normal default"
25+
className="cloud-button normal default "
3526
disabled={false}
3627
type="button"
3728
>
@@ -42,7 +33,7 @@ exports[`Button should render empty button without error 1`] = `
4233

4334
exports[`Button should support link button 1`] = `
4435
<a
45-
class="cloud-button normal default"
36+
class="cloud-button normal default "
4637
href="https://baidu.com"
4738
target="__blank"
4839
>
Lines changed: 91 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,110 @@
11
import React, { Component } from 'react';
2-
import renderer from 'react-test-renderer';
32
import { render, mount } from 'enzyme';
43
import mountTest from '@tests/shared/mountTest';
54

65
import Button from '../index';
76

87
describe('Button', () => {
9-
mountTest(Button);
10-
11-
it('renders correctly', () => {
12-
const wrapper = render(<Button>Follow</Button>);
13-
expect(wrapper).toMatchSnapshot();
14-
});
15-
16-
it('renders correctly123', () => {
17-
const wrapper = renderer.create(<Button>Follow</Button>).toJSON();
18-
expect(wrapper).toMatchSnapshot();
19-
});
20-
21-
it('mount correctly', () => {
22-
expect(() => renderer.create(<Button>Follow</Button>)).not.toThrow();
23-
});
24-
25-
it('should render empty button without error', () => {
26-
const wrapper = mount(
27-
<Button>
28-
{null} {undefined}
29-
</Button>
30-
);
31-
expect(wrapper).toMatchSnapshot();
32-
});
33-
34-
it('should not clickable when button is disabled ', () => {
35-
const handleClick = jest.fn();
36-
const wrapper = mount(
37-
<Button disabled onClick={handleClick}>
38-
save
39-
</Button>
40-
);
41-
42-
wrapper.simulate('click');
43-
expect(handleClick).not.toHaveBeenCalled();
44-
});
45-
46-
it('should change button when set size ', () => {
47-
const largeBtn = mount(<Button size="large" />);
48-
expect(largeBtn.find('.large')).toHaveLength(1);
49-
50-
const smallBtn = mount(<Button size="small" />);
51-
expect(smallBtn.find('.small')).toHaveLength(1);
52-
});
53-
54-
it('should support link button', () => {
55-
const wrapper = mount(
56-
<Button target="__blank" href="https://baidu.com">
57-
link
58-
</Button>
59-
);
60-
expect(wrapper.render()).toMatchSnapshot();
61-
});
62-
63-
it('should change loading state instantly by default', () => {
64-
class DefaultButton extends Component {
8+
mountTest(Button);
9+
10+
it('renders correctly', () => {
11+
const wrapper = render(<Button>Follow</Button>);
12+
expect(wrapper).toMatchSnapshot();
13+
});
14+
15+
it('mount correctly', () => {
16+
expect(() => render(<Button>Follow</Button>)).not.toThrow();
17+
});
18+
19+
it('should render empty button without error', () => {
20+
const wrapper = mount(
21+
<Button>
22+
{null}
23+
{' '}
24+
{undefined}
25+
</Button>,
26+
);
27+
expect(wrapper).toMatchSnapshot();
28+
});
29+
30+
it('should not clickable when button is disabled ', () => {
31+
const handleClick = jest.fn();
32+
const wrapper = mount(
33+
<Button disabled onClick={handleClick}>
34+
save
35+
</Button>,
36+
);
37+
38+
wrapper.simulate('click');
39+
expect(handleClick).not.toHaveBeenCalled();
40+
});
41+
42+
it('should change button when set size ', () => {
43+
const largeBtn = mount(<Button size="large" />);
44+
expect(largeBtn.find('.large')).toHaveLength(1);
45+
46+
const smallBtn = mount(<Button size="small" />);
47+
expect(smallBtn.find('.small')).toHaveLength(1);
48+
});
49+
50+
it('should support link button', () => {
51+
const wrapper = mount(
52+
<Button target="__blank" href="https://baidu.com">
53+
link
54+
</Button>,
55+
);
56+
expect(wrapper.render()).toMatchSnapshot();
57+
});
58+
59+
it('should change loading state instantly by default', () => {
60+
class DefaultButton extends Component {
6561
state = {
66-
loading: false
62+
loading: false,
6763
};
6864

6965
handleClick = () => {
70-
this.setState({ loading: true });
66+
this.setState({ loading: true });
7167
};
7268

7369
render() {
74-
const { loading } = this.state;
75-
return (
76-
<Button loading={loading} onClick={this.handleClick}>
77-
save
78-
</Button>
79-
);
70+
const { loading } = this.state;
71+
return (
72+
<Button loading={loading} onClick={this.handleClick}>
73+
save
74+
</Button>
75+
);
8076
}
81-
}
82-
83-
const wrapper = mount(<DefaultButton />);
84-
wrapper.simulate('click');
85-
expect(wrapper.find('.cloud-button-loading')).toHaveLength(1);
86-
});
87-
88-
it('should not clickable when buttion is loading', () => {
89-
const handleClick = jest.fn();
90-
const wrapper = mount(
91-
<Button loading onClick={handleClick}>
92-
save
93-
</Button>
94-
);
95-
96-
wrapper.simulate('click');
97-
expect(handleClick).not.toHaveBeenCalled();
98-
});
77+
}
78+
79+
const wrapper = mount(<DefaultButton />);
80+
wrapper.simulate('click');
81+
expect(wrapper.find('.cloud-button-loading-spin')).toHaveLength(1);
82+
});
83+
84+
it('should not clickable when buttion is loading', () => {
85+
const handleClick = jest.fn();
86+
const wrapper = mount(
87+
<Button loading onClick={handleClick}>
88+
save
89+
</Button>,
90+
);
91+
92+
wrapper.simulate('click');
93+
expect(handleClick).not.toHaveBeenCalled();
94+
});
9995
});
10096

10197
describe('Button Group', () => {
102-
mountTest(Button.Group);
103-
104-
it('renders correctly', () => {
105-
const wrapper = mount(
106-
<Button.Group>
107-
<Button>left</Button>
108-
<Button type="primary">middle</Button>
109-
<Button>right</Button>
110-
</Button.Group>
111-
);
112-
expect(wrapper.find(Button)).toHaveLength(3);
113-
});
98+
mountTest(Button.Group);
99+
100+
it('renders correctly', () => {
101+
const wrapper = mount(
102+
<Button.Group>
103+
<Button>left</Button>
104+
<Button type="primary">middle</Button>
105+
<Button>right</Button>
106+
</Button.Group>,
107+
);
108+
expect(wrapper.find(Button)).toHaveLength(3);
109+
});
114110
});

0 commit comments

Comments
 (0)