From 0e501159dc7d78241c023fc85fda73ae0d44a10a Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Thu, 19 Sep 2019 13:45:18 +0300 Subject: [PATCH] web: Components: Added tests for ComboBox component. --- .../src/components/combobox/combobox.test.js | 79 +++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/web/ASC.Web.Components/src/components/combobox/combobox.test.js b/web/ASC.Web.Components/src/components/combobox/combobox.test.js index 834ed99c2d..b7ee955efe 100644 --- a/web/ASC.Web.Components/src/components/combobox/combobox.test.js +++ b/web/ASC.Web.Components/src/components/combobox/combobox.test.js @@ -76,7 +76,7 @@ describe('', () => { expect(wrapper.prop('opened')).toEqual(true); }); - it('not scaled button', () => { + it('must contain max height', () => { const wrapper = mount(); expect(wrapper.prop('dropDownMaxHeight')).toEqual(200); @@ -101,25 +101,25 @@ describe('', () => { }); it('middle size options', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.prop('size')).toEqual('middle'); }); it('big size options', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.prop('size')).toEqual('big'); }); it('huge size options', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.prop('size')).toEqual('huge'); }); it('content size options', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.prop('size')).toEqual('content'); }); @@ -141,8 +141,75 @@ describe('', () => { it('re-render test', () => { const wrapper = shallow().instance(); - const shouldUpdate = wrapper.shouldComponentUpdate({ noBorder: true }, wrapper.state); + const shouldUpdate = wrapper.shouldComponentUpdate({ opened: true }, wrapper.state); expect(shouldUpdate).toBe(true); }); + + it('comboBoxClick() disabled test', () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + instance.comboBoxClick(); + + expect(wrapper.state('isOpen')).toBe(false); + }); + + it('comboBoxClick() not disabled test', () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + instance.comboBoxClick(); + + expect(wrapper.state('isOpen')).toBe(true); + }); + + it('optionClick() test', () => { + const onSelect = jest.fn(); + const selectedOption = { + key: 1, + label: "Select" + }; + const wrapper = shallow(); + const instance = wrapper.instance(); + + instance.optionClick(selectedOption); + + expect(wrapper.state('isOpen')).toBe(false); + expect(onSelect).toHaveBeenCalledWith(selectedOption); + }); + + it('handleClick() with simulate test', () => { + const wrapper = mount(); + + wrapper.simulate('click'); + + expect(wrapper.state('isOpen')).toBe(false); + }); + + it('handleClick() with simulate and ComboBox not opened test', () => { + const wrapper = mount(); + + wrapper.simulate('click'); + + expect(wrapper.state('isOpen')).toBe(true); + }); + + it('componentDidUpdate() lifecycle test', () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + instance.componentDidUpdate(wrapper.props, wrapper.state); + + expect(wrapper.props).toBe(wrapper.props); + expect(wrapper.state).toBe(wrapper.state); + }); + + it('componentWillUnmount() lifecycle test', () => { + const wrapper = mount(); + const componentWillUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount'); + + wrapper.unmount(); + expect(componentWillUnmount).toHaveBeenCalled(); + }); });