2020-08-02 15:27:24 +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 { CircleClose } from '@element-plus/icons-vue'
|
2021-11-08 11:53:51 +08:00
|
|
|
import Progress from '../src/progress.vue'
|
2020-08-02 15:27:24 +08:00
|
|
|
describe('Progress.vue', () => {
|
|
|
|
test('percent', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
percentage: 66,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.find('.el-progress__text').text()).toBe('66%')
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-progress-bar__inner').attributes('style')).toBe(
|
|
|
|
'width: 66%; animation-duration: 3s;'
|
|
|
|
)
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('status', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
status: 'exception',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.classes()).toContain('is-exception')
|
2021-10-27 23:17:13 +08:00
|
|
|
expect(wrapper.findComponent(CircleClose).exists()).toBe(true)
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('text inside', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
textInside: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.classes()).toContain('el-progress--text-inside')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('stroke width', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
strokeWidth: 7,
|
|
|
|
},
|
|
|
|
})
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-progress-bar__outer').attributes('style')).toBe(
|
|
|
|
'height: 7px;'
|
|
|
|
)
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('show text', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
showText: false,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.find('.el-progress__text').exists()).toBe(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('circle', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
type: 'circle',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.classes()).toContain('el-progress--circle')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('dashboard', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
type: 'dashboard',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.classes()).toContain('el-progress--dashboard')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('width', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
type: 'circle',
|
|
|
|
width: 120,
|
|
|
|
},
|
|
|
|
})
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-progress-circle').attributes('style')).toBe(
|
|
|
|
'height: 120px; width: 120px;'
|
|
|
|
)
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('color', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
color: 'rgb(255, 255, 255)',
|
|
|
|
},
|
|
|
|
})
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-progress-bar__inner').attributes('style')
|
|
|
|
).toContain('background-color: rgb(255, 255, 255);')
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('color is function', async () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
percentage: 0,
|
2022-05-29 03:58:05 +08:00
|
|
|
color: (percentage: number) => {
|
2020-08-02 15:27:24 +08:00
|
|
|
if (percentage > 50) {
|
|
|
|
return 'rgb(4, 5, 6)'
|
|
|
|
} else {
|
|
|
|
return 'rgb(1, 2, 3)'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-progress-bar__inner').attributes('style')
|
|
|
|
).toContain('background-color: rgb(1, 2, 3);')
|
2020-08-02 15:27:24 +08:00
|
|
|
await wrapper.setProps({ percentage: 60 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-progress-bar__inner').attributes('style')
|
|
|
|
).toContain('background-color: rgb(4, 5, 6);')
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('color is array', async () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
percentage: 0,
|
|
|
|
color: [
|
|
|
|
{ color: 'rgb(1, 1, 1)', percentage: 10 },
|
|
|
|
{ color: 'rgb(9, 9, 9)', percentage: 90 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
await wrapper.setProps({ percentage: 9 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-progress-bar__inner').attributes('style')
|
|
|
|
).toContain('background-color: rgb(1, 1, 1);')
|
2020-08-02 15:27:24 +08:00
|
|
|
await wrapper.setProps({ percentage: 89 })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-progress-bar__inner').attributes('style')
|
|
|
|
).toContain('background-color: rgb(9, 9, 9);')
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('format', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
props: {
|
|
|
|
percentage: 100,
|
2022-05-29 03:58:05 +08:00
|
|
|
format: (percent: number) => `占比${percent}%`,
|
2020-08-02 15:27:24 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.find('.el-progress__text').text()).toBe('占比100%')
|
|
|
|
})
|
2021-02-05 16:27:44 +08:00
|
|
|
|
|
|
|
test('slot', () => {
|
|
|
|
const wrapper = mount(Progress, {
|
|
|
|
slots: {
|
|
|
|
default: '自定义内容',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.find('.el-progress__text').text()).toBe('自定义内容')
|
|
|
|
})
|
2020-08-02 15:27:24 +08:00
|
|
|
})
|