Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: support name prop (#574)" #575

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ class AjaxUploader extends Component<UploadProps> {
classNames = {},
disabled,
id,
name,
style,
styles = {},
multiple,
Expand Down Expand Up @@ -308,7 +307,6 @@ class AjaxUploader extends Component<UploadProps> {
<input
{...pickAttrs(otherProps, { aria: true, data: true })}
id={id}
name={name}
disabled={disabled}
type="file"
ref={this.saveFileInput}
Expand Down
1 change: 1 addition & 0 deletions src/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Upload extends Component<UploadProps> {
prefixCls: 'rc-upload',
data: {},
headers: {},
name: 'file',
multipart: false,
onStart: empty,
onError: empty,
Expand Down
31 changes: 25 additions & 6 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ describe('uploader', () => {
expect(container.querySelector('input')!.id).toBe('bamboo');
});

// https://github.com/ant-design/ant-design/issues/50643
it('with name', () => {
const { container } = render(<Upload name="bamboo" />);
expect(container.querySelector('input')!.name).toBe('bamboo');
});

it('should pass through data & aria attributes', () => {
const { container } = render(
<Upload
Expand Down Expand Up @@ -375,6 +369,31 @@ describe('uploader', () => {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => setTimeout(resolve, 2000));
});

it('should pass file to request', done => {
const fakeRequest = jest.fn((file) => {
expect(file).toEqual(expect.objectContaining({
filename: 'file', // <= https://github.com/react-component/upload/pull/574
file: expect.any(File),
method: 'post',
onError: expect.any(Function),
onProgress: expect.any(Function),
onSuccess: expect.any(Function),
data: expect.anything(),
}));

done();
});

const { container } = render(<Upload customRequest={fakeRequest} />);
const input = container.querySelector('input')!;
const files = [new File([''], 'success.png', { type: 'image/png' })];
Object.defineProperty(files, 'item', {
value: i => files[i],
});

fireEvent.change(input, { target: { files } });
});
});

describe('directory uploader', () => {
Expand Down