Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CI #6982

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a constant for the search term 'Num' to improve maintainability


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
Loading