فهرست منبع

fix: skip removed pending uploads

Developer 3 روز پیش
والد
کامیت
67e9203875
2فایلهای تغییر یافته به همراه29 افزوده شده و 0 حذف شده
  1. 1 0
      src/views/pages/team-background-upload.vue
  2. 28 0
      tests/unit/teamBackgroundPublicUpload.spec.js

+ 1 - 0
src/views/pages/team-background-upload.vue

@@ -308,6 +308,7 @@ export default {
         if (batchGeneration !== this.asyncGeneration ||
           !this.isSessionContextCurrent(batchContext) ||
           this.completing) break
+        if (this.queue.indexOf(item) === -1) continue
         await this.uploadOne(item)
         if (batchGeneration !== this.asyncGeneration ||
           !this.isSessionContextCurrent(batchContext)) break

+ 28 - 0
tests/unit/teamBackgroundPublicUpload.spec.js

@@ -588,6 +588,34 @@ describe('public team background upload page state machine', () => {
     expect(failed).toMatchObject({ status: 'success', progress: 100, error: '' })
   })
 
+  test('does not upload a pending batch item removed while an earlier item is active', async () => {
+    if (!expectPage(source)) return
+    const firstRequest = deferred()
+    api.uploadPublicTeamBackgroundFile
+      .mockReturnValueOnce(firstRequest.promise)
+      .mockResolvedValue({ code: 0, data: {} })
+    const vm = createPageVm(api, {
+      state: 'ready',
+      session: { uploadToken: 'upload-token' }
+    })
+
+    const batch = vm.handleFileChange({
+      target: { files: [{ name: 'first.pdf', size: 1 }, { name: 'removed.pdf', size: 1 }] }
+    })
+    const removedItem = vm.queue[1]
+    expect(api.uploadPublicTeamBackgroundFile).toHaveBeenCalledTimes(1)
+    expect(removedItem).toMatchObject({ name: 'removed.pdf', status: 'pending' })
+
+    vm.removeQueueItem(removedItem)
+    expect(vm.queue).not.toContain(removedItem)
+
+    firstRequest.resolve({ code: 0, data: {} })
+    await batch
+
+    expect(api.uploadPublicTeamBackgroundFile).toHaveBeenCalledTimes(1)
+    expect(vm.queue).not.toContain(removedItem)
+  })
+
   test('a session-level upload failure expires the page and stops later files in the batch', async () => {
     if (!expectPage(source)) return
     api.uploadPublicTeamBackgroundFile.mockRejectedValue({ msg: '上传会话已过期' })