ant-design/components/upload/__tests__/dragger.test.js
yykoypj 83eb5e5a35
test: move test cases to @testing/library for Upload (#36024)
* test: move test cases to @testing/library for Upload

* refactor: use jest.fn to replace done logic

* test: sample of moving test to testing lib

* test: check for 17

* refactor: manual control timer for React18

* refactor: animateEnd for useless middle state snapshot for 'handle error'

Co-authored-by: zombiej <smith3816@gmail.com>
2022-06-16 23:29:04 +08:00

59 lines
1.5 KiB
JavaScript

/* eslint-disable react/no-string-refs, react/prefer-es6-class */
import React from 'react';
import { act } from 'react-dom/test-utils';
import Upload from '..';
import { setup, teardown } from './mock';
import mountTest from '../../../tests/shared/mountTest';
import { fireEvent, render, waitFor } from '../../../tests/utils';
describe('Upload.Dragger', () => {
mountTest(Upload.Dragger);
beforeEach(() => setup());
afterEach(() => teardown());
it('support drag file with over style', async () => {
jest.useFakeTimers();
const { container: wrapper } = render(
<Upload.Dragger action="http://upload.com">
<div />
</Upload.Dragger>,
);
fireEvent.dragOver(wrapper.querySelector('.ant-upload-drag-container'), {
target: {
files: [{ file: 'foo.png' }],
},
});
await act(() => {
jest.runAllTimers();
});
await waitFor(() => {
expect(wrapper.querySelector('.ant-upload-drag')).toHaveClass('ant-upload-drag-hover');
});
jest.useRealTimers();
});
it('support onDrop when files are dropped onto upload area', async () => {
const onDrop = jest.fn();
const { container: wrapper } = render(
<Upload.Dragger onDrop={onDrop}>
<div />
</Upload.Dragger>,
);
fireEvent.drop(wrapper.querySelector('.ant-upload-drag-container'), {
dataTransfer: {
files: [new File(['foo'], 'foo.png', { type: 'image/png' })],
},
});
await waitFor(() => {
expect(onDrop).toHaveBeenCalled();
});
});
});