-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pooja1425
committed
Mar 5, 2021
1 parent
a30a8d3
commit 74951aa
Showing
3 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ( | ||
<MockedProvider mocks={mocks}> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<MemoryRouter> | ||
<FlowList /> | ||
</MemoryRouter> | ||
</MockedProvider> | ||
); | ||
|
||
describe('<Flow />', () => { | ||
it('should render Flow', () => { | ||
setUserSession(JSON.stringify({ roles: ['Admin'] })); | ||
|
||
describe('<FlowList />', () => { | ||
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) => ( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<Router history={history}> | ||
<Flow match={match} /> | ||
</Router> | ||
</MockedProvider> | ||
); | ||
const { container } = render(copyFlow({ params: { id: 1 } })); | ||
await waitFor(() => { | ||
expect(container.querySelector('input[name="name"]')?.value).toBe('Copy of Help'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters