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

Made sure we can upload new files if we cancel last file (allowMultipleUploads: false) #1764

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/@uppy/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,12 @@ class Uppy {

this.setState({
currentUploads: updatedUploads,
files: updatedFiles
files: updatedFiles,
...(
// If this is the last file we just removed - allow new uploads!
Object.keys(updatedFiles).length === 0 &&
{ allowNewUpload: true }
)
lakesare marked this conversation as resolved.
Show resolved Hide resolved
})

removeUploads.forEach((uploadID) => {
Expand Down Expand Up @@ -653,7 +658,6 @@ class Uppy {
})

this.setState({
allowNewUpload: true,
totalProgress: 0,
error: null
})
Expand Down
75 changes: 62 additions & 13 deletions packages/@uppy/core/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,27 +664,76 @@ describe('src/Core', () => {
expect(core.getFiles().length).toEqual(0)
})

it('allows no new files after upload when allowMultipleUploads: false', async () => {
const core = new Core({ allowMultipleUploads: false })
core.addFile({
source: 'jest',
name: 'foo.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
describe('with allowMultipleUploads: false', () => {
it('allows no new files after upload', async () => {
const core = new Core({ allowMultipleUploads: false })
core.addFile({
source: 'jest',
name: 'foo.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
})

await core.upload()

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 core.upload()
it('does not allow new files after the removeFile() if some file is still present', async () => {
const core = new Core({ allowMultipleUploads: false })

expect(() => {
// adding 2 files
const fileId1 = core.addFile({
source: 'jest',
name: '1.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
})
core.addFile({
source: 'jest',
name: '123.foo',
name: '2.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
})
}).toThrow(
/Cannot add new files: already uploading\./
)

// removing 1 file
core.removeFile(fileId1)

await expect(core.upload()).resolves.toBeDefined()
})

it('allows new files after the last removeFile()', async () => {
const core = new Core({ allowMultipleUploads: false })

// adding 2 files
const fileId1 = core.addFile({
source: 'jest',
name: '1.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
})
const fileId2 = core.addFile({
source: 'jest',
name: '2.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' })
})

// removing 2 files
core.removeFile(fileId1)
core.removeFile(fileId2)

await expect(core.upload()).resolves.toBeDefined()
})
})

it('does not dedupe different files', async () => {
Expand Down