add more test cases for Button

This commit is contained in:
afc163 2019-09-07 19:45:06 +08:00 committed by 偏右
parent c2bcf44f62
commit 4338a5b7cf
2 changed files with 134 additions and 0 deletions

View File

@ -188,6 +188,17 @@ exports[`Button renders Chinese characters correctly 6`] = `
</button>
`;
exports[`Button renders Chinese characters correctly 7`] = `
<button
class="ant-btn"
type="button"
>
<span>
按 钮
</span>
</button>
`;
exports[`Button renders correctly 1`] = `
<button
class="ant-btn"
@ -244,6 +255,23 @@ exports[`Button should not render as link button when href is undefined 1`] = `
</button>
`;
exports[`Button should render empty button without errors 1`] = `
<Button
block={false}
ghost={false}
htmlType="button"
loading={false}
>
<Wave>
<button
className="ant-btn"
onClick={[Function]}
type="button"
/>
</Wave>
</Button>
`;
exports[`Button should support link button 1`] = `
<a
class="ant-btn"
@ -255,3 +283,66 @@ exports[`Button should support link button 1`] = `
</span>
</a>
`;
exports[`Button should support to change loading 1`] = `
<button
class="ant-btn ant-btn-loading"
type="button"
>
<i
aria-label="icon: loading"
class="anticon anticon-loading"
>
<svg
aria-hidden="true"
class="anticon-spin"
data-icon="loading"
fill="currentColor"
focusable="false"
height="1em"
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 0 0-94.3-139.9 437.71 437.71 0 0 0-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z"
/>
</svg>
</i>
<span>
Button
</span>
</button>
`;
exports[`Button should support to change loading 2`] = `
<button
class="ant-btn"
type="button"
>
<span>
Button
</span>
</button>
`;
exports[`Button should support to change loading 3`] = `
<button
class="ant-btn"
type="button"
>
<span>
Button
</span>
</button>
`;
exports[`Button should support to change loading 4`] = `
<button
class="ant-btn"
type="button"
>
<span>
Button
</span>
</button>
`;

View File

@ -7,7 +7,11 @@ import mountTest from '../../../tests/shared/mountTest';
describe('Button', () => {
mountTest(Button);
mountTest(() => <Button size="large" />);
mountTest(() => <Button size="small" />);
mountTest(Button.Group);
mountTest(() => <Button.Group size="large" />);
mountTest(() => <Button.Group size="small" />);
it('renders correctly', () => {
const wrapper = render(<Button>Follow</Button>);
@ -48,6 +52,10 @@ describe('Button', () => {
// should insert space while loading
const wrapper5 = render(<Button loading>按钮</Button>);
expect(wrapper5).toMatchSnapshot();
// should insert space while only one nested element
const wrapper6 = render(<Button><span>按钮</span></Button>);
expect(wrapper6).toMatchSnapshot();
});
it('renders Chinese characters correctly in HOC', () => {
@ -76,6 +84,11 @@ describe('Button', () => {
expect(wrapper).toMatchSnapshot();
});
it('should render empty button without errors', () => {
const wrapper = mount(<Button />);
expect(wrapper).toMatchSnapshot();
});
it('have static property for type detecting', () => {
const wrapper = mount(<Button>Button Text</Button>);
// eslint-disable-next-line
@ -131,6 +144,17 @@ describe('Button', () => {
expect(wrapper.hasClass('ant-btn-loading')).toBe(false);
});
it('should not clickable when button is loading', () => {
const onClick = jest.fn();
const wrapper = mount(
<Button loading onClick={onClick}>
button
</Button>,
);
wrapper.simulate('click');
expect(onClick).not.toHaveBeenCalledWith();
});
it('should support link button', () => {
const wrapper = mount(
<Button target="_blank" href="http://ant.design">
@ -178,4 +202,23 @@ describe('Button', () => {
expect(wrapper.render()).toMatchSnapshot();
});
it('should support to change loading', () => {
const wrapper = mount(
<Button>
Button
</Button>,
);
wrapper.setProps({ loading: true });
expect(wrapper.render()).toMatchSnapshot();
wrapper.setProps({ loading: false });
expect(wrapper.render()).toMatchSnapshot();
wrapper.setProps({ loading: { delay: 200 } });
expect(wrapper.render()).toMatchSnapshot();
wrapper.setProps({ loading: false });
expect(wrapper.render()).toMatchSnapshot();
expect(() => {
wrapper.unmount();
}).not.toThrow();
});
});