diff --git a/backend/src/db/factories.js b/backend/src/db/factories.js index 7ea82f661..8a6ca380e 100644 --- a/backend/src/db/factories.js +++ b/backend/src/db/factories.js @@ -49,8 +49,9 @@ Factory.define('badge') Factory.define('image') .attr('url', faker.image.unsplash.imageUrl) - .attr('aspectRatio', 1) + .attr('aspectRatio', 1.3333333333333333) .attr('alt', faker.lorem.sentence) + .attr('type', 'image/jpeg') .after((buildObject, options) => { const { url: imageUrl } = buildObject if (imageUrl) buildObject.url = uniqueImageUrl(imageUrl) diff --git a/backend/src/models/Image.js b/backend/src/models/Image.js index 19824b493..b46342c18 100644 --- a/backend/src/models/Image.js +++ b/backend/src/models/Image.js @@ -3,5 +3,6 @@ export default { alt: { type: 'string' }, sensitive: { type: 'boolean', default: false }, aspectRatio: { type: 'float', default: 1.0 }, + type: { type: 'string' }, createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, } diff --git a/backend/src/schema/resolvers/images.js b/backend/src/schema/resolvers/images.js index 8b3f4a3e8..111f84888 100644 --- a/backend/src/schema/resolvers/images.js +++ b/backend/src/schema/resolvers/images.js @@ -2,7 +2,7 @@ import Resolver from './helpers/Resolver' export default { Image: { ...Resolver('Image', { - undefinedToNull: ['sensitive', 'alt', 'aspectRatio'], + undefinedToNull: ['sensitive', 'alt', 'aspectRatio', 'type'], }), }, } diff --git a/backend/src/schema/resolvers/images/images.js b/backend/src/schema/resolvers/images/images.js index 9b57579c4..656ae114a 100644 --- a/backend/src/schema/resolvers/images/images.js +++ b/backend/src/schema/resolvers/images/images.js @@ -53,8 +53,8 @@ export async function mergeImage(resource, relationshipType, imageInput, opts = if (!(existingImage || upload)) throw new UserInputError('Cannot find image for given resource') if (existingImage && upload) deleteImageFile(existingImage, deleteCallback) const url = await uploadImageFile(upload, uploadCallback) - const { alt, sensitive, aspectRatio } = imageInput - const image = { alt, sensitive, aspectRatio, url } + const { alt, sensitive, aspectRatio, type } = imageInput + const image = { alt, sensitive, aspectRatio, url, type } txResult = await transaction.run( ` MATCH (resource {id: $resource.id}) diff --git a/backend/src/schema/types/type/Image.gql b/backend/src/schema/types/type/Image.gql index 41cc11eef..f171a4b77 100644 --- a/backend/src/schema/types/type/Image.gql +++ b/backend/src/schema/types/type/Image.gql @@ -8,6 +8,7 @@ type Image { alt: String, sensitive: Boolean, aspectRatio: Float, + type: String, } input ImageInput { @@ -15,4 +16,5 @@ input ImageInput { upload: Upload, sensitive: Boolean, aspectRatio: Float, + type: String, } diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index eb4e9cd5a..cce187a63 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -151,6 +151,7 @@ describe('ContributionForm.vue', () => { aspectRatio: null, sensitive: false, upload: imageUpload, + type: null, } const spy = jest .spyOn(FileReader.prototype, 'readAsDataURL') diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 42ed2799e..d2cb419a4 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -19,6 +19,7 @@ :class="[formData.imageBlurred && '--blur-image']" @addHeroImage="addHeroImage" @addImageAspectRatio="addImageAspectRatio" + @addImageType="addImageType" />
@@ -84,7 +85,11 @@ export default { }, data() { const { title, content, image } = this.contribution - const { sensitive: imageBlurred = false, aspectRatio: imageAspectRatio = null } = image || {} + const { + sensitive: imageBlurred = false, + aspectRatio: imageAspectRatio = null, + type: imageType = null, + } = image || {} return { links, @@ -93,6 +98,7 @@ export default { content: content || '', image: image || null, imageAspectRatio, + imageType, imageBlurred, }, formSchema: { @@ -125,6 +131,7 @@ export default { if (this.imageUpload) { image.upload = this.imageUpload image.aspectRatio = this.formData.imageAspectRatio + image.type = this.formData.imageType } } this.loading = true @@ -173,6 +180,9 @@ export default { addImageAspectRatio(aspectRatio) { this.formData.imageAspectRatio = aspectRatio }, + addImageType(imageType) { + this.formData.imageType = imageType + }, }, apollo: { User: { diff --git a/webapp/components/ImageUploader/ImageUploader.spec.js b/webapp/components/ImageUploader/ImageUploader.spec.js index 537febac3..200369436 100644 --- a/webapp/components/ImageUploader/ImageUploader.spec.js +++ b/webapp/components/ImageUploader/ImageUploader.spec.js @@ -25,19 +25,11 @@ describe('ImageUploader.vue', () => { describe('handles errors', () => { 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) - }) + const unSupportedFileMessage = '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) + wrapper.vm.onUnSupportedFormat(unSupportedFileMessage) + expect(mocks.$toast.error).toHaveBeenCalledWith(unSupportedFileMessage) }) }) }) diff --git a/webapp/components/ImageUploader/ImageUploader.vue b/webapp/components/ImageUploader/ImageUploader.vue index d4f402e02..d885782f3 100644 --- a/webapp/components/ImageUploader/ImageUploader.vue +++ b/webapp/components/ImageUploader/ImageUploader.vue @@ -1,17 +1,21 @@