Add tests for modules/people, modules/pipeline, modules/search and modules/settings (#3395)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
mutation CreateOnePipelineStep($input: PipelineStepCreateInput!) {
|
||||
createPipelineStep(data: $input) {
|
||||
id
|
||||
name
|
||||
id
|
||||
createdAt
|
||||
opportunities {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
position
|
||||
color
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const deleteQuery = gql`
|
||||
mutation DeleteOnePipelineStep($idToDelete: ID!) {
|
||||
deletePipelineStep(id: $idToDelete) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const mockId = '8f3b2121-f194-4ba4-9fbf-2d5a37126806';
|
||||
export const currentPipelineId = 'f088c8c9-05d2-4276-b065-b863cc7d0b33';
|
||||
|
||||
const data = {
|
||||
color: 'yellow',
|
||||
id: 'columnId',
|
||||
position: 1,
|
||||
name: 'Column Title',
|
||||
pipeline: { connect: { id: currentPipelineId } },
|
||||
type: 'ongoing',
|
||||
};
|
||||
|
||||
export const variables = {
|
||||
input: {
|
||||
id: mockId,
|
||||
variables: {
|
||||
data,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const deleteVariables = { idToDelete: 'columnId' };
|
||||
|
||||
export const responseData = {
|
||||
...data,
|
||||
createdAt: '',
|
||||
opportunities: {
|
||||
edges: [],
|
||||
},
|
||||
updatedAt: '',
|
||||
};
|
||||
|
||||
export const deleteResponseData = {
|
||||
id: 'columnId',
|
||||
};
|
||||
@ -0,0 +1,104 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { RecoilRoot, useSetRecoilState } from 'recoil';
|
||||
|
||||
import { BoardColumnDefinition } from '@/object-record/record-board/types/BoardColumnDefinition';
|
||||
import { currentPipelineState } from '@/pipeline/states/currentPipelineState';
|
||||
|
||||
import {
|
||||
currentPipelineId,
|
||||
deleteQuery,
|
||||
deleteResponseData,
|
||||
deleteVariables,
|
||||
mockId,
|
||||
query,
|
||||
responseData,
|
||||
variables,
|
||||
} from '../__mocks__/usePipelineSteps';
|
||||
import { usePipelineSteps } from '../usePipelineSteps';
|
||||
|
||||
const mocks = [
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
variables,
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: {
|
||||
createPipelineStep: responseData,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
request: {
|
||||
query: deleteQuery,
|
||||
variables: deleteVariables,
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: {
|
||||
deletePipelineStep: deleteResponseData,
|
||||
},
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
const Wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<RecoilRoot>
|
||||
<MockedProvider mocks={mocks} addTypename={false}>
|
||||
{children}
|
||||
</MockedProvider>
|
||||
</RecoilRoot>
|
||||
);
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
v4: jest.fn(() => mockId),
|
||||
}));
|
||||
|
||||
describe('usePipelineSteps', () => {
|
||||
it('should handlePipelineStepAdd successfully', async () => {
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const setCurrentPipeline = useSetRecoilState(currentPipelineState);
|
||||
setCurrentPipeline({ id: currentPipelineId });
|
||||
return usePipelineSteps();
|
||||
},
|
||||
{
|
||||
wrapper: Wrapper,
|
||||
},
|
||||
);
|
||||
|
||||
const boardColumn: BoardColumnDefinition = {
|
||||
id: 'columnId',
|
||||
title: 'Column Title',
|
||||
colorCode: 'yellow',
|
||||
position: 1,
|
||||
};
|
||||
|
||||
await act(async () => {
|
||||
const res = await result.current.handlePipelineStepAdd(boardColumn);
|
||||
expect(res).toEqual(responseData);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handlePipelineStepDelete successfully', async () => {
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const setCurrentPipeline = useSetRecoilState(currentPipelineState);
|
||||
setCurrentPipeline({ id: currentPipelineId });
|
||||
return usePipelineSteps();
|
||||
},
|
||||
{
|
||||
wrapper: Wrapper,
|
||||
},
|
||||
);
|
||||
|
||||
const boardColumnId = 'columnId';
|
||||
|
||||
await act(async () => {
|
||||
const res = await result.current.handlePipelineStepDelete(boardColumnId);
|
||||
expect(res).toEqual(deleteResponseData);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user