steps.test.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { markRaw, nextTick } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, test } from 'vitest'
  4. import { Edit } from '@element-plus/icons-vue'
  5. import Steps from '../src/steps.vue'
  6. import Step from '../src/item.vue'
  7. import type { VNode } from 'vue'
  8. const _mount = (render: () => VNode) =>
  9. mount({
  10. setup() {
  11. return render
  12. },
  13. attachTo: document.body,
  14. global: {
  15. provide: {
  16. ElSteps: {},
  17. },
  18. },
  19. })
  20. describe('Steps.vue', () => {
  21. test('render', () => {
  22. const wrapper = _mount(() => (
  23. <Steps>
  24. <Step />
  25. <Step />
  26. <Step />
  27. </Steps>
  28. ))
  29. expect(wrapper.findAll('.el-step').length).toBe(3)
  30. expect(wrapper.classes()).toContain('el-steps--horizontal')
  31. expect(wrapper.find('.el-step').classes()).toContain('is-horizontal')
  32. })
  33. test('space', () => {
  34. const wrapper = _mount(() => (
  35. <Steps space={100}>
  36. <Step />
  37. </Steps>
  38. ))
  39. expect(wrapper.find('.el-step').attributes('style')).toMatch(
  40. 'flex-basis: 100px;'
  41. )
  42. })
  43. test('alignCenter', () => {
  44. const wrapper = _mount(() => (
  45. <Steps alignCenter>
  46. <Step />
  47. </Steps>
  48. ))
  49. expect(wrapper.find('.el-step').classes()).toContain('is-center')
  50. })
  51. test('direction', () => {
  52. const wrapper = _mount(() => (
  53. <Steps direction="vertical">
  54. <Step />
  55. </Steps>
  56. ))
  57. expect(wrapper.classes()).toContain('el-steps--vertical')
  58. expect(wrapper.find('.el-step').classes()).toContain('is-vertical')
  59. })
  60. test('simple', () => {
  61. const wrapper = _mount(() => (
  62. <Steps simple direction="vertical" space={100} alignCenter>
  63. <Step />
  64. </Steps>
  65. ))
  66. expect(wrapper.classes()).toContain('el-steps--simple')
  67. expect(wrapper.find('is-center').exists()).toBe(false)
  68. expect(wrapper.find('is-vertical').exists()).toBe(false)
  69. })
  70. test('active', async () => {
  71. const wrapper = _mount(() => (
  72. <Steps active={0}>
  73. <Step />
  74. <Step />
  75. <Step />
  76. </Steps>
  77. ))
  78. await nextTick()
  79. expect(
  80. wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
  81. ).toContain('is-process')
  82. expect(
  83. wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
  84. ).toContain('is-wait')
  85. expect(
  86. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  87. ).toContain('is-wait')
  88. await wrapper.setProps({ active: 1 })
  89. expect(
  90. wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
  91. ).toContain('is-finish')
  92. expect(
  93. wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
  94. ).toContain('is-process')
  95. expect(
  96. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  97. ).toContain('is-wait')
  98. await wrapper.setProps({ active: 2 })
  99. expect(
  100. wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
  101. ).toContain('is-finish')
  102. expect(
  103. wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
  104. ).toContain('is-finish')
  105. expect(
  106. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  107. ).toContain('is-process')
  108. await wrapper.setProps({ active: 3 })
  109. expect(
  110. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  111. ).toContain('is-finish')
  112. })
  113. test('process-status', async () => {
  114. const wrapper = _mount(() => (
  115. <Steps active={2} process-status="success">
  116. <Step />
  117. <Step />
  118. <Step />
  119. </Steps>
  120. ))
  121. await nextTick()
  122. expect(
  123. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  124. ).toContain('is-success')
  125. await wrapper.setProps({ processStatus: 'error' })
  126. expect(
  127. wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
  128. ).toContain('is-error')
  129. })
  130. test('finish-status', async () => {
  131. const wrapper = _mount(() => (
  132. <Steps active={2} finish-status="error">
  133. <Step />
  134. <Step />
  135. <Step />
  136. </Steps>
  137. ))
  138. await nextTick()
  139. expect(
  140. wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
  141. ).toContain('is-error')
  142. await wrapper.setProps({ finishStatus: 'success' })
  143. expect(
  144. wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
  145. ).toContain('is-success')
  146. })
  147. test('step attribute', () => {
  148. const wrapper = mount({
  149. setup() {
  150. const iconEdit = markRaw(Edit)
  151. return () => (
  152. <Steps active={0}>
  153. <Step
  154. icon={iconEdit}
  155. title="title"
  156. description="description"
  157. status="wait"
  158. />
  159. </Steps>
  160. )
  161. },
  162. })
  163. expect(wrapper.find('.el-step__head').classes()).toContain('is-wait')
  164. expect(wrapper.find('.el-step__title').text()).toBe('title')
  165. expect(wrapper.find('.el-step__description').text()).toBe('description')
  166. expect(wrapper.findComponent(Edit).exists()).toBe(true)
  167. })
  168. test('step slot', () => {
  169. const wrapper = _mount(() => (
  170. <Steps active={0}>
  171. <Step
  172. v-slots={{
  173. title: () => 'A',
  174. description: () => 'B',
  175. }}
  176. />
  177. </Steps>
  178. ))
  179. expect(wrapper.find('.el-step__title').text()).toBe('A')
  180. expect(wrapper.find('.el-step__description').text()).toBe('B')
  181. })
  182. })