From 74951aaca319406a69cccd75609af3a855bf27ff Mon Sep 17 00:00:00 2001 From: pooja1425 Date: Fri, 5 Mar 2021 21:20:37 +0530 Subject: [PATCH] Added tests for flow list component --- .../Flow/FlowList/FlowList.test.tsx | 71 +++++++++++++++++-- src/containers/List/List.tsx | 1 + src/mocks/Flow.tsx | 45 ++++++++++++ 3 files changed, 110 insertions(+), 7 deletions(-) diff --git a/src/containers/Flow/FlowList/FlowList.test.tsx b/src/containers/Flow/FlowList/FlowList.test.tsx index 7cda3b64a..aefa7b0c6 100644 --- a/src/containers/Flow/FlowList/FlowList.test.tsx +++ b/src/containers/Flow/FlowList/FlowList.test.tsx @@ -1,23 +1,80 @@ import React from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render, waitFor } from '@testing-library/react'; import { FlowList } from './FlowList'; import { MockedProvider } from '@apollo/client/testing'; -import { getFlowCountQuery } from '../../../mocks/Flow'; -import { MemoryRouter } from 'react-router'; +import { + getFlowCountQuery, + filterFlowQuery, + filterFlowNewQuery, + getFlowCountNewQuery, + getFlowQuery, +} from '../../../mocks/Flow'; +import { MemoryRouter, Router } from 'react-router-dom'; +import { createBrowserHistory } from 'history'; +import { setUserSession } from '../../../services/AuthService'; +import { Flow } from '../Flow'; -const mocks = [getFlowCountQuery]; +const mocks = [ + getFlowCountQuery, + filterFlowQuery, + filterFlowNewQuery, + getFlowCountNewQuery, + getFlowQuery, +]; const flowList = ( - + ); -describe('', () => { - it('should render Flow', () => { +setUserSession(JSON.stringify({ roles: ['Admin'] })); + +describe('', () => { + test('should render Flow', async () => { const { getByText } = render(flowList); expect(getByText('Loading...')).toBeInTheDocument(); + await waitFor(() => { + expect(getByText('Flows')); + }); + }); + + test('should search flow and check if flow keywprds are present below the name', async () => { + const { getByText, getByTestId, queryByPlaceholderText } = render(flowList); + await waitFor(() => { + // type "Help Workflow" in search box and enter + expect(getByTestId('searchInput')).toBeInTheDocument(); + const searchInput = queryByPlaceholderText('Search'); + fireEvent.change(searchInput, { target: { value: 'Help Workflow' } }); + fireEvent.keyPress(searchInput, { key: 'enter', keyCode: 13 }); + expect(getByText('help, मदद')).toBeInTheDocument(); + }); + }); + + test('click on Make a copy', async () => { + const { container } = render(flowList); + await waitFor(() => { + expect(container.querySelector('#copy-icon')).toBeInTheDocument(); + fireEvent.click(container.querySelector('#copy-icon')); + }); + }); + + test('should redirect to make a copy', async () => { + const history: any = createBrowserHistory(); + history.push({ pathname: `/flow/1/edit`, state: 'copy' }); + + const copyFlow = (match: any) => ( + + + + + + ); + const { container } = render(copyFlow({ params: { id: 1 } })); + await waitFor(() => { + expect(container.querySelector('input[name="name"]')?.value).toBe('Copy of Help'); + }); }); }); diff --git a/src/containers/List/List.tsx b/src/containers/List/List.tsx index 280bef7be..25902f883 100644 --- a/src/containers/List/List.tsx +++ b/src/containers/List/List.tsx @@ -399,6 +399,7 @@ export const List: React.SFC = ({ color="default" data-testid="additionalButton" className={styles.additonalButton} + id="copy-icon" onClick={() => action.dialog(additionalActionParameter)} key={key} > diff --git a/src/mocks/Flow.tsx b/src/mocks/Flow.tsx index aef5088d9..5b49a8d38 100644 --- a/src/mocks/Flow.tsx +++ b/src/mocks/Flow.tsx @@ -159,3 +159,48 @@ export const getPublishedFlowQuery = { }, }, }; + +export const filterFlowNewQuery = { + request: { + query: FILTER_FLOW, + variables: { + filter: { name: 'Help Workflow' }, + opts: { + limit: 50, + offset: 0, + order: 'ASC', + orderWith: 'name', + }, + }, + }, + + result: { + data: { + flows: [ + { + id: '1', + ignoreKeywords: true, + keywords: ['help', 'मदद'], + name: 'Help Workflow', + updatedAt: '2021-03-05T04:32:23Z', + uuid: '3fa22108-f464-41e5-81d9-d8a298854429', + }, + ], + }, + }, +}; + +export const getFlowCountNewQuery = { + request: { + query: GET_FLOW_COUNT, + variables: { + filter: { name: 'Help Workflow' }, + }, + }, + + result: { + data: { + countFlows: 1, + }, + }, +};