Skip to content

Commit

Permalink
⚡ removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kurund committed Aug 2, 2020
1 parent 68d7a31 commit 8ed9b11
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 133 deletions.
131 changes: 3 additions & 128 deletions src/containers/Template/Form/SpeedSend/SpeedSend.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,139 +2,14 @@ import React from 'react';
import { render, wait, within, fireEvent, cleanup } from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import { MockedProvider } from '@apollo/client/testing';
import { GET_LANGUAGES } from '../../../../graphql/queries/List';
import {
GET_TEMPLATE,
GET_TEMPLATES_COUNT,
FILTER_TEMPLATES,
} from '../../../../graphql/queries/Template';
import { CREATE_TEMPLATE } from '../../../../graphql/mutations/Template';

import { SpeedSend } from './SpeedSend';
import { Switch, Route } from 'react-router-dom';
import { SpeedSendList } from '../../List/SpeedSendList/SpeedSendList';
import { TEMPLATE_MOCKS } from '../../Template.test.helper';

afterEach(cleanup);
const mocks = [
{
request: {
query: CREATE_TEMPLATE,
variables: {
input: {
body: 'new Template body',
label: 'new Template',
languageId: 1,
type: 'TEXT',
},
},
},
result: {
data: {
createSessionTemplate: {
sessionTemplate: {
body: 'new Template body',
id: '121',
label: 'new Template',
},
},
},
},
},
{
request: {
query: GET_TEMPLATES_COUNT,
variables: {
filter: {
label: '',
isHsm: false,
},
},
},
result: {
data: {
countSessionTemplates: 2,
},
},
},
{
request: {
query: FILTER_TEMPLATES,
variables: {
filter: {
label: '',
isHsm: false,
},
opts: {
limit: 10,
offset: 0,
order: 'ASC',
},
},
},
result: {
data: {
sessionTemplates: [
{
id: '87',
label: 'Good message',
body: 'Hey There',
isReserved: false,
isHsm: true,
},
{
id: '94',
label: 'Message',
body: 'some description',
isReserved: false,
isHsm: false,
},
],
},
},
},
{
request: {
query: GET_LANGUAGES,
},
result: {
data: {
languages: [
{
id: '1',
label: 'English (United States)',
},
{
id: '2',
label: 'Hindi (India)',
},
],
},
},
},

{
request: {
query: GET_TEMPLATE,
variables: {
id: 1,
},
},
result: {
data: {
sessionTemplate: {
sessionTemplate: {
id: 1,
label: 'important',
body: 'important template',
isActive: true,
language: {
id: 1,
},
},
},
},
},
},
];
const mocks = TEMPLATE_MOCKS;

test('cancel button should redirect to SpeedSendlist page', async () => {
const { container, getByText, unmount } = render(
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Template/List/HSMList/HSMList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import { MockedProvider } from '@apollo/client/testing';
import { HSMList } from './HSMList';
import { within } from '@testing-library/dom';
import { TEMPLATE_MOCKS } from '../Template.test.helper';
import { TEMPLATE_MOCKS } from '../../Template.test.helper';

afterEach(cleanup);
const mocks = TEMPLATE_MOCKS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import { MockedProvider } from '@apollo/client/testing';
import { SpeedSendList } from './SpeedSendList';
import { within } from '@testing-library/dom';
import { TEMPLATE_MOCKS } from '../Template.test.helper';
import { TEMPLATE_MOCKS } from '../../Template.test.helper';

afterEach(cleanup);
const mocks = TEMPLATE_MOCKS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GET_LANGUAGES } from '../../../graphql/queries/List';
import { GET_TEMPLATES_COUNT, FILTER_TEMPLATES } from '../../../graphql/queries/Template';
import { DELETE_TEMPLATE } from '../../../graphql/mutations/Template';
import { GET_LANGUAGES } from '../../graphql/queries/List';
import { GET_TEMPLATES_COUNT, FILTER_TEMPLATES, GET_TEMPLATE } from '../../graphql/queries/Template';
import { DELETE_TEMPLATE, CREATE_TEMPLATE } from '../../graphql/mutations/Template';

const count = {
request: {
Expand Down Expand Up @@ -127,6 +127,53 @@ const filterByBody = (body: string) => ({
});

export const TEMPLATE_MOCKS = [
{
request: {
query: CREATE_TEMPLATE,
variables: {
input: {
body: 'new Template body',
label: 'new Template',
languageId: 1,
type: 'TEXT',
},
},
},
result: {
data: {
createSessionTemplate: {
sessionTemplate: {
body: 'new Template body',
id: '121',
label: 'new Template',
},
},
},
},
},
{
request: {
query: GET_TEMPLATE,
variables: {
id: 1,
},
},
result: {
data: {
sessionTemplate: {
sessionTemplate: {
id: 1,
label: 'important',
body: 'important template',
isActive: true,
language: {
id: 1,
},
},
},
},
},
},
{
request: {
query: DELETE_TEMPLATE,
Expand Down

0 comments on commit 8ed9b11

Please sign in to comment.