2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test, vi } from 'vitest'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { EVENT_CODE } from '@element-plus/constants'
|
2020-09-27 12:10:36 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
import makeMount from '@element-plus/test-utils/make-mount'
|
2020-09-27 12:10:36 +08:00
|
|
|
import UploadList from '../src/upload-list.vue'
|
|
|
|
|
|
|
|
const testName = 'test name'
|
|
|
|
|
|
|
|
const mount = makeMount(UploadList, {
|
|
|
|
props: {
|
|
|
|
files: [new File([], testName)],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('<upload-list />', () => {
|
|
|
|
describe('render test', () => {
|
|
|
|
test('should render correct', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
slots: {
|
2022-03-05 23:09:31 +08:00
|
|
|
default: ({ file }: { file: File }) => <div>{file.name}</div>,
|
2020-09-27 12:10:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.text()).toBe(testName)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('functionalities', () => {
|
|
|
|
test('handle preview works', async () => {
|
2022-04-19 12:46:57 +08:00
|
|
|
const preview = vi.fn()
|
2020-09-27 12:10:36 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
props: {
|
|
|
|
handlePreview: preview,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-upload-list__item-name').trigger('click')
|
|
|
|
expect(preview).toHaveBeenCalled()
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
listType: 'picture-card',
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-upload-list__item-preview').trigger('click')
|
|
|
|
expect(preview).toHaveBeenCalledTimes(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('handle delete works', async () => {
|
2022-04-19 12:46:57 +08:00
|
|
|
const remove = vi.fn()
|
2020-09-27 12:10:36 +08:00
|
|
|
|
|
|
|
const wrapper = mount({
|
|
|
|
props: {
|
|
|
|
onRemove: remove,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-10-27 23:17:13 +08:00
|
|
|
await wrapper.find('.el-icon--close').trigger('click')
|
2020-09-27 12:10:36 +08:00
|
|
|
expect(remove).toHaveBeenCalled()
|
|
|
|
|
|
|
|
await wrapper.find('.el-upload-list__item').trigger('keydown', {
|
|
|
|
key: EVENT_CODE.delete,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(remove).toHaveBeenCalledTimes(2)
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
listType: 'picture-card',
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-upload-list__item-delete').trigger('click')
|
|
|
|
expect(remove).toHaveBeenCalledTimes(3)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|