2020-12-21 20:07:48 +08:00
|
|
|
import { nextTick } from 'vue'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2020-12-21 20:07:48 +08:00
|
|
|
import makeMount from '@element-plus/test-utils/make-mount'
|
2021-11-14 22:55:50 +08:00
|
|
|
import Skeleton from '../src/skeleton.vue'
|
2022-03-13 20:53:05 +08:00
|
|
|
import type { SkeletonInstance } from '../src/skeleton'
|
2020-12-21 20:07:48 +08:00
|
|
|
const AXIOM = 'AXIOM is the best girl'
|
|
|
|
|
|
|
|
describe('Skeleton.vue', () => {
|
2022-03-13 20:53:05 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
vi.useFakeTimers()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.restoreAllMocks()
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const mount = makeMount(Skeleton, {})
|
2022-03-13 20:53:05 +08:00
|
|
|
it('render test', () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount()
|
|
|
|
expect(wrapper.findAll('.el-skeleton__p')).toHaveLength(4)
|
2022-03-13 20:53:05 +08:00
|
|
|
expect(wrapper.classes()).toMatchInlineSnapshot(`
|
|
|
|
[
|
|
|
|
"el-skeleton",
|
|
|
|
]
|
|
|
|
`)
|
2020-12-21 20:07:48 +08:00
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render with animation', () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
props: {
|
|
|
|
animated: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
expect(wrapper.classes()).toMatchInlineSnapshot(`
|
|
|
|
[
|
|
|
|
"el-skeleton",
|
|
|
|
"is-animated",
|
|
|
|
]
|
|
|
|
`)
|
2020-12-21 20:07:48 +08:00
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render x times', async () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount()
|
|
|
|
|
|
|
|
expect(wrapper.findAll('.el-skeleton__p')).toHaveLength(4)
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
count: 2,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.findAll('.el-skeleton__p')).toHaveLength(8)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render x rows', () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
props: {
|
|
|
|
rows: 4,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.findAll('.el-skeleton__p')).toHaveLength(5)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render default slots', () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
slots: {
|
|
|
|
default: () => AXIOM,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
loading: false,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render templates', () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
slots: {
|
|
|
|
template: () => AXIOM,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should throttle rendering', async () => {
|
2020-12-21 20:07:48 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
props: {
|
|
|
|
throttle: 500,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
expect((wrapper.vm as SkeletonInstance).uiLoading).toBe(false)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
vi.runAllTimers()
|
2020-12-21 20:07:48 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
expect((wrapper.vm as SkeletonInstance).uiLoading).toBe(true)
|
2020-12-21 20:07:48 +08:00
|
|
|
})
|
|
|
|
})
|