2019-09-29 12:33:24 +08:00
|
|
|
/* eslint-disable react/no-string-refs, react/prefer-es6-class */
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2020-08-18 15:44:31 +08:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2019-09-29 12:33:24 +08:00
|
|
|
import Upload from '..';
|
|
|
|
import { setup, teardown } from './mock';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
|
|
|
|
describe('Upload.Dragger', () => {
|
|
|
|
mountTest(Upload.Dragger);
|
|
|
|
|
|
|
|
beforeEach(() => setup());
|
|
|
|
afterEach(() => teardown());
|
|
|
|
|
|
|
|
it('support drag file with over style', () => {
|
2020-08-18 15:44:31 +08:00
|
|
|
jest.useFakeTimers();
|
2019-09-29 12:33:24 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Upload.Dragger action="http://upload.com">
|
|
|
|
<div />
|
|
|
|
</Upload.Dragger>,
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.find('.ant-upload-drag-container').simulate('dragover', {
|
|
|
|
target: {
|
|
|
|
files: [{ file: 'foo.png' }],
|
|
|
|
},
|
|
|
|
});
|
2020-08-18 15:44:31 +08:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
wrapper.update();
|
|
|
|
|
2019-09-29 12:33:24 +08:00
|
|
|
expect(wrapper.find('.ant-upload-drag').hasClass('ant-upload-drag-hover')).toBe(true);
|
2020-08-18 15:44:31 +08:00
|
|
|
|
|
|
|
jest.useRealTimers();
|
2019-09-29 12:33:24 +08:00
|
|
|
});
|
2021-04-30 22:11:31 +08:00
|
|
|
|
|
|
|
it('support onDrop when files are dropped onto upload area', () => {
|
|
|
|
const onDrop = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Upload.Dragger onDrop={onDrop}>
|
|
|
|
<div />
|
|
|
|
</Upload.Dragger>,
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.find('.ant-upload-drag-container').simulate('drop', {
|
|
|
|
dataTransfer: {
|
|
|
|
files: [new File(['foo'], 'foo.png', { type: 'image/png' })],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(onDrop).toHaveBeenCalled();
|
|
|
|
});
|
2019-09-29 12:33:24 +08:00
|
|
|
});
|