fix: upload default FileList is more than maxCount, it can't remove it (#47747)

* fix: upload default FileList is more than maxCount, it can't remove it

* fix: snapshot

* fix: line
This commit is contained in:
Zhou Bill 2024-03-28 10:14:34 +08:00 committed by GitHub
parent 7ec6a7b430
commit 7c09fc01ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View File

@ -137,6 +137,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
if (
!exceedMaxCount ||
file.status === 'removed' ||
// We should ignore event if current file is exceed `maxCount`
cloneList.some((f) => f.uid === file.uid)
) {

View File

@ -815,6 +815,53 @@ describe('Upload', () => {
}),
);
});
it('should trigger onChange when defaultFileList.length is longer than maxCount ', async () => {
const onChange = jest.fn();
const { container } = render(
<Upload
onChange={onChange}
maxCount={3}
defaultFileList={[
{
uid: 'bamboo',
name: 'bamboo.png',
},
{
uid: 'little',
name: 'little.png',
},
{
uid: 'foo',
name: 'foo.png',
},
{
uid: 'bar',
name: 'bar.png',
},
{
uid: 'bar1',
name: 'bar1.png',
},
]}
showUploadList
>
<button type="button">upload</button>
</Upload>,
);
fireEvent.click(container.querySelector('.ant-upload-list-item-action')!);
await waitFakeTimer();
// Click delete
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
// Have 3 file
fileList: [expect.anything(), expect.anything(), expect.anything()],
}),
);
});
});
it('auto fill file uid', () => {