-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:twentyhq/twenty into fix-re-render-…
…view-groups
- Loading branch information
Showing
40 changed files
with
1,631 additions
and
1,070 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
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
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
96 changes: 0 additions & 96 deletions
96
...ages/twenty-front/src/modules/object-record/hooks/__tests__/useFetchAllRecordIds.test.tsx
This file was deleted.
Oops, something went wrong.
173 changes: 173 additions & 0 deletions
173
...es/twenty-front/src/modules/object-record/hooks/__tests__/useLazyFetchAllRecords.test.tsx
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 |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { act, renderHook, waitFor } from '@testing-library/react'; | ||
import { expect } from '@storybook/test'; | ||
import { useLazyFetchAllRecords } from '@/object-record/hooks/useLazyFetchAllRecords'; | ||
import { MockedResponse } from '@apollo/client/testing'; | ||
import gql from 'graphql-tag'; | ||
import { PERSON_FRAGMENT_WITH_DEPTH_ZERO_RELATIONS } from '@/object-record/hooks/__mocks__/personFragments'; | ||
import { getJestMetadataAndApolloMocksAndActionMenuWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksAndContextStoreWrapper'; | ||
|
||
const defaultResponseData = { | ||
pageInfo: { | ||
hasNextPage: false, | ||
hasPreviousPage: false, | ||
startCursor: '', | ||
endCursor: '', | ||
}, | ||
totalCount: 2, | ||
}; | ||
|
||
const mockPerson = { | ||
__typename: 'Person', | ||
updatedAt: '2021-08-03T19:20:06.000Z', | ||
whatsapp: { | ||
primaryPhoneNumber: '+1', | ||
primaryPhoneCountryCode: '234-567-890', | ||
additionalPhones: [], | ||
}, | ||
linkedinLink: { | ||
primaryLinkUrl: 'https://www.linkedin.com', | ||
primaryLinkLabel: 'linkedin', | ||
secondaryLinks: ['https://www.linkedin.com'], | ||
}, | ||
name: { | ||
firstName: 'firstName', | ||
lastName: 'lastName', | ||
}, | ||
emails: { | ||
primaryEmail: 'email', | ||
additionalEmails: [], | ||
}, | ||
position: 'position', | ||
createdBy: { | ||
source: 'source', | ||
workspaceMemberId: '1', | ||
name: 'name', | ||
}, | ||
avatarUrl: 'avatarUrl', | ||
jobTitle: 'jobTitle', | ||
xLink: { | ||
primaryLinkUrl: 'https://www.linkedin.com', | ||
primaryLinkLabel: 'linkedin', | ||
secondaryLinks: ['https://www.linkedin.com'], | ||
}, | ||
performanceRating: 1, | ||
createdAt: '2021-08-03T19:20:06.000Z', | ||
phones: { | ||
primaryPhoneNumber: '+1', | ||
primaryPhoneCountryCode: '234-567-890', | ||
additionalPhones: [], | ||
}, | ||
id: '123', | ||
city: 'city', | ||
companyId: '1', | ||
intro: 'intro', | ||
deletedAt: null, | ||
workPreference: 'workPreference', | ||
}; | ||
|
||
const mock: MockedResponse = { | ||
request: { | ||
query: gql` | ||
query FindManyPeople( | ||
$filter: PersonFilterInput | ||
$orderBy: [PersonOrderByInput] | ||
$lastCursor: String | ||
$limit: Int | ||
) { | ||
people( | ||
filter: $filter | ||
orderBy: $orderBy | ||
first: $limit | ||
after: $lastCursor | ||
) { | ||
edges { | ||
node { | ||
${PERSON_FRAGMENT_WITH_DEPTH_ZERO_RELATIONS} | ||
} | ||
cursor | ||
} | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
endCursor | ||
} | ||
totalCount | ||
} | ||
} | ||
`, | ||
variables: { | ||
limit: 30, | ||
}, | ||
}, | ||
result: jest.fn(() => ({ | ||
data: { | ||
people: { | ||
...defaultResponseData, | ||
edges: [ | ||
{ | ||
node: mockPerson, | ||
cursor: '1', | ||
}, | ||
{ | ||
node: mockPerson, | ||
cursor: '2', | ||
}, | ||
], | ||
}, | ||
}, | ||
})), | ||
}; | ||
|
||
const Wrapper = getJestMetadataAndApolloMocksAndActionMenuWrapper({ | ||
apolloMocks: [mock], | ||
componentInstanceId: 'recordIndexId', | ||
contextStoreTargetedRecordsRule: { | ||
mode: 'selection', | ||
selectedRecordIds: [], | ||
}, | ||
contextStoreCurrentObjectMetadataNameSingular: 'person', | ||
}); | ||
|
||
describe('useLazyFetchAllRecords', () => { | ||
const objectNameSingular = 'person'; | ||
const objectMetadataItem = generatedMockObjectMetadataItems.find( | ||
(item) => item.nameSingular === objectNameSingular, | ||
); | ||
if (!objectMetadataItem) { | ||
throw new Error('Object metadata item not found'); | ||
} | ||
|
||
it('should handle one single page', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useLazyFetchAllRecords({ | ||
objectNameSingular, | ||
limit: 30, | ||
}), | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
let res: any; | ||
|
||
act(() => { | ||
res = result.current.fetchAllRecords(); | ||
}); | ||
|
||
expect(result.current.isDownloading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isDownloading).toBe(false); | ||
expect(result.current.progress).toEqual({ displayType: 'number' }); | ||
}); | ||
|
||
expect(result.current.progress).toEqual({ displayType: 'number' }); | ||
|
||
const finalResult = await res; | ||
|
||
expect(finalResult).toEqual([mockPerson, mockPerson]); | ||
}); | ||
}); |
Oops, something went wrong.