From fb77f1effad24b761cd1123beeec79406d4bee6d Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Tue, 10 Oct 2017 17:17:48 +0800 Subject: [PATCH] cleanup package.json & enzyme adapter, and improve EditIncomingWebhook unit test --- package.json | 2 - tests/components/about_build_modal.test.jsx | 5 +- .../components/backstage_header.test.jsx | 5 +- .../edit_incoming_webhook.test.jsx.snap | 93 +++++++++++++++++++ .../add_incoming_webhook.test.jsx | 5 +- .../edit_incoming_webhook.test.jsx | 57 ++++++++++-- 6 files changed, 144 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 7b075ae77134..8a79c659d267 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "bootstrap-colorpicker": "2.5.2", "chart.js": "2.7.0", "compass-mixins": "0.12.10", - "enzyme-adapter-react-15": "1.0.1", "exif2css": "1.2.0", "fastclick": "1.0.6", "flux": "3.1.3", @@ -41,7 +40,6 @@ "react-redux": "5.0.6", "react-router": "2.8.1", "react-select": "1.0.0-rc.10", - "react-test-renderer": "15", "redux": "3.7.2", "redux-batched-actions": "0.2.0", "redux-persist": "4.10.1", diff --git a/tests/components/about_build_modal.test.jsx b/tests/components/about_build_modal.test.jsx index bef39a12433e..d7cccf1bc7f3 100644 --- a/tests/components/about_build_modal.test.jsx +++ b/tests/components/about_build_modal.test.jsx @@ -4,15 +4,12 @@ import React from 'react'; import {Modal} from 'react-bootstrap'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-15'; +import {shallow} from 'enzyme'; import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx'; import AboutBuildModal from 'components/about_build_modal/about_build_modal.jsx'; -configure({adapter: new Adapter()}); - describe('components/AboutBuildModal', () => { let config = null; let license = null; diff --git a/tests/components/backstage/components/backstage_header.test.jsx b/tests/components/backstage/components/backstage_header.test.jsx index 183979a3b23b..f6da444d9f6d 100644 --- a/tests/components/backstage/components/backstage_header.test.jsx +++ b/tests/components/backstage/components/backstage_header.test.jsx @@ -2,13 +2,10 @@ // See License.txt for license information. import React from 'react'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-15'; +import {shallow} from 'enzyme'; import BackstageHeader from 'components/backstage/components/backstage_header.jsx'; -configure({adapter: new Adapter()}); - describe('components/backstage/components/BackstageHeader', () => { test('should match snapshot without children', () => { const wrapper = shallow( diff --git a/tests/components/integrations/__snapshots__/edit_incoming_webhook.test.jsx.snap b/tests/components/integrations/__snapshots__/edit_incoming_webhook.test.jsx.snap index d8a99a45ca0e..01dd113922fc 100644 --- a/tests/components/integrations/__snapshots__/edit_incoming_webhook.test.jsx.snap +++ b/tests/components/integrations/__snapshots__/edit_incoming_webhook.test.jsx.snap @@ -1,5 +1,98 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components/integrations/EditIncomingWebhook should have called submitHook when editIncomingHook is initiated (no server error) 1`] = ` + +`; + +exports[`components/integrations/EditIncomingWebhook should have called submitHook when editIncomingHook is initiated (with data) 1`] = ` + +`; + +exports[`components/integrations/EditIncomingWebhook should have called submitHook when editIncomingHook is initiated (with server error) 1`] = ` + +`; + exports[`components/integrations/EditIncomingWebhook should not call getIncomingHook 1`] = ` { const createIncomingHook = jest.fn(); const props = { diff --git a/tests/components/integrations/edit_incoming_webhook.test.jsx b/tests/components/integrations/edit_incoming_webhook.test.jsx index 04576747bab1..aeb23ed9e18e 100644 --- a/tests/components/integrations/edit_incoming_webhook.test.jsx +++ b/tests/components/integrations/edit_incoming_webhook.test.jsx @@ -2,13 +2,10 @@ // See License.txt for license information. import React from 'react'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-15'; +import {shallow} from 'enzyme'; import EditIncomingWebhook from 'components/integrations/components/edit_incoming_webhook/edit_incoming_webhook.jsx'; -configure({adapter: new Adapter()}); - describe('components/integrations/EditIncomingWebhook', () => { global.window.mm_config = {}; @@ -79,9 +76,51 @@ describe('components/integrations/EditIncomingWebhook', () => { expect(getIncomingHook).toHaveBeenCalledTimes(0); }); - // // Should find way how to test editIncomingHook and submitHook - // test('should have called editIncomingHook and submitHook', () => { - // // assertion for editIncomingHook - // // assertion for submitHook - // } + test('should have called submitHook when editIncomingHook is initiated (no server error)', () => { + const asyncHook = { + id: 'id', + token: 'token' + }; + const props = {...requiredProps, actions, hook}; + const wrapper = shallow(); + + wrapper.instance().editIncomingHook(asyncHook); + expect(wrapper).toMatchSnapshot(); + expect(updateIncomingHook).toHaveBeenCalledTimes(1); + expect(updateIncomingHook).toBeCalledWith(asyncHook); + }); + + test('should have called submitHook when editIncomingHook is initiated (with server error)', () => { + const asyncHook = { + id: 'id', + token: 'token' + }; + const updateIncomingHookRequest = { + status: 'error', + error: {message: 'error message'} + }; + const props = {...requiredProps, actions, hook, updateIncomingHookRequest}; + const wrapper = shallow(); + + wrapper.instance().editIncomingHook(asyncHook); + expect(wrapper).toMatchSnapshot(); + expect(updateIncomingHook).toHaveBeenCalledTimes(1); + expect(updateIncomingHook).toBeCalledWith(asyncHook); + }); + + test('should have called submitHook when editIncomingHook is initiated (with data)', () => { + const newUpdateIncomingHook = jest.fn(() => 'data'); + const newActions = {...actions, updateIncomingHook: newUpdateIncomingHook}; + const asyncHook = { + id: 'id', + token: 'token' + }; + const props = {...requiredProps, actions: newActions, hook}; + const wrapper = shallow(); + + wrapper.instance().editIncomingHook(asyncHook); + expect(wrapper).toMatchSnapshot(); + expect(newUpdateIncomingHook).toHaveBeenCalledTimes(1); + expect(newUpdateIncomingHook).toBeCalledWith(asyncHook); + }); });