From 51e2940f868d78eb948a46dfffcd8864c883521a Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Fri, 22 Nov 2019 16:20:24 +0300 Subject: [PATCH] web: Components: Added tests for AvatarEditor component. --- .../avatar-editor/avatar-editor.test.js | 172 +++++++++++++++++- 1 file changed, 167 insertions(+), 5 deletions(-) diff --git a/web/ASC.Web.Components/src/components/avatar-editor/avatar-editor.test.js b/web/ASC.Web.Components/src/components/avatar-editor/avatar-editor.test.js index 098b6a2435..d09e4d7d06 100644 --- a/web/ASC.Web.Components/src/components/avatar-editor/avatar-editor.test.js +++ b/web/ASC.Web.Components/src/components/avatar-editor/avatar-editor.test.js @@ -1,16 +1,178 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import AvatarEditor from '.'; +const baseProps = { + visible: true, + headerLabel: 'test', + chooseFileLabel: 'test', + saveButtonLabel: 'test', + maxSizeFileError: 'test', + image: '', + maxSize: 1, + accept: ['image/png', 'image/jpeg'], + unknownTypeError: 'test', + unknownError: 'test', + displayType: 'auto' +}; + describe('', () => { it('renders without error', () => { const wrapper = mount( - {console.log(data.croppedImage, data.defaultImage)}} - /> + ); expect(wrapper).toExist(); }); + + it('accepts id', () => { + const wrapper = mount( + + ); + + expect(wrapper.prop('id')).toEqual('testId'); + }); + + it('accepts className', () => { + const wrapper = mount( + + ); + + expect(wrapper.prop('className')).toEqual('test'); + }); + + it('accepts style', () => { + const wrapper = mount( + + ); + + expect(wrapper.getDOMNode().style).toHaveProperty('color', 'red'); + }); + + it('componentDidUpdate() props lifecycle test', () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + instance.componentDidUpdate({visible: false}, wrapper.state()); + + instance.componentDidUpdate({visible: true}, wrapper.state()); + + expect(wrapper.props()).toBe(wrapper.props()); + }); + + it('causes function onClose()', () => { + const onClose = jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onClose(); + + expect(wrapper.state('visible')).toBe(false); + }); + + it('causes function onSaveButtonClick()', () => { + const onSave = jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + wrapper.setState({ isContainsFile: false }); + + instance.onSaveButtonClick(); + + wrapper.setState({ isContainsFile: true }); + + instance.onSaveButtonClick(); + + expect(wrapper.state('visible')).toBe(true); + }); + + it('causes function onImageChange()', () => { + const fileString = ''; + const onImageChange= jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onImageChange(fileString); + + expect(onImageChange).toHaveBeenCalled(); + }); + + it('causes function onImageChange() no onImageChange', () => { + const fileString = ''; + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onImageChange(fileString); + + expect(wrapper.state('croppedImage')).toBe(fileString); + }); + + it('causes function onDeleteImage()', () => { + const onDeleteImage= jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onDeleteImage(); + + expect(onDeleteImage).toHaveBeenCalled(); + }); + + it('causes function onDeleteImage() no onDeleteImage', () => { + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onDeleteImage(); + + expect(wrapper.state('isContainsFile')).toBe(false); + }); + + it('causes function onPositionChange()', () => { + const data = {test: 'test'}; + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onPositionChange(data); + + expect(wrapper.state('test')).toBe('test'); + }); + + it('causes function onLoadFileError()', () => { + const onLoadFileError= jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onLoadFileError(); + + expect(onLoadFileError).toHaveBeenCalled(); + }); + + it('causes function onLoadFileError() no onLoadFileError', () => { + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onLoadFileError(); + + expect(wrapper.state('isContainsFile')).toBe(false); + }); + + it('causes function onLoadFile()', () => { + const file = 'test'; + const onLoadFile= jest.fn(); + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onLoadFile(file); + + expect(onLoadFile).toHaveBeenCalled(); + expect(wrapper.state('isContainsFile')).toBe(true); + }); + + it('causes function onLoadFile() no onLoadFile', () => { + const wrapper = mount(); + const instance = wrapper.instance(); + + instance.onLoadFile(); + + expect(wrapper.state('isContainsFile')).toBe(true); + }); });