Skip to content

Commit

Permalink
fix(Uplaod): support upload again when an upload fails, close alibaba…
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyYang committed Jul 8, 2024
1 parent 4ab101e commit 4b43eeb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
44 changes: 44 additions & 0 deletions components/upload/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,50 @@ describe('Upload', () => {
cy.get('input').trigger('change', { target: { files: files }, force: true });
});

it('should support upload again, when an upload fails', () => {
let uploaderRef: ReturnType<InstanceType<typeof Upload>['getInstance']>;
const saveUploaderRef = (ref: InstanceType<typeof Upload> | null) => {
if (!ref) return;
uploaderRef = ref.getInstance();
};

const onSubmit = () => {
uploaderRef.startUpload();
};

const beforeUpload = cy.spy().as('beforeUpload');
cy.mount(
<div>
<Upload
action="https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload"
autoUpload={false}
ref={saveUploaderRef}
listType="image"
beforeUpload={beforeUpload}
useDataURL
>
<button className="upload-btn" style={{ marginBottom: 8 }}>
Select File
</button>
</Upload>
<br />
<button className="submit-btn" onClick={onSubmit}>
Upload
</button>
</div>
);

cy.get('input[type="file"]').trigger('change', {
target: { files: [buildFile()] },
force: true,
});

cy.get('.submit-btn').trigger('click');
cy.get('@beforeUpload').should('have.been.calledOnce');
cy.get('.submit-btn').trigger('click');
cy.get('@beforeUpload').should('have.been.calledTwice');
});

it('should support onPreview events when listType is set to card and isPreview is set to true', () => {
const onPreview = cy.spy().as('onPreviewSpy');
cy.mount(
Expand Down
6 changes: 5 additions & 1 deletion components/upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ class Upload extends Base<UploadProps, UploadState> {
this.state.uploading = true;
const fileList = files
.filter(file => {
if (file.state === 'selected') {
if (
file.state === 'selected' ||
file.state === 'error' ||
file.state === 'uploading'
) {
file.state = 'uploading';
return true;
}
Expand Down

0 comments on commit 4b43eeb

Please sign in to comment.