|
@@ -153,7 +153,7 @@ describe('src/Core', () => {
|
|
|
currentUploads: {},
|
|
|
allowNewUpload: true,
|
|
|
foo: 'baar',
|
|
|
- info: { isHidden: true, message: '', type: 'info' },
|
|
|
+ info: [],
|
|
|
meta: {},
|
|
|
plugins: {},
|
|
|
totalProgress: 0,
|
|
@@ -178,7 +178,7 @@ describe('src/Core', () => {
|
|
|
currentUploads: {},
|
|
|
allowNewUpload: true,
|
|
|
foo: 'bar',
|
|
|
- info: { isHidden: true, message: '', type: 'info' },
|
|
|
+ info: [],
|
|
|
meta: {},
|
|
|
plugins: {},
|
|
|
totalProgress: 0,
|
|
@@ -192,7 +192,7 @@ describe('src/Core', () => {
|
|
|
currentUploads: {},
|
|
|
allowNewUpload: true,
|
|
|
foo: 'baar',
|
|
|
- info: { isHidden: true, message: '', type: 'info' },
|
|
|
+ info: [],
|
|
|
meta: {},
|
|
|
plugins: {},
|
|
|
totalProgress: 0,
|
|
@@ -232,7 +232,7 @@ describe('src/Core', () => {
|
|
|
allowNewUpload: true,
|
|
|
error: null,
|
|
|
foo: 'bar',
|
|
|
- info: { isHidden: true, message: '', type: 'info' },
|
|
|
+ info: [],
|
|
|
meta: {},
|
|
|
plugins: {},
|
|
|
totalProgress: 0,
|
|
@@ -293,7 +293,7 @@ describe('src/Core', () => {
|
|
|
currentUploads: {},
|
|
|
allowNewUpload: true,
|
|
|
error: null,
|
|
|
- info: { isHidden: true, message: '', type: 'info' },
|
|
|
+ info: [],
|
|
|
meta: {},
|
|
|
plugins: {},
|
|
|
totalProgress: 0,
|
|
@@ -329,16 +329,16 @@ describe('src/Core', () => {
|
|
|
describe('preprocessors', () => {
|
|
|
it('should add a preprocessor', () => {
|
|
|
const core = new Core()
|
|
|
- const preprocessor = () => {}
|
|
|
+ const preprocessor = () => { }
|
|
|
core.addPreProcessor(preprocessor)
|
|
|
expect(core.preProcessors[0]).toEqual(preprocessor)
|
|
|
})
|
|
|
|
|
|
it('should remove a preprocessor', () => {
|
|
|
const core = new Core()
|
|
|
- const preprocessor1 = () => {}
|
|
|
- const preprocessor2 = () => {}
|
|
|
- const preprocessor3 = () => {}
|
|
|
+ const preprocessor1 = () => { }
|
|
|
+ const preprocessor2 = () => { }
|
|
|
+ const preprocessor3 = () => { }
|
|
|
core.addPreProcessor(preprocessor1)
|
|
|
core.addPreProcessor(preprocessor2)
|
|
|
core.addPreProcessor(preprocessor3)
|
|
@@ -458,16 +458,16 @@ describe('src/Core', () => {
|
|
|
describe('postprocessors', () => {
|
|
|
it('should add a postprocessor', () => {
|
|
|
const core = new Core()
|
|
|
- const postprocessor = () => {}
|
|
|
+ const postprocessor = () => { }
|
|
|
core.addPostProcessor(postprocessor)
|
|
|
expect(core.postProcessors[0]).toEqual(postprocessor)
|
|
|
})
|
|
|
|
|
|
it('should remove a postprocessor', () => {
|
|
|
const core = new Core()
|
|
|
- const postprocessor1 = () => {}
|
|
|
- const postprocessor2 = () => {}
|
|
|
- const postprocessor3 = () => {}
|
|
|
+ const postprocessor1 = () => { }
|
|
|
+ const postprocessor2 = () => { }
|
|
|
+ const postprocessor3 = () => { }
|
|
|
core.addPostProcessor(postprocessor1)
|
|
|
core.addPostProcessor(postprocessor2)
|
|
|
core.addPostProcessor(postprocessor3)
|
|
@@ -588,16 +588,16 @@ describe('src/Core', () => {
|
|
|
describe('uploaders', () => {
|
|
|
it('should add an uploader', () => {
|
|
|
const core = new Core()
|
|
|
- const uploader = () => {}
|
|
|
+ const uploader = () => { }
|
|
|
core.addUploader(uploader)
|
|
|
expect(core.uploaders[0]).toEqual(uploader)
|
|
|
})
|
|
|
|
|
|
it('should remove an uploader', () => {
|
|
|
const core = new Core()
|
|
|
- const uploader1 = () => {}
|
|
|
- const uploader2 = () => {}
|
|
|
- const uploader3 = () => {}
|
|
|
+ const uploader1 = () => { }
|
|
|
+ const uploader2 = () => { }
|
|
|
+ const uploader3 = () => { }
|
|
|
core.addUploader(uploader1)
|
|
|
core.addUploader(uploader2)
|
|
|
core.addUploader(uploader3)
|
|
@@ -1065,9 +1065,9 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
describe('restoring a file', () => {
|
|
|
- xit('should restore a file', () => {})
|
|
|
+ xit('should restore a file', () => { })
|
|
|
|
|
|
- xit("should fail to restore a file if it doesn't exist", () => {})
|
|
|
+ xit("should fail to restore a file if it doesn't exist", () => { })
|
|
|
})
|
|
|
|
|
|
describe('get a file', () => {
|
|
@@ -1538,11 +1538,11 @@ describe('src/Core', () => {
|
|
|
throw new Error('should have thrown')
|
|
|
} catch (err) {
|
|
|
expect(err).toMatchObject(new Error('You can only upload 1 file'))
|
|
|
- expect(core.getState().info.message).toEqual('You can only upload 1 file')
|
|
|
+ expect(core.getState().info[0].message).toEqual('You can only upload 1 file')
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- xit('should enforce the minNumberOfFiles rule', () => {})
|
|
|
+ xit('should enforce the minNumberOfFiles rule', () => { })
|
|
|
|
|
|
it('should enforce the allowedFileTypes rule', () => {
|
|
|
const core = new Core({
|
|
@@ -1561,7 +1561,7 @@ describe('src/Core', () => {
|
|
|
throw new Error('should have thrown')
|
|
|
} catch (err) {
|
|
|
expect(err).toMatchObject(new Error('You can only upload: image/gif, image/png'))
|
|
|
- expect(core.getState().info.message).toEqual('You can only upload: image/gif, image/png')
|
|
|
+ expect(core.getState().info[0].message).toEqual('You can only upload: image/gif, image/png')
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -1595,7 +1595,7 @@ describe('src/Core', () => {
|
|
|
throw new Error('should have thrown')
|
|
|
} catch (err) {
|
|
|
expect(err).toMatchObject(new Error('You can only upload: .gif, .jpg, .jpeg'))
|
|
|
- expect(core.getState().info.message).toEqual('You can only upload: .gif, .jpg, .jpeg')
|
|
|
+ expect(core.getState().info[0].message).toEqual('You can only upload: .gif, .jpg, .jpeg')
|
|
|
}
|
|
|
|
|
|
expect(() => core.addFile({
|
|
@@ -1623,7 +1623,7 @@ describe('src/Core', () => {
|
|
|
throw new Error('should have thrown')
|
|
|
} catch (err) {
|
|
|
expect(err).toMatchObject(new Error('foo.jpg exceeds maximum allowed size of 1.2 KB'))
|
|
|
- expect(core.getState().info.message).toEqual('foo.jpg exceeds maximum allowed size of 1.2 KB')
|
|
|
+ expect(core.getState().info[0].message).toEqual('foo.jpg exceeds maximum allowed size of 1.2 KB')
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -1644,7 +1644,7 @@ describe('src/Core', () => {
|
|
|
throw new Error('should have thrown')
|
|
|
} catch (err) {
|
|
|
expect(err).toMatchObject(new Error('This file is smaller than the allowed size of 1 GB'))
|
|
|
- expect(core.getState().info.message).toEqual('This file is smaller than the allowed size of 1 GB')
|
|
|
+ expect(core.getState().info[0].message).toEqual('This file is smaller than the allowed size of 1 GB')
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -1760,12 +1760,11 @@ describe('src/Core', () => {
|
|
|
},
|
|
|
})
|
|
|
core.emit('upload-error', core.getFile('fileId'), new Error('this is the error'))
|
|
|
- expect(core.getState().info).toEqual({
|
|
|
+ expect(core.getState().info).toEqual([{
|
|
|
message: 'Failed to upload filename',
|
|
|
details: 'this is the error',
|
|
|
- isHidden: false,
|
|
|
type: 'error',
|
|
|
- })
|
|
|
+ }])
|
|
|
})
|
|
|
|
|
|
it('should reset the error state when receiving the upload event', () => {
|
|
@@ -1830,14 +1829,12 @@ describe('src/Core', () => {
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
|
|
|
|
core.info('This is the message', 'info', 0)
|
|
|
- expect(core.getState().info).toEqual({
|
|
|
- isHidden: false,
|
|
|
+ expect(core.getState().info).toEqual([{
|
|
|
type: 'info',
|
|
|
message: 'This is the message',
|
|
|
details: null,
|
|
|
- })
|
|
|
+ }])
|
|
|
expect(infoVisibleEvent.mock.calls.length).toEqual(1)
|
|
|
- expect(typeof core.infoTimeoutID).toEqual('undefined')
|
|
|
})
|
|
|
|
|
|
it('should set a object based message to be displayed infinitely', () => {
|
|
@@ -1851,16 +1848,14 @@ describe('src/Core', () => {
|
|
|
foo: 'bar',
|
|
|
},
|
|
|
}, 'warning', 0)
|
|
|
- expect(core.getState().info).toEqual({
|
|
|
- isHidden: false,
|
|
|
+ expect(core.getState().info).toEqual([{
|
|
|
type: 'warning',
|
|
|
message: 'This is the message',
|
|
|
details: {
|
|
|
foo: 'bar',
|
|
|
},
|
|
|
- })
|
|
|
+ }])
|
|
|
expect(infoVisibleEvent.mock.calls.length).toEqual(1)
|
|
|
- expect(typeof core.infoTimeoutID).toEqual('undefined')
|
|
|
})
|
|
|
|
|
|
it('should set an info message to be displayed for a period of time before hiding', (done) => {
|
|
@@ -1871,16 +1866,10 @@ describe('src/Core', () => {
|
|
|
core.on('info-hidden', infoHiddenEvent)
|
|
|
|
|
|
core.info('This is the message', 'info', 100)
|
|
|
- expect(typeof core.infoTimeoutID).toEqual('number')
|
|
|
expect(infoHiddenEvent.mock.calls.length).toEqual(0)
|
|
|
setTimeout(() => {
|
|
|
expect(infoHiddenEvent.mock.calls.length).toEqual(1)
|
|
|
- expect(core.getState().info).toEqual({
|
|
|
- isHidden: true,
|
|
|
- type: 'info',
|
|
|
- message: 'This is the message',
|
|
|
- details: null,
|
|
|
- })
|
|
|
+ expect(core.getState().info).toEqual([])
|
|
|
done()
|
|
|
}, 110)
|
|
|
})
|
|
@@ -1893,16 +1882,50 @@ describe('src/Core', () => {
|
|
|
core.on('info-hidden', infoHiddenEvent)
|
|
|
|
|
|
core.info('This is the message', 'info', 0)
|
|
|
- expect(typeof core.infoTimeoutID).toEqual('undefined')
|
|
|
expect(infoHiddenEvent.mock.calls.length).toEqual(0)
|
|
|
core.hideInfo()
|
|
|
expect(infoHiddenEvent.mock.calls.length).toEqual(1)
|
|
|
- expect(core.getState().info).toEqual({
|
|
|
- isHidden: true,
|
|
|
- type: 'info',
|
|
|
- message: 'This is the message',
|
|
|
- details: null,
|
|
|
- })
|
|
|
+ expect(core.getState().info).toEqual([])
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should support multiple messages', () => {
|
|
|
+ const infoVisibleEvent = jest.fn()
|
|
|
+ const infoHiddenEvent = jest.fn()
|
|
|
+ const core = new Core()
|
|
|
+
|
|
|
+ core.on('info-visible', infoVisibleEvent)
|
|
|
+ core.on('info-hidden', infoHiddenEvent)
|
|
|
+
|
|
|
+ core.info('This is the message', 'info', 0)
|
|
|
+ core.info('But this is another one', 'info', 0)
|
|
|
+
|
|
|
+ expect(infoHiddenEvent.mock.calls.length).toEqual(0)
|
|
|
+ expect(core.getState().info).toEqual([
|
|
|
+ {
|
|
|
+ type: 'info',
|
|
|
+ message: 'This is the message',
|
|
|
+ details: null,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'info',
|
|
|
+ message: 'But this is another one',
|
|
|
+ details: null,
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ core.hideInfo()
|
|
|
+
|
|
|
+ expect(core.getState().info).toEqual([
|
|
|
+ {
|
|
|
+ type: 'info',
|
|
|
+ message: 'But this is another one',
|
|
|
+ details: null,
|
|
|
+ },
|
|
|
+ ])
|
|
|
+
|
|
|
+ core.hideInfo()
|
|
|
+
|
|
|
+ expect(infoHiddenEvent.mock.calls.length).toEqual(2)
|
|
|
+ expect(core.getState().info).toEqual([])
|
|
|
})
|
|
|
})
|
|
|
|