2022-06-22 08:04:42 +08:00
|
|
|
// @ts-nocheck
|
2022-06-13 14:57:29 +08:00
|
|
|
import { nextTick, ref } from 'vue'
|
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2021-11-05 20:53:08 +08:00
|
|
|
import Result from '../src/result.vue'
|
2021-04-14 10:18:29 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Result.vue', () => {
|
|
|
|
test('render test', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => <Result />)
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon').exists()).toBe(true)
|
|
|
|
expect(wrapper.classes()).toContain('el-result')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should render title props', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => <Result title={AXIOM} />)
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__title').text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should render sub-title props', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => <Result subTitle={AXIOM} />)
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__subtitle').text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should render icon props', async () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const icon = ref('success')
|
|
|
|
const wrapper = mount(() => <Result icon={icon.value} />)
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').classes()).toContain(
|
|
|
|
'icon-success'
|
|
|
|
)
|
2022-06-13 14:57:29 +08:00
|
|
|
icon.value = 'error'
|
|
|
|
await nextTick()
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').classes()).toContain(
|
|
|
|
'icon-error'
|
|
|
|
)
|
2022-06-13 14:57:29 +08:00
|
|
|
icon.value = 'warning'
|
|
|
|
await nextTick()
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').classes()).toContain(
|
|
|
|
'icon-warning'
|
|
|
|
)
|
2022-06-13 14:57:29 +08:00
|
|
|
icon.value = 'info'
|
|
|
|
await nextTick()
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-result__icon svg').classes()).toContain(
|
|
|
|
'icon-info'
|
|
|
|
)
|
2021-04-14 10:18:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render icon slots', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Result
|
|
|
|
v-slots={{
|
|
|
|
icon: () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__icon').exists()).toBe(true)
|
2021-05-21 14:45:46 +08:00
|
|
|
expect(wrapper.find('.el-result__icon').text()).toBe(AXIOM)
|
2021-04-14 10:18:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render title slots', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Result
|
|
|
|
v-slots={{
|
|
|
|
title: () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__title').exists()).toBe(true)
|
2021-05-21 14:45:46 +08:00
|
|
|
expect(wrapper.find('.el-result__title').text()).toBe(AXIOM)
|
2021-04-14 10:18:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render sub-title slots', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Result
|
|
|
|
v-slots={{
|
|
|
|
'sub-title': () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__subtitle').exists()).toBe(true)
|
2021-05-21 14:45:46 +08:00
|
|
|
expect(wrapper.find('.el-result__subtitle').text()).toBe(AXIOM)
|
2021-04-14 10:18:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render extra slots', () => {
|
2022-06-13 14:57:29 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Result
|
|
|
|
v-slots={{
|
|
|
|
extra: () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
2021-04-14 10:18:29 +08:00
|
|
|
expect(wrapper.find('.el-result__extra').exists()).toBe(true)
|
2021-05-21 14:45:46 +08:00
|
|
|
expect(wrapper.find('.el-result__extra').text()).toBe(AXIOM)
|
2021-04-14 10:18:29 +08:00
|
|
|
})
|
|
|
|
})
|