mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
allow only supported file formats
This commit is contained in:
parent
21a9094a25
commit
939466b9bb
@ -27,11 +27,17 @@ describe('ImageUploader.vue', () => {
|
|||||||
beforeEach(() => jest.useFakeTimers())
|
beforeEach(() => jest.useFakeTimers())
|
||||||
const message = 'File upload failed'
|
const message = 'File upload failed'
|
||||||
const fileError = { status: 'error' }
|
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', () => {
|
it('shows an error toaster when verror is called', () => {
|
||||||
wrapper.vm.onDropzoneError(fileError, message)
|
wrapper.vm.onDropzoneError(fileError, message)
|
||||||
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, 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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -62,6 +62,7 @@ export default {
|
|||||||
url: () => '',
|
url: () => '',
|
||||||
maxFilesize: 5.0,
|
maxFilesize: 5.0,
|
||||||
previewTemplate: '<span class="no-preview" />',
|
previewTemplate: '<span class="no-preview" />',
|
||||||
|
acceptedFiles: '.png,.jpg,.jpeg,.gif',
|
||||||
},
|
},
|
||||||
cropper: null,
|
cropper: null,
|
||||||
file: null,
|
file: null,
|
||||||
@ -73,7 +74,20 @@ export default {
|
|||||||
onDropzoneError(file, message) {
|
onDropzoneError(file, message) {
|
||||||
this.$toast.error(file.status, message)
|
this.$toast.error(file.status, message)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onUnSupportedFormat(status, message) {
|
||||||
|
this.$toast.error(status, message)
|
||||||
|
},
|
||||||
initCropper(file) {
|
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.showCropper = true
|
||||||
this.file = file
|
this.file = file
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user