From 59efc240771e2d9848aecf0e4b9e976c177fe51a Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 14 Sep 2021 11:26:22 +0200 Subject: [PATCH] Updated unit test --- .../components/upload-photo/index.spec.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/front/salix/components/upload-photo/index.spec.js b/front/salix/components/upload-photo/index.spec.js index e8ac05fd4..f2aad6a5c 100644 --- a/front/salix/components/upload-photo/index.spec.js +++ b/front/salix/components/upload-photo/index.spec.js @@ -24,17 +24,30 @@ describe('Salix', () => { }); describe('viewportSelection()', () => { - it('should call to displayEditor() and updatePhotoPreview() methods', () => { - controller.displayEditor = jest.fn(); + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "computer"', () => { controller.updatePhotoPreview = jest.fn(); const files = [{name: 'test.jpg'}]; controller.newPhoto.files = files; + controller.uploadMethod = 'computer'; controller.viewportSelection = {code: 'normal'}; - expect(controller.displayEditor).toHaveBeenCalledWith(); - expect(controller.updatePhotoPreview).toHaveBeenCalledWith(files); + const firstFile = files[0]; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(firstFile); + }); + + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "URL"', () => { + controller.updatePhotoPreview = jest.fn(); + + const url = 'http://gothamcity.com/batman.png'; + controller.newPhoto.url = url; + + controller.uploadMethod = 'URL'; + controller.viewportSelection = {code: 'normal'}; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(url); }); });