From dee88fcb9beaac1ef3316ae0eb36a63ca44a8d64 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Tue, 14 Nov 2017 23:20:31 +0800 Subject: [PATCH 1/3] upgrade to enzyme-adapter-react-16, temporarily disable mount (issue with dependencies using react 16 Portals), enable jest at Jenkins build --- Makefile | 4 +- PULL_REQUEST_TEMPLATE.md | 1 + build/Jenkinsfile | 7 + package.json | 4 +- tests/components/about_build_modal.test.jsx | 37 +++-- tests/components/channel_info_modal.test.jsx | 35 ++-- tests/components/edit_post_modal.test.jsx | 156 +++++++++--------- tests/components/get_link_modal.test.jsx | 16 +- tests/components/new_channel_modal.test.jsx | 54 +++--- tests/components/post_deleted_modal.test.jsx | 29 ++-- .../__snapshots__/pluggable.test.jsx.snap | 1 - .../__snapshots__/post_type.test.jsx.snap | 1 - tests/setup.js | 2 +- yarn.lock | 23 +-- 14 files changed, 193 insertions(+), 177 deletions(-) diff --git a/Makefile b/Makefile index b264860e958c..6a2c96876f92 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,9 @@ check-style: .yarninstall yarn run check test: .yarninstall - cd $(BUILD_SERVER_DIR) && $(MAKE) internal-test-web-client + @echo Running jest unit/component testing + + yarn run test .yarninstall: package.json @echo Getting dependencies using yarn diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index fb4ac3f36ebd..0c5c04ac79f7 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -11,6 +11,7 @@ When filling in a section please remove the help text and the above text. #### Checklist [Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.] - [ ] Ran `make check-style` to check for style errors (required for all pull requests) +- [ ] Ran `make test` to ensure unit and component tests passed - [ ] Added or updated unit tests (required for all new features) - [ ] Has server changes (please link) - [ ] Has redux changes (please link) diff --git a/build/Jenkinsfile b/build/Jenkinsfile index 96f433219c95..a961a0265b17 100644 --- a/build/Jenkinsfile +++ b/build/Jenkinsfile @@ -33,6 +33,13 @@ podTemplate(label: 'jenkins-slave-webapp', } } } + stage('Unit/Component Tests') { + container('mattermost-node') { + dir('mattermost-webapp') { + sh 'make test' + } + } + } stage('Build') { container('mattermost-node') { dir('mattermost-webapp') { diff --git a/package.json b/package.json index 9614e2ddafbb..e3850e698e2a 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "cross-env": "5.1.1", "css-loader": "0.28.7", "enzyme": "3.1.1", - "enzyme-adapter-react-15": "1.0.5", + "enzyme-adapter-react-16": "1.0.4", "enzyme-to-json": "3.2.2", "eslint": "3.17.1", "eslint-import-resolver-webpack": "0.8.3", @@ -118,7 +118,9 @@ "client/**/*.{js,jsx}", "components/**/*.jsx", "plugins/**/*.{js,jsx}", + "reducers/**/*.{js,jsx}", "routes/**/*.{js,jsx}", + "selectors/**/*.{js,jsx}", "stores/**/*.{js,jsx}", "utils/**/*.{js,jsx}" ], diff --git a/tests/components/about_build_modal.test.jsx b/tests/components/about_build_modal.test.jsx index d7cccf1bc7f3..98f69ff8aeab 100644 --- a/tests/components/about_build_modal.test.jsx +++ b/tests/components/about_build_modal.test.jsx @@ -2,11 +2,12 @@ // See License.txt for license information. import React from 'react'; -import {Modal} from 'react-bootstrap'; + +// import {Modal} from 'react-bootstrap'; import {shallow} from 'enzyme'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import AboutBuildModal from 'components/about_build_modal/about_build_modal.jsx'; @@ -80,22 +81,22 @@ describe('components/AboutBuildModal', () => { expect(wrapper.find('#versionString').text()).toBe(' 3.6.0\u00a0 (3.6.2)'); }); - test('should call onModalDismissed callback when the modal is hidden', (done) => { - function onHide() { - done(); - } - - const wrapper = mountWithIntl( - - ); - - wrapper.find(Modal).first().props().onHide(); - }); + // test('should call onModalDismissed callback when the modal is hidden', (done) => { + // function onHide() { + // done(); + // } + + // const wrapper = mountWithIntl( + // + // ); + + // wrapper.find(Modal).first().props().onHide(); + // }); function shallowAboutBuildModal(props = {}) { const onModalDismissed = jest.fn(); diff --git a/tests/components/channel_info_modal.test.jsx b/tests/components/channel_info_modal.test.jsx index c6c92b117dd7..be747f8cd0f8 100644 --- a/tests/components/channel_info_modal.test.jsx +++ b/tests/components/channel_info_modal.test.jsx @@ -2,11 +2,12 @@ // See License.txt for license information. import React from 'react'; -import {Modal} from 'react-bootstrap'; + +// import {Modal} from 'react-bootstrap'; import {shallow} from 'enzyme'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import ChannelInfoModal from 'components/channel_info_modal/channel_info_modal.jsx'; @@ -25,19 +26,19 @@ describe('components/ChannelInfoModal', () => { expect(wrapper).toMatchSnapshot(); }); - test('should call onHide callback when modal is hidden', (done) => { - function onHide() { - done(); - } - - const wrapper = mountWithIntl( - - ); - - wrapper.find(Modal).first().props().onExited(); - }); + // test('should call onHide callback when modal is hidden', (done) => { + // function onHide() { + // done(); + // } + + // const wrapper = mountWithIntl( + // + // ); + + // wrapper.find(Modal).first().props().onExited(); + // }); }); diff --git a/tests/components/edit_post_modal.test.jsx b/tests/components/edit_post_modal.test.jsx index 5e21d2e1bfcd..fb47ce40a55a 100644 --- a/tests/components/edit_post_modal.test.jsx +++ b/tests/components/edit_post_modal.test.jsx @@ -1,7 +1,7 @@ import React from 'react'; import {shallow} from 'enzyme'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import Constants from 'utils/constants'; import EditPostModal from 'components/edit_post_modal/edit_post_modal.jsx'; @@ -217,49 +217,49 @@ describe('comoponents/edit_post_modal/edit_post_modal.jsx', () => { expect(wrapper.state().showEmojiPicker).toBe(false); }); - it('should add emoji to editText when an emoji is clicked', () => { - const wrapper = mountWithIntl(createEditPost()); - wrapper.setState({editText: ''}); - wrapper.instance().handleEmojiClick(null); - wrapper.instance().handleEmojiClick({}); - wrapper.instance().handleEmojiClick({aliases: []}); - expect(wrapper.state().editText).toBe(''); - - wrapper.setState({editText: ''}); - wrapper.instance().handleEmojiClick({name: '+1', aliases: ['thumbsup']}); - expect(wrapper.state().editText).toBe(':+1: '); - - wrapper.setState({editText: 'test'}); - wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); - expect(wrapper.state().editText).toBe('test :-1: '); - - wrapper.setState({editText: 'test '}); - wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); - expect(wrapper.state().editText).toBe('test :-1: '); - }); - - it('should set the focus and recalcule the size of the edit box enter end', () => { - const wrapper = mountWithIntl(createEditPost()); - const instance = wrapper.instance(); - const ref = wrapper.ref('editbox'); - ref.focus = jest.fn(); - ref.recalculateSize = jest.fn(); - expect(ref.focus).not.toBeCalled(); - expect(ref.recalculateSize).not.toBeCalled(); - instance.handleEntered(); - expect(ref.focus).toBeCalled(); - expect(ref.recalculateSize).toBeCalled(); - }); - - it('should hide the preview on exit start', () => { - const wrapper = mountWithIntl(createEditPost()); - const instance = wrapper.instance(); - const ref = wrapper.ref('editbox'); - ref.hidePreview = jest.fn(); - expect(ref.hidePreview).not.toBeCalled(); - instance.handleExit(); - expect(ref.hidePreview).toBeCalled(); - }); + // it('should add emoji to editText when an emoji is clicked', () => { + // const wrapper = mountWithIntl(createEditPost()); + // wrapper.setState({editText: ''}); + // wrapper.instance().handleEmojiClick(null); + // wrapper.instance().handleEmojiClick({}); + // wrapper.instance().handleEmojiClick({aliases: []}); + // expect(wrapper.state().editText).toBe(''); + + // wrapper.setState({editText: ''}); + // wrapper.instance().handleEmojiClick({name: '+1', aliases: ['thumbsup']}); + // expect(wrapper.state().editText).toBe(':+1: '); + + // wrapper.setState({editText: 'test'}); + // wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); + // expect(wrapper.state().editText).toBe('test :-1: '); + + // wrapper.setState({editText: 'test '}); + // wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); + // expect(wrapper.state().editText).toBe('test :-1: '); + // }); + + // it('should set the focus and recalcule the size of the edit box enter end', () => { + // const wrapper = mountWithIntl(createEditPost()); + // const instance = wrapper.instance(); + // const ref = wrapper.ref('editbox'); + // ref.focus = jest.fn(); + // ref.recalculateSize = jest.fn(); + // expect(ref.focus).not.toBeCalled(); + // expect(ref.recalculateSize).not.toBeCalled(); + // instance.handleEntered(); + // expect(ref.focus).toBeCalled(); + // expect(ref.recalculateSize).toBeCalled(); + // }); + + // it('should hide the preview on exit start', () => { + // const wrapper = mountWithIntl(createEditPost()); + // const instance = wrapper.instance(); + // const ref = wrapper.ref('editbox'); + // ref.hidePreview = jest.fn(); + // expect(ref.hidePreview).not.toBeCalled(); + // instance.handleExit(); + // expect(ref.hidePreview).toBeCalled(); + // }); it('should hide when confirm the edition and the message is not edited', () => { const actions = { @@ -403,38 +403,38 @@ describe('comoponents/edit_post_modal/edit_post_modal.jsx', () => { expect(instance.handleEdit).not.toBeCalled(); }); - it('should handle edition on key press enter depending on the conditions', () => { - global.navigator = {userAgent: 'Android'}; - var wrapper = mountWithIntl(createEditPost({ctrlSend: true})); - var instance = wrapper.instance(); - const preventDefault = jest.fn(); - instance.handleEdit = jest.fn(); - instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - expect(instance.handleEdit).not.toBeCalled(); - expect(preventDefault).not.toBeCalled(); - instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: false, preventDefault, shiftKey: false, altKey: false}); - expect(instance.handleEdit).not.toBeCalled(); - expect(preventDefault).not.toBeCalled(); - instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - expect(instance.handleEdit).toBeCalled(); - expect(preventDefault).toBeCalled(); - - global.navigator = {userAgent: 'Chrome'}; - wrapper = mountWithIntl(createEditPost({ctrlSend: false})); - instance = wrapper.instance(); - preventDefault.mockClear(); - instance.handleEdit = jest.fn(); - instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - expect(instance.handleEdit).not.toBeCalled(); - expect(preventDefault).not.toBeCalled(); - instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: true, altKey: false}); - expect(instance.handleEdit).not.toBeCalled(); - expect(preventDefault).not.toBeCalled(); - instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: true}); - expect(instance.handleEdit).not.toBeCalled(); - expect(preventDefault).not.toBeCalled(); - instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - expect(instance.handleEdit).toBeCalled(); - expect(preventDefault).toBeCalled(); - }); + // it('should handle edition on key press enter depending on the conditions', () => { + // global.navigator = {userAgent: 'Android'}; + // var wrapper = mountWithIntl(createEditPost({ctrlSend: true})); + // var instance = wrapper.instance(); + // const preventDefault = jest.fn(); + // instance.handleEdit = jest.fn(); + // instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + // expect(instance.handleEdit).not.toBeCalled(); + // expect(preventDefault).not.toBeCalled(); + // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: false, preventDefault, shiftKey: false, altKey: false}); + // expect(instance.handleEdit).not.toBeCalled(); + // expect(preventDefault).not.toBeCalled(); + // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + // expect(instance.handleEdit).toBeCalled(); + // expect(preventDefault).toBeCalled(); + + // global.navigator = {userAgent: 'Chrome'}; + // wrapper = mountWithIntl(createEditPost({ctrlSend: false})); + // instance = wrapper.instance(); + // preventDefault.mockClear(); + // instance.handleEdit = jest.fn(); + // instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + // expect(instance.handleEdit).not.toBeCalled(); + // expect(preventDefault).not.toBeCalled(); + // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: true, altKey: false}); + // expect(instance.handleEdit).not.toBeCalled(); + // expect(preventDefault).not.toBeCalled(); + // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: true}); + // expect(instance.handleEdit).not.toBeCalled(); + // expect(preventDefault).not.toBeCalled(); + // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + // expect(instance.handleEdit).toBeCalled(); + // expect(preventDefault).toBeCalled(); + // }); }); diff --git a/tests/components/get_link_modal.test.jsx b/tests/components/get_link_modal.test.jsx index 0f02a0925970..cc0a3c14b39d 100644 --- a/tests/components/get_link_modal.test.jsx +++ b/tests/components/get_link_modal.test.jsx @@ -6,7 +6,7 @@ import React from 'react'; import {shallow} from 'enzyme'; import {Modal} from 'react-bootstrap'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import GetLinkModal from 'components/get_link_modal.jsx'; @@ -61,12 +61,12 @@ describe('components/GetLinkModal', () => { expect(wrapper.state('copiedLink')).toBe(false); }); - test('should have handle copyLink', () => { - const wrapper = mountWithIntl( - - ); + // test('should have handle copyLink', () => { + // const wrapper = mountWithIntl( + // + // ); - wrapper.instance().copyLink(); - expect(wrapper.state('copiedLink')).toBe(true); - }); + // wrapper.instance().copyLink(); + // expect(wrapper.state('copiedLink')).toBe(true); + // }); }); diff --git a/tests/components/new_channel_modal.test.jsx b/tests/components/new_channel_modal.test.jsx index 03d656201f66..c3e42d6c71e8 100644 --- a/tests/components/new_channel_modal.test.jsx +++ b/tests/components/new_channel_modal.test.jsx @@ -5,7 +5,7 @@ import React from 'react'; import {shallow} from 'enzyme'; import {Modal} from 'react-bootstrap'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import Constants from 'utils/constants.jsx'; @@ -79,39 +79,39 @@ describe('components/NewChannelModal', () => { expect(wrapper).toMatchSnapshot(); }); - test('should match when handleChange is called', () => { - const newOnDataChanged = jest.fn(); - const props = {...baseProps, onDataChanged: newOnDataChanged}; - const wrapper = mountWithIntl( - - ); + // test('should match when handleChange is called', () => { + // const newOnDataChanged = jest.fn(); + // const props = {...baseProps, onDataChanged: newOnDataChanged}; + // const wrapper = mountWithIntl( + // + // ); - const refDisplayName = wrapper.ref('display_name'); - refDisplayName.value = 'new display_name'; + // const refDisplayName = wrapper.ref('display_name'); + // refDisplayName.value = 'new display_name'; - const refChannelHeader = wrapper.ref('channel_header'); - refChannelHeader.value = 'new channel_header'; + // const refChannelHeader = wrapper.ref('channel_header'); + // refChannelHeader.value = 'new channel_header'; - const refChannelPurpose = wrapper.ref('channel_purpose'); - refChannelPurpose.value = 'new channel_purpose'; + // const refChannelPurpose = wrapper.ref('channel_purpose'); + // refChannelPurpose.value = 'new channel_purpose'; - wrapper.instance().handleChange(); + // wrapper.instance().handleChange(); - expect(newOnDataChanged).toHaveBeenCalledTimes(1); - expect(newOnDataChanged).toHaveBeenCalledWith({displayName: 'new display_name', header: 'new channel_header', purpose: 'new channel_purpose'}); - }); + // expect(newOnDataChanged).toHaveBeenCalledTimes(1); + // expect(newOnDataChanged).toHaveBeenCalledWith({displayName: 'new display_name', header: 'new channel_header', purpose: 'new channel_purpose'}); + // }); - test('should match when handleSubmit is called', () => { - const newOnSubmitChannel = jest.fn(); - const props = {...baseProps, onSubmitChannel: newOnSubmitChannel}; - const wrapper = mountWithIntl( - - ); - wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + // test('should match when handleSubmit is called', () => { + // const newOnSubmitChannel = jest.fn(); + // const props = {...baseProps, onSubmitChannel: newOnSubmitChannel}; + // const wrapper = mountWithIntl( + // + // ); + // wrapper.instance().handleSubmit({preventDefault: jest.fn()}); - expect(newOnSubmitChannel).toHaveBeenCalledTimes(1); - expect(wrapper.state('displayNameError')).toEqual(''); - }); + // expect(newOnSubmitChannel).toHaveBeenCalledTimes(1); + // expect(wrapper.state('displayNameError')).toEqual(''); + // }); test('should have called handleSubmit on onEnterKeyDown', () => { const wrapper = shallow( diff --git a/tests/components/post_deleted_modal.test.jsx b/tests/components/post_deleted_modal.test.jsx index 86a2a972174d..59633bb26795 100644 --- a/tests/components/post_deleted_modal.test.jsx +++ b/tests/components/post_deleted_modal.test.jsx @@ -3,9 +3,10 @@ import React from 'react'; import {shallow} from 'enzyme'; -import {Modal} from 'react-bootstrap'; -import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +// import {Modal} from 'react-bootstrap'; + +// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import PostDeletedModal from 'components/post_deleted_modal.jsx'; describe('components/ChannelInfoModal', () => { @@ -35,20 +36,20 @@ describe('components/ChannelInfoModal', () => { expect(wrapper).toMatchSnapshot(); }); - test('should call onHide callback when modal is hidden', (done) => { - function onHide() { - done(); - } + // test('should call onHide callback when modal is hidden', (done) => { + // function onHide() { + // done(); + // } - const wrapper = mountWithIntl( - - ); + // const wrapper = mountWithIntl( + // + // ); - wrapper.find(Modal).first().props().onHide(); - }); + // wrapper.find(Modal).first().props().onHide(); + // }); test('shouldComponentUpdate returns the correct results', () => { function emptyFunction() {} //eslint-disable-line no-empty-function diff --git a/tests/plugins/__snapshots__/pluggable.test.jsx.snap b/tests/plugins/__snapshots__/pluggable.test.jsx.snap index eab18aabf279..96a3bb25a36c 100644 --- a/tests/plugins/__snapshots__/pluggable.test.jsx.snap +++ b/tests/plugins/__snapshots__/pluggable.test.jsx.snap @@ -163,7 +163,6 @@ exports[`plugins/Pluggable should match snapshot with no overridden component 1`
Date: Wed, 15 Nov 2017 18:44:55 +0800 Subject: [PATCH 2/3] add "clearMocks:true" to jest config --- package.json | 1 + tests/components/audio_video_preview.test.jsx | 4 ---- tests/components/pdf_preview.test.jsx | 4 ---- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/package.json b/package.json index e3850e698e2a..2be3afde68de 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ "/node_modules/", "/non_npm_dependencies/" ], + "clearMocks": true, "collectCoverageFrom": [ "actions/**/*.{js,jsx}", "client/**/*.{js,jsx}", diff --git a/tests/components/audio_video_preview.test.jsx b/tests/components/audio_video_preview.test.jsx index c7a388d10af1..4d2c00b18731 100644 --- a/tests/components/audio_video_preview.test.jsx +++ b/tests/components/audio_video_preview.test.jsx @@ -16,10 +16,6 @@ describe('component/AudioVideoPreview', () => { fileUrl: '/api/v4/files/file_id' }; - afterAll(() => { - jest.clearAllMocks(); - }); - test('should match snapshot without children', () => { const wrapper = shallow( diff --git a/tests/components/pdf_preview.test.jsx b/tests/components/pdf_preview.test.jsx index eacca69bbeac..5cf88a302904 100644 --- a/tests/components/pdf_preview.test.jsx +++ b/tests/components/pdf_preview.test.jsx @@ -23,10 +23,6 @@ describe('component/PDFPreview', () => { fileUrl: 'https://pre-release.mattermost.com/api/v4/files/ips59w4w9jnfbrs3o94m1dbdie' }; - afterAll(() => { - jest.clearAllMocks(); - }); - test('should match snapshot, loading', () => { const wrapper = shallow( From 0ffac4f6aa58bba9600e6580d436bb63bd255626 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Wed, 15 Nov 2017 19:09:27 +0800 Subject: [PATCH 3/3] revert commented tests and upgrade to "enzyme-adapter-react-16@1.1.0" which fix React 16 Portals issue --- package.json | 2 +- tests/components/about_build_modal.test.jsx | 38 +++-- tests/components/channel_info_modal.test.jsx | 36 ++--- tests/components/edit_post_modal.test.jsx | 156 +++++++++---------- tests/components/get_link_modal.test.jsx | 17 +- tests/components/new_channel_modal.test.jsx | 54 +++---- tests/components/post_deleted_modal.test.jsx | 29 ++-- yarn.lock | 6 +- 8 files changed, 166 insertions(+), 172 deletions(-) diff --git a/package.json b/package.json index 2be3afde68de..36100ff758f2 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "cross-env": "5.1.1", "css-loader": "0.28.7", "enzyme": "3.1.1", - "enzyme-adapter-react-16": "1.0.4", + "enzyme-adapter-react-16": "1.1.0", "enzyme-to-json": "3.2.2", "eslint": "3.17.1", "eslint-import-resolver-webpack": "0.8.3", diff --git a/tests/components/about_build_modal.test.jsx b/tests/components/about_build_modal.test.jsx index 98f69ff8aeab..7b6af8812193 100644 --- a/tests/components/about_build_modal.test.jsx +++ b/tests/components/about_build_modal.test.jsx @@ -2,12 +2,10 @@ // See License.txt for license information. import React from 'react'; - -// import {Modal} from 'react-bootstrap'; - +import {Modal} from 'react-bootstrap'; import {shallow} from 'enzyme'; -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import AboutBuildModal from 'components/about_build_modal/about_build_modal.jsx'; @@ -81,22 +79,22 @@ describe('components/AboutBuildModal', () => { expect(wrapper.find('#versionString').text()).toBe(' 3.6.0\u00a0 (3.6.2)'); }); - // test('should call onModalDismissed callback when the modal is hidden', (done) => { - // function onHide() { - // done(); - // } - - // const wrapper = mountWithIntl( - // - // ); - - // wrapper.find(Modal).first().props().onHide(); - // }); + test('should call onModalDismissed callback when the modal is hidden', (done) => { + function onHide() { + done(); + } + + const wrapper = mountWithIntl( + + ); + + wrapper.find(Modal).first().props().onHide(); + }); function shallowAboutBuildModal(props = {}) { const onModalDismissed = jest.fn(); diff --git a/tests/components/channel_info_modal.test.jsx b/tests/components/channel_info_modal.test.jsx index be747f8cd0f8..e9be049e8278 100644 --- a/tests/components/channel_info_modal.test.jsx +++ b/tests/components/channel_info_modal.test.jsx @@ -2,12 +2,10 @@ // See License.txt for license information. import React from 'react'; - -// import {Modal} from 'react-bootstrap'; - +import {Modal} from 'react-bootstrap'; import {shallow} from 'enzyme'; -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import ChannelInfoModal from 'components/channel_info_modal/channel_info_modal.jsx'; @@ -26,19 +24,19 @@ describe('components/ChannelInfoModal', () => { expect(wrapper).toMatchSnapshot(); }); - // test('should call onHide callback when modal is hidden', (done) => { - // function onHide() { - // done(); - // } - - // const wrapper = mountWithIntl( - // - // ); - - // wrapper.find(Modal).first().props().onExited(); - // }); + test('should call onHide callback when modal is hidden', (done) => { + function onHide() { + done(); + } + + const wrapper = mountWithIntl( + + ); + + wrapper.find(Modal).first().props().onExited(); + }); }); diff --git a/tests/components/edit_post_modal.test.jsx b/tests/components/edit_post_modal.test.jsx index fb47ce40a55a..5e21d2e1bfcd 100644 --- a/tests/components/edit_post_modal.test.jsx +++ b/tests/components/edit_post_modal.test.jsx @@ -1,7 +1,7 @@ import React from 'react'; import {shallow} from 'enzyme'; -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import Constants from 'utils/constants'; import EditPostModal from 'components/edit_post_modal/edit_post_modal.jsx'; @@ -217,49 +217,49 @@ describe('comoponents/edit_post_modal/edit_post_modal.jsx', () => { expect(wrapper.state().showEmojiPicker).toBe(false); }); - // it('should add emoji to editText when an emoji is clicked', () => { - // const wrapper = mountWithIntl(createEditPost()); - // wrapper.setState({editText: ''}); - // wrapper.instance().handleEmojiClick(null); - // wrapper.instance().handleEmojiClick({}); - // wrapper.instance().handleEmojiClick({aliases: []}); - // expect(wrapper.state().editText).toBe(''); - - // wrapper.setState({editText: ''}); - // wrapper.instance().handleEmojiClick({name: '+1', aliases: ['thumbsup']}); - // expect(wrapper.state().editText).toBe(':+1: '); - - // wrapper.setState({editText: 'test'}); - // wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); - // expect(wrapper.state().editText).toBe('test :-1: '); - - // wrapper.setState({editText: 'test '}); - // wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); - // expect(wrapper.state().editText).toBe('test :-1: '); - // }); - - // it('should set the focus and recalcule the size of the edit box enter end', () => { - // const wrapper = mountWithIntl(createEditPost()); - // const instance = wrapper.instance(); - // const ref = wrapper.ref('editbox'); - // ref.focus = jest.fn(); - // ref.recalculateSize = jest.fn(); - // expect(ref.focus).not.toBeCalled(); - // expect(ref.recalculateSize).not.toBeCalled(); - // instance.handleEntered(); - // expect(ref.focus).toBeCalled(); - // expect(ref.recalculateSize).toBeCalled(); - // }); - - // it('should hide the preview on exit start', () => { - // const wrapper = mountWithIntl(createEditPost()); - // const instance = wrapper.instance(); - // const ref = wrapper.ref('editbox'); - // ref.hidePreview = jest.fn(); - // expect(ref.hidePreview).not.toBeCalled(); - // instance.handleExit(); - // expect(ref.hidePreview).toBeCalled(); - // }); + it('should add emoji to editText when an emoji is clicked', () => { + const wrapper = mountWithIntl(createEditPost()); + wrapper.setState({editText: ''}); + wrapper.instance().handleEmojiClick(null); + wrapper.instance().handleEmojiClick({}); + wrapper.instance().handleEmojiClick({aliases: []}); + expect(wrapper.state().editText).toBe(''); + + wrapper.setState({editText: ''}); + wrapper.instance().handleEmojiClick({name: '+1', aliases: ['thumbsup']}); + expect(wrapper.state().editText).toBe(':+1: '); + + wrapper.setState({editText: 'test'}); + wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); + expect(wrapper.state().editText).toBe('test :-1: '); + + wrapper.setState({editText: 'test '}); + wrapper.instance().handleEmojiClick({name: '-1', aliases: ['thumbsdown']}); + expect(wrapper.state().editText).toBe('test :-1: '); + }); + + it('should set the focus and recalcule the size of the edit box enter end', () => { + const wrapper = mountWithIntl(createEditPost()); + const instance = wrapper.instance(); + const ref = wrapper.ref('editbox'); + ref.focus = jest.fn(); + ref.recalculateSize = jest.fn(); + expect(ref.focus).not.toBeCalled(); + expect(ref.recalculateSize).not.toBeCalled(); + instance.handleEntered(); + expect(ref.focus).toBeCalled(); + expect(ref.recalculateSize).toBeCalled(); + }); + + it('should hide the preview on exit start', () => { + const wrapper = mountWithIntl(createEditPost()); + const instance = wrapper.instance(); + const ref = wrapper.ref('editbox'); + ref.hidePreview = jest.fn(); + expect(ref.hidePreview).not.toBeCalled(); + instance.handleExit(); + expect(ref.hidePreview).toBeCalled(); + }); it('should hide when confirm the edition and the message is not edited', () => { const actions = { @@ -403,38 +403,38 @@ describe('comoponents/edit_post_modal/edit_post_modal.jsx', () => { expect(instance.handleEdit).not.toBeCalled(); }); - // it('should handle edition on key press enter depending on the conditions', () => { - // global.navigator = {userAgent: 'Android'}; - // var wrapper = mountWithIntl(createEditPost({ctrlSend: true})); - // var instance = wrapper.instance(); - // const preventDefault = jest.fn(); - // instance.handleEdit = jest.fn(); - // instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - // expect(instance.handleEdit).not.toBeCalled(); - // expect(preventDefault).not.toBeCalled(); - // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: false, preventDefault, shiftKey: false, altKey: false}); - // expect(instance.handleEdit).not.toBeCalled(); - // expect(preventDefault).not.toBeCalled(); - // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - // expect(instance.handleEdit).toBeCalled(); - // expect(preventDefault).toBeCalled(); - - // global.navigator = {userAgent: 'Chrome'}; - // wrapper = mountWithIntl(createEditPost({ctrlSend: false})); - // instance = wrapper.instance(); - // preventDefault.mockClear(); - // instance.handleEdit = jest.fn(); - // instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - // expect(instance.handleEdit).not.toBeCalled(); - // expect(preventDefault).not.toBeCalled(); - // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: true, altKey: false}); - // expect(instance.handleEdit).not.toBeCalled(); - // expect(preventDefault).not.toBeCalled(); - // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: true}); - // expect(instance.handleEdit).not.toBeCalled(); - // expect(preventDefault).not.toBeCalled(); - // instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); - // expect(instance.handleEdit).toBeCalled(); - // expect(preventDefault).toBeCalled(); - // }); + it('should handle edition on key press enter depending on the conditions', () => { + global.navigator = {userAgent: 'Android'}; + var wrapper = mountWithIntl(createEditPost({ctrlSend: true})); + var instance = wrapper.instance(); + const preventDefault = jest.fn(); + instance.handleEdit = jest.fn(); + instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + expect(instance.handleEdit).not.toBeCalled(); + expect(preventDefault).not.toBeCalled(); + instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: false, preventDefault, shiftKey: false, altKey: false}); + expect(instance.handleEdit).not.toBeCalled(); + expect(preventDefault).not.toBeCalled(); + instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + expect(instance.handleEdit).toBeCalled(); + expect(preventDefault).toBeCalled(); + + global.navigator = {userAgent: 'Chrome'}; + wrapper = mountWithIntl(createEditPost({ctrlSend: false})); + instance = wrapper.instance(); + preventDefault.mockClear(); + instance.handleEdit = jest.fn(); + instance.handleEditKeyPress({which: 1, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + expect(instance.handleEdit).not.toBeCalled(); + expect(preventDefault).not.toBeCalled(); + instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: true, altKey: false}); + expect(instance.handleEdit).not.toBeCalled(); + expect(preventDefault).not.toBeCalled(); + instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: true}); + expect(instance.handleEdit).not.toBeCalled(); + expect(preventDefault).not.toBeCalled(); + instance.handleEditKeyPress({which: Constants.KeyCodes.ENTER, ctrlKey: true, preventDefault, shiftKey: false, altKey: false}); + expect(instance.handleEdit).toBeCalled(); + expect(preventDefault).toBeCalled(); + }); }); diff --git a/tests/components/get_link_modal.test.jsx b/tests/components/get_link_modal.test.jsx index cc0a3c14b39d..273b434d8100 100644 --- a/tests/components/get_link_modal.test.jsx +++ b/tests/components/get_link_modal.test.jsx @@ -2,11 +2,10 @@ // See License.txt for license information. import React from 'react'; - import {shallow} from 'enzyme'; import {Modal} from 'react-bootstrap'; -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import GetLinkModal from 'components/get_link_modal.jsx'; @@ -61,12 +60,12 @@ describe('components/GetLinkModal', () => { expect(wrapper.state('copiedLink')).toBe(false); }); - // test('should have handle copyLink', () => { - // const wrapper = mountWithIntl( - // - // ); + test('should have handle copyLink', () => { + const wrapper = mountWithIntl( + + ); - // wrapper.instance().copyLink(); - // expect(wrapper.state('copiedLink')).toBe(true); - // }); + wrapper.instance().copyLink(); + expect(wrapper.state('copiedLink')).toBe(true); + }); }); diff --git a/tests/components/new_channel_modal.test.jsx b/tests/components/new_channel_modal.test.jsx index c3e42d6c71e8..03d656201f66 100644 --- a/tests/components/new_channel_modal.test.jsx +++ b/tests/components/new_channel_modal.test.jsx @@ -5,7 +5,7 @@ import React from 'react'; import {shallow} from 'enzyme'; import {Modal} from 'react-bootstrap'; -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import Constants from 'utils/constants.jsx'; @@ -79,39 +79,39 @@ describe('components/NewChannelModal', () => { expect(wrapper).toMatchSnapshot(); }); - // test('should match when handleChange is called', () => { - // const newOnDataChanged = jest.fn(); - // const props = {...baseProps, onDataChanged: newOnDataChanged}; - // const wrapper = mountWithIntl( - // - // ); + test('should match when handleChange is called', () => { + const newOnDataChanged = jest.fn(); + const props = {...baseProps, onDataChanged: newOnDataChanged}; + const wrapper = mountWithIntl( + + ); - // const refDisplayName = wrapper.ref('display_name'); - // refDisplayName.value = 'new display_name'; + const refDisplayName = wrapper.ref('display_name'); + refDisplayName.value = 'new display_name'; - // const refChannelHeader = wrapper.ref('channel_header'); - // refChannelHeader.value = 'new channel_header'; + const refChannelHeader = wrapper.ref('channel_header'); + refChannelHeader.value = 'new channel_header'; - // const refChannelPurpose = wrapper.ref('channel_purpose'); - // refChannelPurpose.value = 'new channel_purpose'; + const refChannelPurpose = wrapper.ref('channel_purpose'); + refChannelPurpose.value = 'new channel_purpose'; - // wrapper.instance().handleChange(); + wrapper.instance().handleChange(); - // expect(newOnDataChanged).toHaveBeenCalledTimes(1); - // expect(newOnDataChanged).toHaveBeenCalledWith({displayName: 'new display_name', header: 'new channel_header', purpose: 'new channel_purpose'}); - // }); + expect(newOnDataChanged).toHaveBeenCalledTimes(1); + expect(newOnDataChanged).toHaveBeenCalledWith({displayName: 'new display_name', header: 'new channel_header', purpose: 'new channel_purpose'}); + }); - // test('should match when handleSubmit is called', () => { - // const newOnSubmitChannel = jest.fn(); - // const props = {...baseProps, onSubmitChannel: newOnSubmitChannel}; - // const wrapper = mountWithIntl( - // - // ); - // wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + test('should match when handleSubmit is called', () => { + const newOnSubmitChannel = jest.fn(); + const props = {...baseProps, onSubmitChannel: newOnSubmitChannel}; + const wrapper = mountWithIntl( + + ); + wrapper.instance().handleSubmit({preventDefault: jest.fn()}); - // expect(newOnSubmitChannel).toHaveBeenCalledTimes(1); - // expect(wrapper.state('displayNameError')).toEqual(''); - // }); + expect(newOnSubmitChannel).toHaveBeenCalledTimes(1); + expect(wrapper.state('displayNameError')).toEqual(''); + }); test('should have called handleSubmit on onEnterKeyDown', () => { const wrapper = shallow( diff --git a/tests/components/post_deleted_modal.test.jsx b/tests/components/post_deleted_modal.test.jsx index 59633bb26795..86a2a972174d 100644 --- a/tests/components/post_deleted_modal.test.jsx +++ b/tests/components/post_deleted_modal.test.jsx @@ -3,10 +3,9 @@ import React from 'react'; import {shallow} from 'enzyme'; +import {Modal} from 'react-bootstrap'; -// import {Modal} from 'react-bootstrap'; - -// import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import PostDeletedModal from 'components/post_deleted_modal.jsx'; describe('components/ChannelInfoModal', () => { @@ -36,20 +35,20 @@ describe('components/ChannelInfoModal', () => { expect(wrapper).toMatchSnapshot(); }); - // test('should call onHide callback when modal is hidden', (done) => { - // function onHide() { - // done(); - // } + test('should call onHide callback when modal is hidden', (done) => { + function onHide() { + done(); + } - // const wrapper = mountWithIntl( - // - // ); + const wrapper = mountWithIntl( + + ); - // wrapper.find(Modal).first().props().onHide(); - // }); + wrapper.find(Modal).first().props().onHide(); + }); test('shouldComponentUpdate returns the correct results', () => { function emptyFunction() {} //eslint-disable-line no-empty-function diff --git a/yarn.lock b/yarn.lock index e2011613b658..1d9ca879992c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2607,9 +2607,9 @@ entities@^1.1.1, entities@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0" -enzyme-adapter-react-16@1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.0.4.tgz#67f898cc053452f5c786424e395fe0c63a0607fe" +enzyme-adapter-react-16@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.1.0.tgz#86c5db7c10f0be6ec25d54ca41b59f2abb397cf4" dependencies: enzyme-adapter-utils "^1.1.0" lodash "^4.17.4"