Increase test coverage for /modules/activities/timeline (#4494)

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
gitstart-app[bot] 2024-03-15 16:26:45 +01:00 committed by GitHub
parent 683f1f1f33
commit 14a3fc1ba6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 95 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import styled from '@emotion/styled';
import { useRecoilValue } from 'recoil';
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
import { timelineActivityWithoutTargetsFamilyState } from '@/activities/timeline/states/timelineActivityFirstLevelFamilySelector';
import { timelineActivityWithoutTargetsFamilyState } from '@/activities/timeline/states/timelineActivityWithoutTargetsFamilyState';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { IconCheckbox, IconNotes } from '@/ui/display/icon';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';

View File

@ -7,7 +7,7 @@ import { objectShowPageTargetableObjectState } from '@/activities/timeline/state
import { timelineActivitiesFammilyState } from '@/activities/timeline/states/timelineActivitiesFamilyState';
import { timelineActivitiesForGroupState } from '@/activities/timeline/states/timelineActivitiesForGroupState';
import { timelineActivitiesNetworkingState } from '@/activities/timeline/states/timelineActivitiesNetworkingState';
import { timelineActivityWithoutTargetsFamilyState } from '@/activities/timeline/states/timelineActivityFirstLevelFamilySelector';
import { timelineActivityWithoutTargetsFamilyState } from '@/activities/timeline/states/timelineActivityWithoutTargetsFamilyState';
import { Activity } from '@/activities/types/Activity';
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
import { sortObjectRecordByDateField } from '@/object-record/utils/sortObjectRecordByDateField';

View File

@ -0,0 +1,54 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { act, renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil';
import { useInjectIntoTimelineActivitiesQueries } from '@/activities/timeline/hooks/useInjectIntoTimelineActivitiesQueries';
import { useUpsertFindManyRecordsQueryInCache } from '@/object-record/cache/hooks/useUpsertFindManyRecordsQueryInCache';
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
import { mockedActivities } from '~/testing/mock-data/activities';
const upsertFindManyRecordsQueryInCacheMock = jest.fn();
jest.mock(
'@/object-record/cache/hooks/useUpsertFindManyRecordsQueryInCache',
() => ({
useUpsertFindManyRecordsQueryInCache: jest.fn(),
}),
);
(useUpsertFindManyRecordsQueryInCache as jest.Mock).mockImplementation(() => ({
upsertFindManyRecordsQueryInCache: upsertFindManyRecordsQueryInCacheMock,
}));
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>
<MockedProvider addTypename={false}>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
{children}
</SnackBarProviderScope>
</MockedProvider>
</RecoilRoot>
);
describe('useInjectIntoTimelineActivitiesQueries', () => {
it('works as expected', () => {
const { result } = renderHook(
() => useInjectIntoTimelineActivitiesQueries(),
{ wrapper: Wrapper },
);
act(() => {
result.current.injectIntoTimelineActivitiesQueries({
activityToInject: mockedActivities[0],
activityTargetsToInject: [],
timelineTargetableObject: {
id: '123',
targetObjectNameSingular: 'person',
},
});
});
expect(upsertFindManyRecordsQueryInCacheMock).toHaveBeenCalledTimes(1);
});
});

View File

@ -0,0 +1,38 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil';
import { useTimelineActivities } from '@/activities/timeline/hooks/useTimelineActivities';
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>
<MockedProvider addTypename={false}>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
{children}
</SnackBarProviderScope>
</MockedProvider>
</RecoilRoot>
);
// FIXME: The hook is re-rendering so many times that it's causing a maximum
// update depth exceeded error. We need to fix this before we can write a proper test.
describe('useTimelineActivities', () => {
it('works as expected', () => {
try {
renderHook(
() =>
useTimelineActivities({
targetableObject: {
id: '123',
targetObjectNameSingular: 'person',
},
}),
{ wrapper: Wrapper },
);
} catch (e) {
expect((e as Error).message).toMatch(/^Maximum update depth exceeded/);
}
});
});

View File

@ -5,6 +5,6 @@ export const timelineActivityWithoutTargetsFamilyState = createFamilyState<
Pick<Activity, 'id' | 'title' | 'createdAt' | 'author' | 'type'> | null,
string
>({
key: 'timelineActivityFirstLevelFamilySelector',
key: 'timelineActivityWithoutTargetsFamilyState',
defaultValue: null,
});