progress.test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { mount } from 'enzyme';
  3. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  4. import Progress from '../index';
  5. const getProgress = (props = {}) => mount(<Progress {...props} />);
  6. describe('Progress', () => {
  7. it('percent pass invalid value like NaN', () => {
  8. const p = getProgress({ percent: 30 });
  9. function testNaN() {
  10. p.setProps({ percent: NaN });
  11. }
  12. expect(testNaN).toThrow('');
  13. });
  14. it('render successfully', () => {
  15. const p = getProgress();
  16. const node = p.find(`.${BASE_CLASS_PREFIX}-progress`);
  17. expect(node.length).toEqual(1);
  18. });
  19. it('render circle progress', () => {
  20. const p = getProgress({ type: 'circle' });
  21. const node = p.find(`svg.${BASE_CLASS_PREFIX}-progress-circle-ring`);
  22. expect(node.length).toEqual(1);
  23. });
  24. it('process change success', () => {
  25. const p = getProgress({ type: 'circle', percent: 30 });
  26. p.setProps({ percent: 50 });
  27. const percentNumber = p.state('percentNumber');
  28. setTimeout(() => {
  29. expect(percentNumber).toEqual(50);
  30. }, 500);
  31. });
  32. it('classname & style', () => {
  33. const p = getProgress({ className: 'test', color: 'red' });
  34. const node = p.find(`.${BASE_CLASS_PREFIX}-progress`);
  35. expect(node.length).toEqual(1);
  36. });
  37. it('showInfo', () => {
  38. const p = getProgress({ showInfo: true, percent: 50 });
  39. expect(p.exists('.semi-progress-line-text')).toEqual(true);
  40. });
  41. it('stroke & size & orbitStroke', () => {
  42. let props = {
  43. stroke: '#fc8800',
  44. size: 'small',
  45. orbitStroke: '#f93920'
  46. };
  47. const p = getProgress(props);
  48. expect(p.exists('.semi-progress-large'))
  49. });
  50. it('direction', () => {
  51. const p = getProgress({ direction: 'vertical' });
  52. expect(p.exists('.semi-progress-vertical')).toEqual(true);
  53. });
  54. it('format', () => {
  55. let props = {
  56. percent: 70,
  57. showInfo: true,
  58. format: () => 'semi',
  59. type: 'circle',
  60. };
  61. const p = getProgress(props);
  62. expect(p.find('.semi-progress-circle-text').text()).toEqual('semi');
  63. });
  64. it('strokeLinecap & strokeWidth', () => {
  65. let props = {
  66. percent: 70,
  67. strokeLinecap: 'square',
  68. type: 'circle',
  69. strokeWidth: 10,
  70. };
  71. const p = getProgress(props);
  72. let firstCircle = p.find('circle').at(0).getDOMNode();
  73. expect(firstCircle.getAttribute('stroke-linecap')).toEqual('square');
  74. expect(firstCircle.getAttribute('stroke-width')).toEqual('10');
  75. });
  76. it('width', () => {
  77. let props = {
  78. width: 120,
  79. type: 'circle'
  80. }
  81. const p = getProgress(props);
  82. let svgRing = p.find('.semi-progress-circle-ring').at(0).getDOMNode();
  83. expect(svgRing.getAttribute('width')).toEqual('120');
  84. });
  85. it('motion = false', () => {
  86. let props = {
  87. motion: false,
  88. percent: 70,
  89. showInfo: true
  90. }
  91. const p = getProgress(props);
  92. expect(p.find('.semi-progress-line-text').text()).toEqual('70%');
  93. p.setProps({ percent: 80 });
  94. p.update();
  95. expect(p.find('.semi-progress-line-text').text()).toEqual('80%');
  96. p.unmount();
  97. });
  98. it('pass invalid percent like 101, -1', () => {
  99. let props = {
  100. percent: 101,
  101. showInfo: true,
  102. };
  103. const p = getProgress(props);
  104. expect(p.find('.semi-progress-line-text').text()).toEqual('100%');
  105. let minProps = {
  106. percent: -2,
  107. showInfo: true,
  108. };
  109. const minp = getProgress(minProps);
  110. expect(minp.find('.semi-progress-line-text').text()).toEqual('0%');
  111. });
  112. });