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

refactor(ImageUploader): get complete upload data #6779

Merged
merged 8 commits into from
Nov 12, 2024

Conversation

Layouwen
Copy link
Member

Copy link
Contributor

github-actions bot commented Nov 10, 2024

Preview is ready

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.70%. Comparing base (f71756a) to head (ff3fec0).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6779      +/-   ##
==========================================
- Coverage   92.70%   92.70%   -0.01%     
==========================================
  Files         335      335              
  Lines        7199     7198       -1     
  Branches     1792     1804      +12     
==========================================
- Hits         6674     6673       -1     
  Misses        490      490              
  Partials       35       35              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -196,7 +196,7 @@ export const ImageUploader = forwardRef<ImageUploaderRef, ImageUploaderProps>(

setTasks(prev => [...getFinalTasks(prev), ...newTasks])
const newVal: ImageUploadItem[] = []
await Promise.all(
await Promise.allSettled(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个兼容性比起 all 差很多。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个兼容性比起 all 差很多。

改为 for 循环, 成功的时候 push 值, 失败的话 push null 并在 catch log error 如何

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个解法看起来和之前 Promise.all 里去掉 throw 是差不多意思?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实~

@@ -225,10 +225,10 @@ export const ImageUploader = forwardRef<ImageUploaderRef, ImageUploaderProps>(
return task
})
})
throw e
console.error(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试用例~~

@@ -35,6 +35,19 @@ export async function mockUploadFail() {
throw new Error('Fail to upload')
}

export function mockUploadWithFailure(failOnCount: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个最好放 get all upload url 测试里定义,内聚一下~


expect(fn.mock.lastCall[0].length).toBe(4)

function mockUploadWithFailure(failOnCount: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定义放最前面

jest.runAllTimers()
})

expect(fn.mock.lastCall[0].length).toBe(4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失败的 2 个要去掉,否则实际上传和 UI 会对不上

jest.runAllTimers()
})

expect(fn.mock.lastCall[0].length).toBe(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对比一下现在的 list file name 是否和 mock input 里的 file list 是对上的~

@zombieJ zombieJ merged commit 495be63 into ant-design:master Nov 12, 2024
10 checks passed
@Layouwen Layouwen deleted the fix/image-uploader branch November 12, 2024 13:06
@afc163
Copy link
Member

afc163 commented Nov 13, 2024

PR 标题不对。

@Layouwen Layouwen changed the title refactor: use Promise.allSettled refactor(ImageUploader): get complete upload data Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants