2018-03-11 00:11:52 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Progress from '..';
|
2019-03-24 17:05:24 +08:00
|
|
|
import { handleGradient, sortGradient } from '../Line';
|
2020-08-22 01:29:48 +08:00
|
|
|
import ProgressSteps from '../Steps';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2018-03-11 00:11:52 +08:00
|
|
|
|
|
|
|
describe('Progress', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Progress);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Progress);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2018-04-29 23:01:58 +08:00
|
|
|
it('successPercent should decide the progress status when it exists', () => {
|
2020-07-01 23:32:22 +08:00
|
|
|
const wrapper = mount(<Progress percent={100} success={{ percent: 50 }} />);
|
2018-03-11 00:11:52 +08:00
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
|
|
|
|
2020-07-01 23:32:22 +08:00
|
|
|
wrapper.setProps({ percent: 50, success: { percent: 100 } });
|
2018-03-11 00:11:52 +08:00
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
2019-02-10 23:06:45 +08:00
|
|
|
|
2020-07-01 23:32:22 +08:00
|
|
|
wrapper.setProps({ percent: 100, success: { percent: 0 } });
|
2019-02-10 23:06:45 +08:00
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
2018-03-11 00:11:52 +08:00
|
|
|
});
|
2018-04-18 10:45:07 +08:00
|
|
|
|
2018-04-29 23:01:58 +08:00
|
|
|
it('render out-of-range progress', () => {
|
2018-04-18 10:45:07 +08:00
|
|
|
const wrapper = mount(<Progress percent={120} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-04-29 23:01:58 +08:00
|
|
|
it('render out-of-range progress with info', () => {
|
2018-04-18 11:10:32 +08:00
|
|
|
const wrapper = mount(<Progress percent={120} showInfo />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-03-22 17:59:43 +08:00
|
|
|
it('render negative progress', () => {
|
2018-04-18 10:45:07 +08:00
|
|
|
const wrapper = mount(<Progress percent={-20} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-03-22 17:59:43 +08:00
|
|
|
it('render negative successPercent', () => {
|
2020-07-01 23:32:22 +08:00
|
|
|
const wrapper = mount(<Progress percent={50} success={{ percent: -20 }} />);
|
2018-04-18 10:45:07 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2018-04-29 23:01:58 +08:00
|
|
|
|
|
|
|
it('render format', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Progress
|
|
|
|
percent={50}
|
2020-07-01 23:32:22 +08:00
|
|
|
success={{ percent: 10 }}
|
2018-04-29 23:01:58 +08:00
|
|
|
format={(percent, successPercent) => `${percent} ${successPercent}`}
|
2018-12-07 16:17:45 +08:00
|
|
|
/>,
|
2018-04-29 23:01:58 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2018-10-13 01:19:41 +08:00
|
|
|
|
|
|
|
it('render strokeColor', () => {
|
|
|
|
const wrapper = mount(<Progress type="circle" percent={50} strokeColor="red" />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-03-24 17:05:24 +08:00
|
|
|
wrapper.setProps({
|
|
|
|
strokeColor: {
|
|
|
|
from: '#108ee9',
|
|
|
|
to: '#87d068',
|
|
|
|
},
|
|
|
|
type: 'line',
|
|
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper.setProps({
|
|
|
|
strokeColor: {
|
|
|
|
'0%': '#108ee9',
|
|
|
|
'100%': '#87d068',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
2018-10-13 01:19:41 +08:00
|
|
|
});
|
2018-12-04 21:42:04 +08:00
|
|
|
|
|
|
|
it('render normal progress', () => {
|
|
|
|
const wrapper = mount(<Progress status="normal" />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-03-24 17:05:24 +08:00
|
|
|
|
2020-02-25 11:11:19 +08:00
|
|
|
it('render trailColor progress', () => {
|
|
|
|
const wrapper = mount(<Progress status="normal" trailColor="#ffffff" />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-06-28 22:41:59 +08:00
|
|
|
it('render successColor progress', () => {
|
|
|
|
const wrapper = mount(
|
2020-07-01 23:32:22 +08:00
|
|
|
<Progress percent={60} success={{ percent: 30, strokeColor: '#ffffff' }} />,
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-03-22 17:59:43 +08:00
|
|
|
it('render dashboard zero gapDegree', () => {
|
|
|
|
const wrapper = mount(<Progress type="dashboard" gapDegree={0} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render dashboard 295 gapDegree', () => {
|
|
|
|
const wrapper = mount(<Progress type="dashboard" gapDegree={295} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render dashboard 296 gapDegree', () => {
|
|
|
|
const wrapper = mount(<Progress type="dashboard" gapDegree={296} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-03-24 17:05:24 +08:00
|
|
|
it('get correct line-gradient', () => {
|
|
|
|
expect(handleGradient({ from: 'test', to: 'test' }).backgroundImage).toBe(
|
|
|
|
'linear-gradient(to right, test, test)',
|
|
|
|
);
|
2020-08-20 17:15:40 +08:00
|
|
|
expect(handleGradient({}).backgroundImage).toBe('linear-gradient(to right, #1890FF, #1890FF)');
|
2019-03-24 17:05:24 +08:00
|
|
|
expect(handleGradient({ from: 'test', to: 'test', '0%': 'test' }).backgroundImage).toBe(
|
|
|
|
'linear-gradient(to right, test 0%)',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sort gradients correctly', () => {
|
|
|
|
expect(sortGradient({ '10%': 'test10', '30%': 'test30', '20%': 'test20' })).toBe(
|
|
|
|
'test10 10%, test20 20%, test30 30%',
|
|
|
|
);
|
2020-02-25 12:21:49 +08:00
|
|
|
expect(sortGradient({ '10%': 'test10', '30%': 'test30', '20%': 'test20', dummy: 'test' })).toBe(
|
|
|
|
'test10 10%, test20 20%, test30 30%',
|
|
|
|
);
|
2019-03-24 17:05:24 +08:00
|
|
|
});
|
2019-04-08 21:43:30 +08:00
|
|
|
|
|
|
|
it('should show success status when percent is 100', () => {
|
|
|
|
const wrapper = mount(<Progress percent={100} />);
|
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/15950
|
|
|
|
it('should show success status when percent is 100 and status is undefined', () => {
|
2019-04-08 22:33:12 +08:00
|
|
|
const wrapper = mount(<Progress percent={100} status={undefined} />);
|
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/pull/15951#discussion_r273062969
|
|
|
|
it('should show success status when status is invalid', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
const wrapper = mount(<Progress percent={100} status="invalid" />);
|
|
|
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
|
|
|
errorSpy.mockRestore();
|
2019-04-08 21:43:30 +08:00
|
|
|
});
|
2020-05-25 16:27:02 +08:00
|
|
|
|
|
|
|
it('should support steps', () => {
|
|
|
|
const wrapper = mount(<Progress steps={3} />);
|
|
|
|
expect(wrapper).toMatchRenderedSnapshot();
|
|
|
|
});
|
2020-05-29 13:43:53 +08:00
|
|
|
|
|
|
|
it('steps should be changable', () => {
|
|
|
|
const wrapper = mount(<Progress steps={5} percent={60} />);
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(3);
|
|
|
|
wrapper.setProps({ percent: 40 });
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('steps should be changable when has strokeColor', () => {
|
|
|
|
const wrapper = mount(<Progress steps={5} percent={60} strokeColor="#1890ff" />);
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item').at(0).getDOMNode().style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 255)',
|
|
|
|
);
|
|
|
|
wrapper.setProps({ percent: 40 });
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item').at(2).getDOMNode().style.backgroundColor).toBe(
|
|
|
|
'',
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item').at(1).getDOMNode().style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 255)',
|
|
|
|
);
|
|
|
|
});
|
2020-07-01 23:32:22 +08:00
|
|
|
|
2020-08-22 01:29:48 +08:00
|
|
|
it('steps should support trailColor', () => {
|
|
|
|
const wrapper = mount(<Progress steps={5} percent={20} trailColor="#1890ee" />);
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item').at(1).getDOMNode().style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 238)',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-29 12:20:11 +08:00
|
|
|
it('should display correct step', () => {
|
|
|
|
const wrapper = mount(<Progress steps={9} percent={22.22} />);
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(2);
|
|
|
|
wrapper.setProps({ percent: 33.33 });
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(3);
|
|
|
|
wrapper.setProps({ percent: 44.44 });
|
|
|
|
expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(4);
|
|
|
|
});
|
|
|
|
|
2020-08-22 01:29:48 +08:00
|
|
|
it('steps should have default percent 0', () => {
|
|
|
|
const wrapper = mount(<ProgressSteps />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-07-01 23:32:22 +08:00
|
|
|
it('should warnning if use `progress` in success', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2020-08-20 17:15:40 +08:00
|
|
|
mount(<Progress percent={60} success={{ progress: 30 }} />);
|
2020-07-01 23:32:22 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
2020-08-20 17:15:40 +08:00
|
|
|
});
|
2020-07-01 23:32:22 +08:00
|
|
|
|
2020-08-20 17:15:40 +08:00
|
|
|
it('should warnning if use `progress` in success in type Circle', () => {
|
2020-07-01 23:32:22 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2020-08-20 17:15:40 +08:00
|
|
|
mount(<Progress percent={60} success={{ progress: 30 }} type="circle" />);
|
2020-07-01 23:32:22 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
2020-08-20 17:15:40 +08:00
|
|
|
});
|
2021-06-05 13:25:19 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/30685
|
|
|
|
describe('github issues', () => {
|
|
|
|
it('"Rendered more hooks than during the previous render"', () => {
|
|
|
|
expect(() => {
|
|
|
|
const wrapper = mount(<Progress percent={60} success={{ percent: 0 }} type="circle" />);
|
|
|
|
wrapper.setProps({ success: { percent: 10 } });
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
2018-03-11 00:11:52 +08:00
|
|
|
});
|