Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[PLT-7814] Cleanup package.json & enzyme adapter, and improve EditIncomingWebhook unit test #138

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions tests/components/about_build_modal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
<AbstractIncomingWebhook
action={[Function]}
footer={
Object {
"defaultMessage": "Update",
"id": "update_incoming_webhook.update",
}
}
header={
Object {
"defaultMessage": "Edit",
"id": "integrations.edit",
}
}
initialHook={
Object {
"id": "id",
"token": "token",
}
}
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
}
}
/>
`;

exports[`components/integrations/EditIncomingWebhook should have called submitHook when editIncomingHook is initiated (with data) 1`] = `
<AbstractIncomingWebhook
action={[Function]}
footer={
Object {
"defaultMessage": "Update",
"id": "update_incoming_webhook.update",
}
}
header={
Object {
"defaultMessage": "Edit",
"id": "integrations.edit",
}
}
initialHook={
Object {
"id": "id",
"token": "token",
}
}
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
}
}
/>
`;

exports[`components/integrations/EditIncomingWebhook should have called submitHook when editIncomingHook is initiated (with server error) 1`] = `
<AbstractIncomingWebhook
action={[Function]}
footer={
Object {
"defaultMessage": "Update",
"id": "update_incoming_webhook.update",
}
}
header={
Object {
"defaultMessage": "Edit",
"id": "integrations.edit",
}
}
initialHook={
Object {
"id": "id",
"token": "token",
}
}
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
}
}
/>
`;

exports[`components/integrations/EditIncomingWebhook should not call getIncomingHook 1`] = `
<LoadingScreen
position="relative"
Expand Down
5 changes: 1 addition & 4 deletions tests/components/integrations/add_incoming_webhook.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 AddIncomingWebhook from 'components/integrations/components/add_incoming_webhook/add_incoming_webhook.jsx';

configure({adapter: new Adapter()});

describe('components/integrations/AddIncomingWebhook', () => {
const createIncomingHook = jest.fn();
const props = {
Expand Down
57 changes: 48 additions & 9 deletions tests/components/integrations/edit_incoming_webhook.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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(<EditIncomingWebhook {...props}/>);

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(<EditIncomingWebhook {...props}/>);

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(<EditIncomingWebhook {...props}/>);

wrapper.instance().editIncomingHook(asyncHook);
expect(wrapper).toMatchSnapshot();
expect(newUpdateIncomingHook).toHaveBeenCalledTimes(1);
expect(newUpdateIncomingHook).toBeCalledWith(asyncHook);
});
});