2019-09-29 12:33:24 +08:00
|
|
|
/* eslint-disable react/no-string-refs, react/prefer-es6-class */
|
|
|
|
import React from 'react';
|
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 mountTest from '../../../tests/shared/mountTest';
|
2022-06-16 23:29:04 +08:00
|
|
|
import { fireEvent, render, waitFor } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { setup, teardown } from './mock';
|
2019-09-29 12:33:24 +08:00
|
|
|
|
|
|
|
describe('Upload.Dragger', () => {
|
|
|
|
mountTest(Upload.Dragger);
|
|
|
|
|
|
|
|
beforeEach(() => setup());
|
|
|
|
afterEach(() => teardown());
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
it('support drag file with over style', async () => {
|
2020-08-18 15:44:31 +08:00
|
|
|
jest.useFakeTimers();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper } = render(
|
2019-09-29 12:33:24 +08:00
|
|
|
<Upload.Dragger action="http://upload.com">
|
|
|
|
<div />
|
|
|
|
</Upload.Dragger>,
|
|
|
|
);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.dragOver(wrapper.querySelector('.ant-upload-drag-container'), {
|
2019-09-29 12:33:24 +08:00
|
|
|
target: {
|
|
|
|
files: [{ file: 'foo.png' }],
|
|
|
|
},
|
|
|
|
});
|
2020-08-18 15:44:31 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
2020-08-18 15:44:31 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(wrapper.querySelector('.ant-upload-drag')).toHaveClass('ant-upload-drag-hover');
|
|
|
|
});
|
2020-08-18 15:44:31 +08:00
|
|
|
|
|
|
|
jest.useRealTimers();
|
2019-09-29 12:33:24 +08:00
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
it('support onDrop when files are dropped onto upload area', async () => {
|
2021-05-24 16:24:00 +08:00
|
|
|
const onDrop = jest.fn();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper } = render(
|
2021-05-24 16:24:00 +08:00
|
|
|
<Upload.Dragger onDrop={onDrop}>
|
|
|
|
<div />
|
|
|
|
</Upload.Dragger>,
|
|
|
|
);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.drop(wrapper.querySelector('.ant-upload-drag-container'), {
|
2021-05-24 16:24:00 +08:00
|
|
|
dataTransfer: {
|
|
|
|
files: [new File(['foo'], 'foo.png', { type: 'image/png' })],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(onDrop).toHaveBeenCalled();
|
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
});
|
2019-09-29 12:33:24 +08:00
|
|
|
});
|