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

Commit

Permalink
[MM-20455] Migrate 'components/integrations/edit_incoming_webhook' mo…
Browse files Browse the repository at this point in the history
…dule and associated tests to TypeScript (#6596)
  • Loading branch information
didithilmy authored and jfrerich committed Oct 23, 2020
1 parent 1a6896c commit 25e15ca
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
}
initialHook={
Object {
"channel_id": "channel_id",
"channel_locked": false,
"create_at": 0,
"delete_at": 20,
"description": "description",
"display_name": "display_name",
"icon_url": "http://test/icon.png",
"id": "id",
"token": "token",
"team_id": "team_id",
"update_at": 10,
"user_id": "user_id",
"username": "username",
}
}
loading={
Expand All @@ -32,8 +42,21 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
"allow_open_invite": false,
"allowed_domains": "",
"company_name": "",
"create_at": 0,
"delete_at": 0,
"description": "",
"display_name": "name",
"email": "",
"group_constrained": false,
"id": "team_id",
"invite_id": "",
"name": "DN",
"scheme_id": "id",
"type": "O",
"update_at": 0,
}
}
/>
Expand All @@ -58,8 +81,18 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
}
initialHook={
Object {
"channel_id": "channel_id",
"channel_locked": false,
"create_at": 0,
"delete_at": 20,
"description": "description",
"display_name": "display_name",
"icon_url": "http://test/icon.png",
"id": "id",
"token": "token",
"team_id": "team_id",
"update_at": 10,
"user_id": "user_id",
"username": "username",
}
}
loading={
Expand All @@ -71,8 +104,21 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
"allow_open_invite": false,
"allowed_domains": "",
"company_name": "",
"create_at": 0,
"delete_at": 0,
"description": "",
"display_name": "name",
"email": "",
"group_constrained": false,
"id": "team_id",
"invite_id": "",
"name": "DN",
"scheme_id": "id",
"type": "O",
"update_at": 0,
}
}
/>
Expand All @@ -97,8 +143,18 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
}
initialHook={
Object {
"channel_id": "channel_id",
"channel_locked": false,
"create_at": 0,
"delete_at": 20,
"description": "description",
"display_name": "display_name",
"icon_url": "http://test/icon.png",
"id": "id",
"token": "token",
"team_id": "team_id",
"update_at": 10,
"user_id": "user_id",
"username": "username",
}
}
loading={
Expand All @@ -110,8 +166,21 @@ exports[`components/integrations/EditIncomingWebhook should have called submitHo
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
"allow_open_invite": false,
"allowed_domains": "",
"company_name": "",
"create_at": 0,
"delete_at": 0,
"description": "",
"display_name": "name",
"email": "",
"group_constrained": false,
"id": "team_id",
"invite_id": "",
"name": "DN",
"scheme_id": "id",
"type": "O",
"update_at": 0,
}
}
/>
Expand Down Expand Up @@ -143,8 +212,18 @@ exports[`components/integrations/EditIncomingWebhook should show AbstractIncomin
}
initialHook={
Object {
"channel_id": "channel_id",
"channel_locked": false,
"create_at": 0,
"delete_at": 20,
"description": "description",
"display_name": "display_name",
"icon_url": "http://test/icon.png",
"id": "id",
"token": "token",
"team_id": "team_id",
"update_at": 10,
"user_id": "user_id",
"username": "username",
}
}
loading={
Expand All @@ -156,8 +235,21 @@ exports[`components/integrations/EditIncomingWebhook should show AbstractIncomin
serverError=""
team={
Object {
"id": "testteamid",
"name": "test",
"allow_open_invite": false,
"allowed_domains": "",
"company_name": "",
"create_at": 0,
"delete_at": 0,
"description": "",
"display_name": "name",
"email": "",
"group_constrained": false,
"id": "team_id",
"invite_id": "",
"name": "DN",
"scheme_id": "id",
"type": "O",
"update_at": 0,
}
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
// See LICENSE.txt for license information.

import React from 'react';
import {shallow} from 'enzyme';
import {shallow, ShallowWrapper} from 'enzyme';

import {IncomingWebhook} from 'mattermost-redux/types/integrations';
import {ActionResult} from 'mattermost-redux/types/actions';

import {browserHistory} from 'utils/browser_history';
import EditIncomingWebhook from 'components/integrations/edit_incoming_webhook/edit_incoming_webhook.jsx';
import EditIncomingWebhook from 'components/integrations/edit_incoming_webhook/edit_incoming_webhook';
import {TestHelper} from '../../../utils/test_helper';

describe('components/integrations/EditIncomingWebhook', () => {
const hook = {
id: 'id',
token: 'token',
create_at: 0,
update_at: 10,
delete_at: 20,
user_id: 'user_id',
channel_id: 'channel_id',
team_id: 'team_id',
display_name: 'display_name',
description: 'description',
username: 'username',
icon_url: 'http://test/icon.png',
channel_locked: false,
};

let updateIncomingHook = null;
let getIncomingHook = null;
let actions = {};
const updateIncomingHook = jest.fn();
const getIncomingHook = jest.fn();
const actions = {
updateIncomingHook: updateIncomingHook as (hook: IncomingWebhook) => Promise<ActionResult>,
getIncomingHook: getIncomingHook as (hookId: string) => Promise<ActionResult>,
};

const requiredProps = {
hookId: 'somehookid',
teamId: 'testteamid',
team: {
id: 'testteamid',
name: 'test',
},
team: TestHelper.getTeamMock(),
updateIncomingHookRequest: {
status: 'not_started',
error: null,
Expand All @@ -34,18 +48,8 @@ describe('components/integrations/EditIncomingWebhook', () => {
};

afterEach(() => {
updateIncomingHook = null;
getIncomingHook = null;
actions = {};
});

beforeEach(() => {
updateIncomingHook = jest.fn();
getIncomingHook = jest.fn();
actions = {
updateIncomingHook,
getIncomingHook,
};
updateIncomingHook.mockReset();
getIncomingHook.mockReset();
});

test('should show Loading screen when no hook is provided', () => {
Expand Down Expand Up @@ -75,12 +79,9 @@ describe('components/integrations/EditIncomingWebhook', () => {
test('should have called submitHook when editIncomingHook is initiated (no server error)', async () => {
const newUpdateIncomingHook = jest.fn().mockReturnValue({data: ''});
const newActions = {...actions, updateIncomingHook: newUpdateIncomingHook};
const asyncHook = {
id: 'id',
token: 'token',
};
const asyncHook = {...hook};
const props = {...requiredProps, actions: newActions, hook};
const wrapper = shallow(<EditIncomingWebhook {...props}/>);
const wrapper: ShallowWrapper<any, any, EditIncomingWebhook> = shallow(<EditIncomingWebhook {...props}/>);

const instance = wrapper.instance();
await instance.editIncomingHook(asyncHook);
Expand All @@ -93,12 +94,9 @@ describe('components/integrations/EditIncomingWebhook', () => {
test('should have called submitHook when editIncomingHook is initiated (with server error)', async () => {
const newUpdateIncomingHook = jest.fn().mockReturnValue({data: ''});
const newActions = {...actions, updateIncomingHook: newUpdateIncomingHook};
const asyncHook = {
id: 'id',
token: 'token',
};
const asyncHook = {...hook};
const props = {...requiredProps, actions: newActions, hook};
const wrapper = shallow(<EditIncomingWebhook {...props}/>);
const wrapper: ShallowWrapper<any, any, EditIncomingWebhook> = shallow(<EditIncomingWebhook {...props}/>);

const instance = wrapper.instance();
await instance.editIncomingHook(asyncHook);
Expand All @@ -112,12 +110,9 @@ describe('components/integrations/EditIncomingWebhook', () => {
const newUpdateIncomingHook = jest.fn().mockReturnValue({data: 'data'});
const newActions = {...actions, updateIncomingHook: newUpdateIncomingHook};
browserHistory.push = jest.fn();
const asyncHook = {
id: 'id',
token: 'token',
};
const asyncHook = {...hook};
const props = {...requiredProps, actions: newActions, hook};
const wrapper = shallow(<EditIncomingWebhook {...props}/>);
const wrapper: ShallowWrapper<any, any, EditIncomingWebhook> = shallow(<EditIncomingWebhook {...props}/>);

const instance = wrapper.instance();
await instance.editIncomingHook(asyncHook);
Expand Down
Loading

0 comments on commit 25e15ca

Please sign in to comment.