From f6094a918ee9befd52fe94b8f90fa7721afa74a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=ED=95=9C=EA=B2=BD?= Date: Wed, 1 Jun 2022 14:05:32 +0900 Subject: [PATCH] refactor(components): [progress] use JSX in Unit test (#8022) --- .../progress/__tests__/progress.test.tsx | 140 +++++++++--------- 1 file changed, 66 insertions(+), 74 deletions(-) diff --git a/packages/components/progress/__tests__/progress.test.tsx b/packages/components/progress/__tests__/progress.test.tsx index 6a8f5b5642..64b9f29209 100644 --- a/packages/components/progress/__tests__/progress.test.tsx +++ b/packages/components/progress/__tests__/progress.test.tsx @@ -1,14 +1,14 @@ +import { nextTick, ref } from 'vue' import { mount } from '@vue/test-utils' import { describe, expect, test } from 'vitest' import { CircleClose } from '@element-plus/icons-vue' + import Progress from '../src/progress.vue' + describe('Progress.vue', () => { test('percent', () => { - const wrapper = mount(Progress, { - props: { - percentage: 66, - }, - }) + const wrapper = mount(() => ) + expect(wrapper.find('.el-progress__text').text()).toBe('66%') expect(wrapper.find('.el-progress-bar__inner').attributes('style')).toBe( 'width: 66%; animation-duration: 3s;' @@ -16,143 +16,135 @@ describe('Progress.vue', () => { }) test('status', () => { - const wrapper = mount(Progress, { - props: { - status: 'exception', - }, - }) + const wrapper = mount(() => ) + expect(wrapper.classes()).toContain('is-exception') expect(wrapper.findComponent(CircleClose).exists()).toBe(true) }) test('text inside', () => { - const wrapper = mount(Progress, { - props: { - textInside: true, - }, - }) + const wrapper = mount(() => ) + expect(wrapper.classes()).toContain('el-progress--text-inside') }) test('stroke width', () => { - const wrapper = mount(Progress, { - props: { - strokeWidth: 7, - }, - }) + const wrapper = mount(() => ) + expect(wrapper.find('.el-progress-bar__outer').attributes('style')).toBe( 'height: 7px;' ) }) test('show text', () => { - const wrapper = mount(Progress, { - props: { - showText: false, - }, - }) + const wrapper = mount(() => ) + expect(wrapper.find('.el-progress__text').exists()).toBe(false) }) test('circle', () => { - const wrapper = mount(Progress, { - props: { - type: 'circle', - }, - }) + const wrapper = mount(() => ) + expect(wrapper.classes()).toContain('el-progress--circle') }) test('dashboard', () => { - const wrapper = mount(Progress, { - props: { - type: 'dashboard', - }, - }) + const wrapper = mount(() => ) + expect(wrapper.classes()).toContain('el-progress--dashboard') }) test('width', () => { - const wrapper = mount(Progress, { - props: { - type: 'circle', - width: 120, - }, - }) + const wrapper = mount(() => ) + expect(wrapper.find('.el-progress-circle').attributes('style')).toBe( 'height: 120px; width: 120px;' ) }) test('color', () => { - const wrapper = mount(Progress, { - props: { - color: 'rgb(255, 255, 255)', - }, - }) + const wrapper = mount(() => ) + expect( wrapper.find('.el-progress-bar__inner').attributes('style') ).toContain('background-color: rgb(255, 255, 255);') }) test('color is function', async () => { - const wrapper = mount(Progress, { - props: { - percentage: 0, - color: (percentage: number) => { + const percentage = ref(0) + + const wrapper = mount(() => ( + { if (percentage > 50) { return 'rgb(4, 5, 6)' } else { return 'rgb(1, 2, 3)' } - }, - }, - }) + }} + /> + )) + expect( wrapper.find('.el-progress-bar__inner').attributes('style') ).toContain('background-color: rgb(1, 2, 3);') - await wrapper.setProps({ percentage: 60 }) + + percentage.value = 60 + + await nextTick() + expect( wrapper.find('.el-progress-bar__inner').attributes('style') ).toContain('background-color: rgb(4, 5, 6);') }) test('color is array', async () => { - const wrapper = mount(Progress, { - props: { - percentage: 0, - color: [ + const percentage = ref(0) + const wrapper = mount(() => ( + + )) + + percentage.value = 9 + await nextTick() + expect( wrapper.find('.el-progress-bar__inner').attributes('style') ).toContain('background-color: rgb(1, 1, 1);') - await wrapper.setProps({ percentage: 89 }) + + percentage.value = 89 + await nextTick() + expect( wrapper.find('.el-progress-bar__inner').attributes('style') ).toContain('background-color: rgb(9, 9, 9);') }) test('format', () => { - const wrapper = mount(Progress, { - props: { - percentage: 100, - format: (percent: number) => `占比${percent}%`, - }, - }) + const wrapper = mount(() => ( + `占比${percent}%`} + /> + )) expect(wrapper.find('.el-progress__text').text()).toBe('占比100%') }) test('slot', () => { - const wrapper = mount(Progress, { - slots: { - default: '自定义内容', - }, - }) + const wrapper = mount(() => ( + '自定义内容', + }} + /> + )) + expect(wrapper.find('.el-progress__text').text()).toBe('自定义内容') }) })