2019-09-29 12:33:24 +08:00
|
|
|
import React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2019-09-29 12:33:24 +08:00
|
|
|
import Upload from '..';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2023-06-07 21:59:21 +08:00
|
|
|
import { act, 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 () => {
|
2023-06-07 21:59:21 +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-09-05 19:41:32 +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-08-05 18:27:08 +08:00
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2020-08-18 15:44:31 +08:00
|
|
|
});
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(wrapper.querySelector('.ant-upload-drag')).toHaveClass('ant-upload-drag-hover');
|
|
|
|
});
|
2020-08-18 15:44:31 +08:00
|
|
|
|
2023-06-07 21:59:21 +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 () => {
|
2023-06-07 21:59:21 +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-09-05 19:41:32 +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' })],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(onDrop).toHaveBeenCalled();
|
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
});
|
2019-09-29 12:33:24 +08:00
|
|
|
});
|