Skip to content

Commit

Permalink
Fixed CI (#6982)
Browse files Browse the repository at this point in the history
Fixed CI : 
- Unit test for useTimelineActivities
- Story for field creation with new 2-step process
  • Loading branch information
lucasbordeau authored Sep 11, 2024
1 parent 1317e1c commit b506332
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { renderHook } from '@testing-library/react';

import { useTimelineActivities } from '@/activities/timelineActivities/hooks/useTimelineActivities';
import { ReactNode } from 'react';
import { RecoilRoot } from 'recoil';
import { getJestHookWrapper } from '~/testing/jest/getJestHookWrapper';

jest.mock('@/object-record/hooks/useFindManyRecords', () => ({
useFindManyRecords: jest.fn(),
}));

const Wrappers = getJestHookWrapper({
apolloMocks: [],
});

const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>{children}</RecoilRoot>
<Wrappers>{children}</Wrappers>
);

describe('useTimelineActivities', () => {
Expand Down Expand Up @@ -46,6 +50,7 @@ describe('useTimelineActivities', () => {
updatedAt: '2024-03-22T08:28:44.830Z',
},
];

const mockTargetableObject = {
id: '1',
targetObjectNameSingular: 'Opportunity',
Expand All @@ -54,15 +59,28 @@ describe('useTimelineActivities', () => {
const useFindManyRecordsMock = jest.requireMock(
'@/object-record/hooks/useFindManyRecords',
);

useFindManyRecordsMock.useFindManyRecords.mockReturnValue({
records: mockedTimelineActivities,
});

const { result } = renderHook(
() => useTimelineActivities(mockTargetableObject),
() => {
return useTimelineActivities(mockTargetableObject);
},
{ wrapper: Wrapper },
);

const wrongMockedTimelineActivities = [
{
...mockedTimelineActivities[0],
name: 'wrong.updated.company',
},
];

expect(result.current.timelineActivities).toEqual(mockedTimelineActivities);
expect(result.current.timelineActivities).not.toEqual(
wrongMockedTimelineActivities,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ export const Default: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await canvas.findByText('Objects');
await canvas.findByText('Name and description');
await canvas.findByText('1. Select a field type');

const searchInput = await canvas.findByPlaceholderText('Search a type');

await userEvent.type(searchInput, 'Num');

const numberTypeButton = await canvas.findByText('Number');

await userEvent.click(numberTypeButton);

await canvas.findByText('2. Configure field');

const employeeInput = await canvas.findByPlaceholderText('Employees');
await userEvent.type(employeeInput, 'Test');
Expand All @@ -41,7 +51,6 @@ export const Default: Story = {
);

await userEvent.type(descriptionInput, 'Test description');
await canvas.findByText('Type and values');

const saveButton = await canvas.findByText('Save');

Expand Down
7 changes: 5 additions & 2 deletions packages/twenty-front/src/testing/jest/getJestHookWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ReactNode } from 'react';
import { MockedProvider, MockedResponse } from '@apollo/client/testing';
import { ReactNode } from 'react';
import { MutableSnapshot, RecoilRoot } from 'recoil';

import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
import { JestObjectMetadataItemSetter } from '~/testing/jest/JestObjectMetadataItemSetter';

export const getJestHookWrapper = ({
apolloMocks,
Expand All @@ -17,7 +18,9 @@ export const getJestHookWrapper = ({
<RecoilRoot initializeState={onInitializeRecoilSnapshot}>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<MockedProvider mocks={apolloMocks} addTypename={false}>
{children}
<JestObjectMetadataItemSetter>
{children}
</JestObjectMetadataItemSetter>
</MockedProvider>
</SnackBarProviderScope>
</RecoilRoot>
Expand Down

0 comments on commit b506332

Please sign in to comment.