steps.spec.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { createVue, destroyVM, waitImmediate } from '../util';
  2. describe('Steps', () => {
  3. let vm;
  4. afterEach(() => {
  5. destroyVM(vm);
  6. });
  7. it('create', () => {
  8. vm = createVue(`
  9. <el-steps>
  10. <el-step title="step1"></el-step>
  11. <el-step title="step2"></el-step>
  12. <el-step title="step3"></el-step>
  13. </el-steps>
  14. `);
  15. expect(vm.$el.querySelectorAll('.el-step')).to.length(3);
  16. });
  17. it('space', async() => {
  18. vm = createVue(`
  19. <el-steps>
  20. <el-step title="step1"></el-step>
  21. <el-step title="step2"></el-step>
  22. <el-step title="step3"></el-step>
  23. </el-steps>
  24. `, true);
  25. const vm2 = createVue(`
  26. <el-steps :space="100">
  27. <el-step title="step1"></el-step>
  28. <el-step title="step2"></el-step>
  29. <el-step title="step3"></el-step>
  30. <el-step title="step4"></el-step>
  31. </el-steps>
  32. `, true);
  33. await waitImmediate();
  34. const stepElm = vm.$el.querySelector('.el-step');
  35. const stepElm2 = vm2.$el.querySelector('.el-step');
  36. expect(getComputedStyle(stepElm).flexBasis).to.equal('50%');
  37. expect(getComputedStyle(stepElm2).flexBasis).to.equal('100px');
  38. });
  39. it('processStatus', done => {
  40. vm = createVue(`
  41. <el-steps :active="1" process-status="error">
  42. <el-step title="step1"></el-step>
  43. <el-step title="step2"></el-step>
  44. <el-step title="step3"></el-step>
  45. </el-steps>
  46. `);
  47. vm.$nextTick(_ => {
  48. expect(vm.$el.querySelectorAll('.el-step__head.is-error')).to.length(1);
  49. done();
  50. });
  51. });
  52. it('update processStatus', done => {
  53. vm = createVue({
  54. template: `
  55. <el-steps :active="1" :process-status="processStatus">
  56. <el-step title="abc"></el-step>
  57. <el-step title="abc2"></el-step>
  58. </el-steps>
  59. `,
  60. data() {
  61. return { processStatus: 'error' };
  62. }
  63. });
  64. vm.$nextTick(_ => {
  65. expect(vm.$el.querySelectorAll('.el-step__head.is-error')).to.length(1);
  66. vm.processStatus = 'process';
  67. vm.$nextTick(_ => {
  68. expect(vm.$el.querySelectorAll('.el-step__head.is-process')).to.length(1);
  69. done();
  70. });
  71. });
  72. });
  73. it('finishStatus', done => {
  74. vm = createVue(`
  75. <el-steps :active="1" finish-status="error">
  76. <el-step title="abc"></el-step>
  77. <el-step title="abc2"></el-step>
  78. </el-steps>
  79. `);
  80. vm.$nextTick(_ => {
  81. expect(vm.$el.querySelectorAll('.el-step__head.is-error')).to.length(1);
  82. done();
  83. });
  84. });
  85. it('active', done => {
  86. vm = createVue({
  87. template: `
  88. <el-steps :active="active" finish-status="error">
  89. <el-step title="abc"></el-step>
  90. <el-step title="abc2"></el-step>
  91. </el-steps>
  92. `,
  93. data() {
  94. return { active: 0 };
  95. }
  96. });
  97. vm.$nextTick(_ => {
  98. expect(vm.$el.querySelectorAll('.el-step__head.is-error')).to.length(0);
  99. vm.active = 2;
  100. vm.$nextTick(_ => {
  101. expect(vm.$el.querySelectorAll('.el-step__head.is-error')).to.length(2);
  102. done();
  103. });
  104. });
  105. });
  106. it('create vertical', () => {
  107. vm = createVue(`
  108. <el-steps direction="vertical">
  109. <el-step title="aaa"></el-step>
  110. <el-step title="bbb"></el-step>
  111. </el-steps>
  112. `);
  113. expect(vm.$el.querySelector('.is-vertical')).to.exist;
  114. });
  115. it('vertical:height', async() => {
  116. vm = createVue(`
  117. <el-steps direction="vertical" :space="200">
  118. <el-step title="aaa"></el-step>
  119. <el-step title="bbb"></el-step>
  120. </el-steps>
  121. `, true);
  122. await waitImmediate();
  123. const stepElm = vm.$el.querySelector('.el-step');
  124. expect(getComputedStyle(stepElm).flexBasis).to.equal('200px');
  125. });
  126. it('step:status=error', done => {
  127. vm = createVue(`
  128. <el-steps :active="2" process-status="process" finish-status="success" direction="horizontal">
  129. <el-step title="step1"></el-step>
  130. <el-step title="step2" status="error"></el-step>
  131. <el-step title="step3"></el-step>
  132. </el-steps>
  133. `);
  134. vm.$nextTick(_ => {
  135. const errorLine = vm.$el.querySelector('.el-step:nth-child(2) .el-step__line-inner');
  136. expect(errorLine.getBoundingClientRect().width).to.equal(0);
  137. const nextStep = vm.$el.querySelector('.el-step:nth-child(3) .el-step__head');
  138. expect(nextStep.classList.contains('is-wait')).to.equal(true);
  139. done();
  140. });
  141. });
  142. });