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:
gitstart-twenty
2024-01-12 18:05:56 +01:00
committed by GitHub
parent 284fabf17c
commit d05d7ec1d1
10 changed files with 830 additions and 1 deletions

View File

@ -0,0 +1,124 @@
import { gql } from '@apollo/client';
export const query = gql`
mutation CreatePeople($data: [PersonCreateInput!]!) {
createPeople(data: $data) {
id
opportunities {
edges {
node {
id
}
}
}
xLink {
label
url
}
id
pointOfContactForOpportunities {
edges {
node {
id
}
}
}
createdAt
company {
id
}
city
email
activityTargets {
edges {
node {
id
}
}
}
jobTitle
favorites {
edges {
node {
id
}
}
}
attachments {
edges {
node {
id
}
}
}
name {
firstName
lastName
}
phone
linkedinLink {
label
url
}
updatedAt
avatarUrl
companyId
}
}
`;
export const personId = 'cb2e9f4b-20c3-4759-9315-4ffeecfaf71a';
export const variables = {
data: [
{
id: personId,
name: { firstName: 'Sheldon', lastName: ' Cooper' },
email: undefined,
jobTitle: undefined,
phone: undefined,
city: undefined,
},
],
};
export const responseData = [
{
opportunities: {
edges: [],
},
xLink: {
label: '',
url: '',
},
pointOfContactForOpportunities: {
edges: [],
},
createdAt: '',
company: {
id: '',
},
city: '',
email: '',
activityTargets: {
edges: [],
},
jobTitle: '',
favorites: {
edges: [],
},
attachments: {
edges: [],
},
name: variables.data[0].name,
phone: '',
linkedinLink: {
label: '',
url: '',
},
updatedAt: '',
avatarUrl: '',
companyId: '',
id: personId,
},
];

View File

@ -0,0 +1,107 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { act, renderHook, waitFor } from '@testing-library/react';
import { RecoilRoot, useRecoilValue } from 'recoil';
import { spreadsheetImportState } from '@/spreadsheet-import/states/spreadsheetImportState';
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
import {
personId,
query,
responseData,
variables,
} from '../__mocks__/useSpreadsheetPersonImport';
import { useSpreadsheetPersonImport } from '../useSpreadsheetPersonImport';
jest.mock('uuid', () => ({
v4: jest.fn(() => personId),
}));
const mocks = [
{
request: {
query,
variables,
},
result: jest.fn(() => ({
data: {
createPeople: responseData,
},
})),
},
];
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>
<MockedProvider mocks={mocks} addTypename={false}>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
{children}
</SnackBarProviderScope>
</MockedProvider>
</RecoilRoot>
);
const fakeCsv = () => {
const csvContent = 'firstname, lastname\nSheldon, Cooper';
const blob = new Blob([csvContent], { type: 'text/csv' });
return new File([blob], 'fakeData.csv', { type: 'text/csv' });
};
describe('useSpreadsheetPersonImport', () => {
it('should work as expected', async () => {
const { result } = renderHook(
() => {
const spreadsheetImport = useRecoilValue(spreadsheetImportState);
const { openPersonSpreadsheetImport } = useSpreadsheetPersonImport();
return { openPersonSpreadsheetImport, spreadsheetImport };
},
{
wrapper: Wrapper,
},
);
const { spreadsheetImport, openPersonSpreadsheetImport } = result.current;
expect(spreadsheetImport.isOpen).toBe(false);
expect(spreadsheetImport.options).toBeNull();
await act(async () => {
openPersonSpreadsheetImport();
});
const { spreadsheetImport: updatedImport } = result.current;
expect(updatedImport.isOpen).toBe(true);
expect(updatedImport.options).toHaveProperty('onSubmit');
expect(updatedImport.options?.onSubmit).toBeInstanceOf(Function);
expect(updatedImport.options).toHaveProperty('fields');
expect(Array.isArray(updatedImport.options?.fields)).toBe(true);
act(() => {
updatedImport.options?.onSubmit(
{
validData: [
{
firstName: 'Sheldon',
lastName: ' Cooper',
},
],
invalidData: [],
all: [
{
firstName: 'Sheldon',
lastName: ' Cooper',
__index: 'cbc3985f-dde9-46d1-bae2-c124141700ac',
},
],
},
fakeCsv(),
);
});
await waitFor(() => {
expect(mocks[0].result).toHaveBeenCalled();
});
});
});