Pārlūkot izejas kodu

Allow new uploads again after reset()

Renée Kooi 6 gadi atpakaļ
vecāks
revīzija
363643f0dc
2 mainītis faili ar 25 papildinājumiem un 13 dzēšanām
  1. 1 0
      packages/@uppy/core/src/index.js
  2. 24 13
      packages/@uppy/core/src/index.test.js

+ 1 - 0
packages/@uppy/core/src/index.js

@@ -621,6 +621,7 @@ class Uppy {
 
   reset () {
     this.cancelAll()
+    this.setState({ allowNewUpload: true })
   }
 
   _calculateProgress (file, data) {

+ 24 - 13
packages/@uppy/core/src/index.test.js

@@ -230,7 +230,7 @@ describe('src/Core', () => {
 
     // expect(corePauseEventMock.mock.calls.length).toEqual(1)
     expect(coreCancelEventMock.mock.calls.length).toEqual(1)
-    expect(coreStateUpdateEventMock.mock.calls.length).toEqual(2)
+    expect(coreStateUpdateEventMock.mock.calls.length).toEqual(3)
     expect(coreStateUpdateEventMock.mock.calls[1][1]).toEqual({
       capabilities: { resumableUploads: false },
       files: {},
@@ -289,7 +289,7 @@ describe('src/Core', () => {
 
     // expect(corePauseEventMock.mock.calls.length).toEqual(1)
     expect(coreCancelEventMock.mock.calls.length).toEqual(1)
-    expect(coreStateUpdateEventMock.mock.calls.length).toEqual(1)
+    expect(coreStateUpdateEventMock.mock.calls.length).toEqual(2)
     expect(coreStateUpdateEventMock.mock.calls[0][1]).toEqual({
       capabilities: { resumableUploads: false },
       files: {},
@@ -782,21 +782,32 @@ describe('src/Core', () => {
       })
 
       await expect(core.upload()).resolves.toBeDefined()
-
-      // expect(() => {
-      //   core.addFile({
-      //     source: 'jest',
-      //     name: '123.foo',
-      //     type: 'image/jpeg',
-      //     data: new File([sampleImage], { type: 'image/jpeg' })
-      //   })
-      // }).toThrow(
-      //   /Cannot add new files: already uploading\./
-      // )
       await expect(core.upload()).rejects.toThrow(
         /Cannot create a new upload: already uploading\./
       )
     })
+
+    it('allows new files again with allowMultipleUploads: false after reset() was called', async () => {
+      const core = new Core({ allowMultipleUploads: false })
+
+      core.addFile({
+        source: 'jest',
+        name: 'bar.jpg',
+        type: 'image/jpeg',
+        data: new File([sampleImage], { type: 'image/jpeg' })
+      })
+      await expect(core.upload()).resolves.toBeDefined()
+
+      core.reset()
+
+      core.addFile({
+        source: 'jest',
+        name: '123.foo',
+        type: 'image/jpeg',
+        data: new File([sampleImage], { type: 'image/jpeg' })
+      })
+      await expect(core.upload()).resolves.toBeDefined()
+    })
   })
 
   describe('removing a file', () => {