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,190 @@
import { gql } from '@apollo/client';
export const query = gql`
query FindManyPeople(
$filter: PersonFilterInput
$orderBy: PersonOrderByInput
$lastCursor: String
$limit: Float = 30
) {
people(
filter: $filter
orderBy: $orderBy
first: $limit
after: $lastCursor
) {
edges {
node {
id
opportunities {
edges {
node {
id
personId
pointOfContactId
updatedAt
companyId
pipelineStepId
probability
closeDate
amount {
amountMicros
currencyCode
}
id
createdAt
}
}
}
xLink {
label
url
}
id
pointOfContactForOpportunities {
edges {
node {
id
personId
pointOfContactId
updatedAt
companyId
pipelineStepId
probability
closeDate
amount {
amountMicros
currencyCode
}
id
createdAt
}
}
}
createdAt
company {
id
xLink {
label
url
}
linkedinLink {
label
url
}
domainName
annualRecurringRevenue {
amountMicros
currencyCode
}
createdAt
address
updatedAt
name
accountOwnerId
employees
id
idealCustomerProfile
}
city
email
activityTargets {
edges {
node {
id
updatedAt
createdAt
personId
activityId
companyId
id
}
}
}
jobTitle
favorites {
edges {
node {
id
id
companyId
createdAt
personId
position
workspaceMemberId
updatedAt
}
}
}
attachments {
edges {
node {
id
updatedAt
createdAt
name
personId
activityId
companyId
id
authorId
type
fullPath
}
}
}
name {
firstName
lastName
}
phone
linkedinLink {
label
url
}
updatedAt
avatarUrl
companyId
}
cursor
}
pageInfo {
hasNextPage
startCursor
endCursor
}
}
}
`;
export const variables = {
entitiesToSelect: {
limit: 10,
filter: {
and: [
{ and: [{ or: [{ name: { ilike: '%Entity%' } }] }] },
{ not: { id: { in: ['1', '2'] } } },
],
},
orderBy: { name: 'AscNullsLast' },
},
filteredSelectedEntities: {
limit: 60,
filter: {
and: [
{ and: [{ or: [{ name: { ilike: '%Entity%' } }] }] },
{ id: { in: ['1'] } },
],
},
orderBy: { name: 'AscNullsLast' },
},
selectedEntities: {
limit: 60,
filter: { id: { in: ['1'] } },
orderBy: { name: 'AscNullsLast' },
},
};
export const responseData = {
edges: [],
};

View File

@ -0,0 +1,109 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { renderHook } from '@testing-library/react';
import { RecoilRoot, useSetRecoilState } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
import { EntitiesForMultipleEntitySelect } from '@/object-record/relation-picker/types/EntitiesForMultipleEntitySelect';
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
import {
query,
responseData,
variables,
} from '../__mocks__/useFilteredSearchEntityQuery';
import { useFilteredSearchEntityQuery } from '../useFilteredSearchEntityQuery';
const mocks = [
{
request: {
query,
variables: variables.entitiesToSelect,
},
result: jest.fn(() => ({
data: {
people: responseData,
},
})),
},
{
request: {
query,
variables: variables.filteredSelectedEntities,
},
result: jest.fn(() => ({
data: {
people: responseData,
},
})),
},
{
request: {
query,
variables: variables.selectedEntities,
},
result: jest.fn(() => ({
data: {
people: responseData,
},
})),
},
];
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>
<MockedProvider mocks={mocks} addTypename={false}>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
{children}
</SnackBarProviderScope>
</MockedProvider>
</RecoilRoot>
);
describe('useFilteredSearchEntityQuery', () => {
it('returns the correct result when everything is provided', async () => {
const { result } = renderHook(
() => {
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
setCurrentWorkspace({
id: '32219445-f587-4c40-b2b1-6d3205ed96da',
displayName: 'cool-workspace',
allowImpersonation: false,
subscriptionStatus: 'incomplete',
});
const mockObjectMetadataItems = getObjectMetadataItemsMock();
const setMetadataItems = useSetRecoilState(objectMetadataItemsState);
setMetadataItems(mockObjectMetadataItems);
return useFilteredSearchEntityQuery({
orderByField: 'name',
filters: [{ fieldNames: ['name'], filter: 'Entity' }],
sortOrder: 'AscNullsLast',
selectedIds: ['1'],
mappingFunction: (entity): any => ({
value: entity.id,
label: entity.name,
}),
limit: 10,
excludeEntityIds: ['2'],
objectNameSingular: 'person',
});
},
{ wrapper: Wrapper },
);
const expectedResult: EntitiesForMultipleEntitySelect<any> = {
selectedEntities: [],
filteredSelectedEntities: [],
entitiesToSelect: [],
loading: true,
};
expect(result.current).toEqual(expectedResult);
});
});