2022-03-25 15:35:56 +08:00
|
|
|
import { markRaw, nextTick } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2021-12-04 11:20:06 +08:00
|
|
|
import { Edit } from '@element-plus/icons-vue'
|
2022-05-20 19:39:34 +08:00
|
|
|
import Steps from '../src/steps.vue'
|
2020-08-12 13:50:44 +08:00
|
|
|
import Step from '../src/item.vue'
|
2022-07-03 17:15:42 +08:00
|
|
|
import type { VNode } from 'vue'
|
2020-08-12 13:50:44 +08:00
|
|
|
|
2022-07-03 17:15:42 +08:00
|
|
|
const _mount = (render: () => VNode) =>
|
|
|
|
mount({
|
|
|
|
setup() {
|
|
|
|
return render
|
2020-08-12 13:50:44 +08:00
|
|
|
},
|
2022-07-03 17:15:42 +08:00
|
|
|
attachTo: document.body,
|
|
|
|
global: {
|
|
|
|
provide: {
|
|
|
|
ElSteps: {},
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
2022-07-03 17:15:42 +08:00
|
|
|
},
|
|
|
|
})
|
2020-08-12 13:50:44 +08:00
|
|
|
|
|
|
|
describe('Steps.vue', () => {
|
|
|
|
test('render', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps>
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.findAll('.el-step').length).toBe(3)
|
|
|
|
expect(wrapper.classes()).toContain('el-steps--horizontal')
|
|
|
|
expect(wrapper.find('.el-step').classes()).toContain('is-horizontal')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('space', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps space={100}>
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-step').attributes('style')).toMatch(
|
|
|
|
'flex-basis: 100px;'
|
|
|
|
)
|
2020-08-12 13:50:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('alignCenter', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps alignCenter>
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.find('.el-step').classes()).toContain('is-center')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('direction', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps direction="vertical">
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-steps--vertical')
|
|
|
|
expect(wrapper.find('.el-step').classes()).toContain('is-vertical')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('simple', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps simple direction="vertical" space={100} alignCenter>
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-steps--simple')
|
|
|
|
expect(wrapper.find('is-center').exists()).toBe(false)
|
|
|
|
expect(wrapper.find('is-vertical').exists()).toBe(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('active', async () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps active={0}>
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
|
|
|
|
).toContain('is-process')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
|
|
|
|
).toContain('is-wait')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-wait')
|
2020-08-12 13:50:44 +08:00
|
|
|
await wrapper.setProps({ active: 1 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
|
|
|
|
).toContain('is-finish')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
|
|
|
|
).toContain('is-process')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-wait')
|
2020-08-12 13:50:44 +08:00
|
|
|
await wrapper.setProps({ active: 2 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
|
|
|
|
).toContain('is-finish')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[1].find('.el-step__head').classes()
|
|
|
|
).toContain('is-finish')
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-process')
|
2020-08-12 13:50:44 +08:00
|
|
|
await wrapper.setProps({ active: 3 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-finish')
|
2020-08-12 13:50:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('process-status', async () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps active={2} process-status="success">
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-success')
|
2020-08-12 13:50:44 +08:00
|
|
|
await wrapper.setProps({ processStatus: 'error' })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[2].find('.el-step__head').classes()
|
|
|
|
).toContain('is-error')
|
2020-08-12 13:50:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('finish-status', async () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps active={2} finish-status="error">
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
<Step />
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
|
|
|
|
).toContain('is-error')
|
2020-08-12 13:50:44 +08:00
|
|
|
await wrapper.setProps({ finishStatus: 'success' })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-step')[0].find('.el-step__head').classes()
|
|
|
|
).toContain('is-success')
|
2020-08-12 13:50:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('step attribute', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
setup() {
|
|
|
|
const iconEdit = markRaw(Edit)
|
|
|
|
return () => (
|
|
|
|
<Steps active={0}>
|
|
|
|
<Step
|
|
|
|
icon={iconEdit}
|
|
|
|
title="title"
|
|
|
|
description="description"
|
|
|
|
status="wait"
|
|
|
|
/>
|
|
|
|
</Steps>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
})
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.find('.el-step__head').classes()).toContain('is-wait')
|
|
|
|
expect(wrapper.find('.el-step__title').text()).toBe('title')
|
|
|
|
expect(wrapper.find('.el-step__description').text()).toBe('description')
|
2021-10-27 23:17:13 +08:00
|
|
|
expect(wrapper.findComponent(Edit).exists()).toBe(true)
|
2020-08-12 13:50:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('step slot', () => {
|
2022-07-03 17:15:42 +08:00
|
|
|
const wrapper = _mount(() => (
|
|
|
|
<Steps active={0}>
|
|
|
|
<Step
|
|
|
|
v-slots={{
|
|
|
|
title: () => 'A',
|
|
|
|
description: () => 'B',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Steps>
|
|
|
|
))
|
2020-08-12 13:50:44 +08:00
|
|
|
expect(wrapper.find('.el-step__title').text()).toBe('A')
|
|
|
|
expect(wrapper.find('.el-step__description').text()).toBe('B')
|
|
|
|
})
|
|
|
|
})
|