2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-09-25 08:51:32 +00:00
|
|
|
import { asyncExpect } from '../../../tests/utils';
|
|
|
|
import { handleGradient, sortGradient } from '../Line';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Progress from '..';
|
2021-09-25 08:51:32 +00:00
|
|
|
import ProgressSteps from '../Steps';
|
2018-06-06 02:48:15 +00:00
|
|
|
|
|
|
|
describe('Progress', () => {
|
|
|
|
it('successPercent should decide the progress status when it exists', async () => {
|
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-06-06 02:48:15 +00:00
|
|
|
percent: 100,
|
2021-09-25 08:51:32 +00:00
|
|
|
success: { percent: 50 },
|
2018-06-06 02:48:15 +00:00
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-06 02:48:15 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(0);
|
|
|
|
});
|
2018-06-06 02:48:15 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
wrapper.setProps({ percent: 50, success: { percent: 100 } });
|
2018-06-06 02:48:15 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(1);
|
|
|
|
});
|
2019-04-30 05:31:21 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
wrapper.setProps({ percent: 100, success: { percent: 0 } });
|
2019-04-30 05:31:21 +00:00
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(0);
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('render out-of-range progress', async () => {
|
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
percent: 120,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('render out-of-range progress with info', async () => {
|
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
percent: 120,
|
|
|
|
showInfo: true,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
it('render negative progress', async () => {
|
2018-09-05 13:28:54 +00:00
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
percent: -20,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
it('render negative successPercent', async () => {
|
2018-09-05 13:28:54 +00:00
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
percent: 50,
|
2021-09-25 08:51:32 +00:00
|
|
|
success: { percent: -20 },
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
it('render format', async () => {
|
2018-09-05 13:28:54 +00:00
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
percent: 50,
|
2021-09-25 08:51:32 +00:00
|
|
|
success: { percent: 10 },
|
2018-09-05 13:28:54 +00:00
|
|
|
format: (percent, successPercent) => `${percent} ${successPercent}`,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-10-30 07:10:16 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
it('render strokeColor', async () => {
|
2018-10-30 07:10:16 +00:00
|
|
|
const wrapper = mount(Progress, {
|
2020-06-26 02:08:47 +00:00
|
|
|
props: {
|
2018-10-30 07:10:16 +00:00
|
|
|
percent: 50,
|
|
|
|
type: 'circle',
|
|
|
|
strokeColor: 'red',
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-10-30 07:10:16 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2021-09-25 08:51:32 +00:00
|
|
|
wrapper.setProps({
|
|
|
|
strokeColor: {
|
|
|
|
from: '#108ee9',
|
|
|
|
to: '#87d068',
|
|
|
|
},
|
|
|
|
type: 'line',
|
|
|
|
});
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
wrapper.setProps({
|
|
|
|
strokeColor: {
|
|
|
|
'0%': '#108ee9',
|
|
|
|
'100%': '#87d068',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2019-01-05 03:24:25 +00:00
|
|
|
|
|
|
|
it('render normal progress', () => {
|
2020-06-26 02:08:47 +00:00
|
|
|
const wrapper = mount(Progress, { props: { status: 'normal' } });
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2021-09-25 08:51:32 +00:00
|
|
|
|
|
|
|
it('render trailColor progress', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress status="normal" trailColor="#ffffff" />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render successColor progress', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress percent={60} success={{ percent: 30, strokeColor: '#ffffff' }} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render dashboard zero gapDegree', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress type="dashboard" gapDegree={0} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render dashboard 295 gapDegree', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress type="dashboard" gapDegree={295} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render dashboard 296 gapDegree', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress type="dashboard" gapDegree={296} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('get correct line-gradient', () => {
|
|
|
|
expect(handleGradient({ from: 'test', to: 'test' }).backgroundImage).toBe(
|
|
|
|
'linear-gradient(to right, test, test)',
|
|
|
|
);
|
|
|
|
expect(handleGradient({}).backgroundImage).toBe('linear-gradient(to right, #1890ff, #1890ff)');
|
|
|
|
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%',
|
|
|
|
);
|
|
|
|
expect(sortGradient({ '10%': 'test10', '30%': 'test30', '20%': 'test20', dummy: 'test' })).toBe(
|
|
|
|
'test10 10%, test20 20%, test30 30%',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show success status when percent is 100', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress percent={100} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.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', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress percent={100} status={undefined} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.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({
|
|
|
|
// render() {
|
|
|
|
// return <Progress percent={100} status="invalid" />;
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(1);
|
|
|
|
// errorSpy.mockRestore();
|
|
|
|
// });
|
|
|
|
|
|
|
|
it('should support steps', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress steps={3} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('steps should be changable', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress steps={5} percent={60} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item-active').length).toBe(3);
|
|
|
|
wrapper.setProps({ percent: 40 });
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item-active').length).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('steps should be changable when has strokeColor', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress steps={5} percent={60} strokeColor="#1890ff" />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item')[0].element.style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 255)',
|
|
|
|
);
|
|
|
|
wrapper.setProps({ percent: 40 });
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item')[2].element.style.backgroundColor).toBe('');
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item')[1].element.style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 255)',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('steps should support trailColor', () => {
|
|
|
|
const wrapper = mount(<Progress steps={5} percent={20} trailColor="#1890ee" />);
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item')[1].element.style.backgroundColor).toBe(
|
|
|
|
'rgb(24, 144, 238)',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display correct step', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Progress steps={9} percent={22.22} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item-active').length).toBe(2);
|
|
|
|
wrapper.setProps({ percent: 33.33 });
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item-active').length).toBe(3);
|
|
|
|
});
|
|
|
|
wrapper.setProps({ percent: 44.44 });
|
|
|
|
await asyncExpect(() => {
|
|
|
|
expect(wrapper.findAll('.ant-progress-steps-item-active').length).toBe(4);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('steps should have default percent 0', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <ProgressSteps />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should warning if use `progress` in success', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
mount(<Progress percent={60} success={{ progress: 30 }} />);
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [ant-design-vue: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should warning if use `progress` in success in type Circle', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
mount({
|
|
|
|
render() {
|
|
|
|
return <Progress percent={60} success={{ progress: 30 }} type="circle" />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [ant-design-vue: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|