Files
Noblet Ouways 2f17df1209 style(eslint-config): newline before import type (#21036)
* perf: change to import-x

* feat: add rules

* chore: fix rule

* chore: fix

* chore: fix

* chore: fix

* style: `pnpm lint:fix`

* Revert "style: `pnpm lint:fix`"

This reverts commit db0116a288299c507e3cfc4d7a22e2207265d920.

* Revert "chore: fix"

This reverts commit 69c82a90c01525e38180be4c21e8ef5602512318.

* chore: fix

* style: `pnpm lint:fix`

* fix: lint

* chore: `pnpm format`
2025-06-16 15:37:12 +08:00

73 lines
1.8 KiB
TypeScript

import { describe, expect, test, vi } from 'vitest'
import { EVENT_CODE } from '@element-plus/constants'
import makeMount from '@element-plus/test-utils/make-mount'
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: {
default: ({ file }: { file: File }) => <div>{file.name}</div>,
},
})
expect(wrapper.text()).toBe(testName)
})
})
describe('functionalities', () => {
test('handle preview works', async () => {
const preview = vi.fn()
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 () => {
const remove = vi.fn()
const wrapper = mount({
props: {
onRemove: remove,
},
})
await wrapper.find('.el-icon--close').trigger('click')
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)
})
})
})