element-plus/packages/components/upload/__tests__/upload-dragger.spec.ts
C.Y.Kun 13ffea1114
refactor(components): refactor upload (#6014)
* refactor(components): refactor ElUpload

* refactor(components): refactor upload

* test: use jsx

* refactor: resolve review comments

* fix: ts error

* refactor: re-order imports

* refactor: rename

* fix: infinity watch

* refactor: rename

* refactor: address PR comments

Co-authored-by: Kevin <sxzz@sxzz.moe>
2022-03-05 23:09:31 +08:00

74 lines
1.8 KiB
TypeScript

import { provide, h, defineComponent, computed } from 'vue'
import makeMount from '@element-plus/test-utils/make-mount'
import { uploadContextKey } from '@element-plus/tokens'
import UploadDragger from '../src/upload-dragger.vue'
const AXIOM = 'Rem is the best girl'
const Wrapper = defineComponent({
props: {
onDrop: Function,
},
setup(props, { slots }) {
provide(uploadContextKey, { accept: computed(() => 'video/*') })
return () => h(UploadDragger, props, slots)
},
})
const mount = makeMount(Wrapper, {
slots: {
default: () => AXIOM,
},
})
describe('<upload-dragger />', () => {
describe('render test', () => {
test('should render correct', () => {
const wrapper = mount()
expect(wrapper.text()).toBe(AXIOM)
})
})
describe('functionality', () => {
test('onDrag works', async () => {
const wrapper = mount()
await wrapper.find('.el-upload-dragger').trigger('dragover')
expect(wrapper.classes('is-dragover')).toBe(true)
})
test('ondrop works for any given video type', async () => {
const onDrop = jest.fn()
const wrapper = mount({
props: {
onDrop,
},
})
const dragger = wrapper.findComponent(UploadDragger)
await dragger.trigger('drop', {
dataTransfer: {
files: [
{
type: 'video/mp4',
name: 'test.mp4',
},
],
},
})
expect(onDrop).toHaveBeenCalledTimes(1)
expect(dragger.emitted('file')).toHaveLength(1)
await dragger.trigger('drop', {
dataTransfer: {
files: [
{
type: 'video/mov',
name: 'test.mov',
},
],
},
})
expect(dragger.emitted('file')).toHaveLength(2)
})
})
})