allow only supported file formats

This commit is contained in:
dasari810 2020-10-27 12:48:08 +05:30
parent 21a9094a25
commit 939466b9bb
2 changed files with 20 additions and 0 deletions

View File

@ -27,11 +27,17 @@ describe('ImageUploader.vue', () => {
beforeEach(() => jest.useFakeTimers())
const message = 'File upload failed'
const fileError = { status: 'error' }
const unSupportedFileMessage =
'Please upload an image of file format : jpg , jpeg , png or gif'
it('shows an error toaster when verror is called', () => {
wrapper.vm.onDropzoneError(fileError, message)
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message)
})
it('shows an error toaster when unSupported file is uploaded', () => {
wrapper.vm.onUnSupportedFormat(fileError.status, unSupportedFileMessage)
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, unSupportedFileMessage)
})
})
})
})

View File

@ -62,6 +62,7 @@ export default {
url: () => '',
maxFilesize: 5.0,
previewTemplate: '<span class="no-preview" />',
acceptedFiles: '.png,.jpg,.jpeg,.gif',
},
cropper: null,
file: null,
@ -73,7 +74,20 @@ export default {
onDropzoneError(file, message) {
this.$toast.error(file.status, message)
},
onUnSupportedFormat(status, message) {
this.$toast.error(status, message)
},
initCropper(file) {
const supportedFormats = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
if (supportedFormats.indexOf(file.type) < 0) {
this.onUnSupportedFormat(
'error',
'Please upload an image of file format : jpg , jpeg , png or gif',
)
return
}
this.showCropper = true
this.file = file