2020-12-21 20:07:48 +08:00
|
|
|
import { nextTick } from 'vue'
|
2022-06-15 01:31:56 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
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'
|
2022-06-15 01:31:56 +08:00
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('render test', () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton />)
|
2020-12-21 20:07:48 +08:00
|
|
|
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', () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton animated={true} />)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
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 () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton />)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
|
|
|
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', () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton rows={4} />)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
|
|
|
expect(wrapper.findAll('.el-skeleton__p')).toHaveLength(5)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render default slots', () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton loading={false}>{AXIOM}</Skeleton>)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
|
|
|
expect(wrapper.text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should render templates', () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Skeleton
|
|
|
|
v-slots={{
|
|
|
|
template: () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
|
|
|
expect(wrapper.text()).toBe(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-13 20:53:05 +08:00
|
|
|
it('should throttle rendering', async () => {
|
2022-06-15 01:31:56 +08:00
|
|
|
const wrapper = mount(<Skeleton throttle={500} />)
|
2020-12-21 20:07:48 +08:00
|
|
|
|
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
|
|
|
})
|
|
|
|
})
|