diff --git a/packages/twenty-front/src/loading/components/__stories__/PrefetchLoading.stories.tsx b/packages/twenty-front/src/loading/components/__stories__/PrefetchLoading.stories.tsx index ff0c14876..41a135516 100644 --- a/packages/twenty-front/src/loading/components/__stories__/PrefetchLoading.stories.tsx +++ b/packages/twenty-front/src/loading/components/__stories__/PrefetchLoading.stories.tsx @@ -6,6 +6,7 @@ import { PageDecorator, PageDecoratorArgs, } from '~/testing/decorators/PageDecorator'; +import { PrefetchLoadingDecorator } from '~/testing/decorators/PrefetchLoadingDecorator'; import { graphqlMocks } from '~/testing/graphqlMocks'; const meta: Meta = { @@ -19,6 +20,7 @@ const meta: Meta = { }, parameters: { msw: graphqlMocks, + prefetchLoadingSetDelay: 1000, }, }; @@ -29,7 +31,7 @@ export type Story = StoryObj; export const Default: Story = { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - decorators: [PageDecorator], + decorators: [PrefetchLoadingDecorator, PageDecorator], play: async ({ canvasElement }) => { const canvas = within(canvasElement); diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RichTextFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RichTextFieldInput.stories.tsx index d61e1e3b7..528b111ed 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RichTextFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RichTextFieldInput.stories.tsx @@ -123,8 +123,8 @@ export const ClickOutside: Story = { const canvas = within(canvasElement); expect(clickOutsideJestFn).toHaveBeenCalledTimes(0); - await waitFor(() => { - const outsideElement = canvas.getByTestId('click-outside-element'); + await waitFor(async () => { + const outsideElement = await canvas.findByTestId('click-outside-element'); userEvent.click(outsideElement); expect(clickOutsideJestFn).toHaveBeenCalledTimes(1); }); diff --git a/packages/twenty-front/src/testing/decorators/PrefetchLoadingDecorator.tsx b/packages/twenty-front/src/testing/decorators/PrefetchLoadingDecorator.tsx index 76f87a691..5e1ba010a 100644 --- a/packages/twenty-front/src/testing/decorators/PrefetchLoadingDecorator.tsx +++ b/packages/twenty-front/src/testing/decorators/PrefetchLoadingDecorator.tsx @@ -3,13 +3,40 @@ import { useSetRecoilState } from 'recoil'; import { prefetchIsLoadedFamilyState } from '@/prefetch/states/prefetchIsLoadedFamilyState'; import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; +import { useEffect, useState } from 'react'; -export const PrefetchLoadingDecorator: Decorator = (Story) => { - const setAreFavoritesPrefetched = useSetRecoilState( +export const PrefetchLoadingDecorator: Decorator = (Story, context) => { + const { parameters } = context; + + const prefetchLoadingSetDelay = parameters.prefetchLoadingSetDelay ?? 0; + + const setAreFavoritesFoldersPrefetched = useSetRecoilState( prefetchIsLoadedFamilyState(PrefetchKey.AllFavoritesFolders), ); - setAreFavoritesPrefetched(false); + const setAreFavoritesPrefetched = useSetRecoilState( + prefetchIsLoadedFamilyState(PrefetchKey.AllFavorites), + ); + + const [isInitialized, setIsInitialized] = useState(false); + + useEffect(() => { + if (isInitialized) { + return; + } + + setIsInitialized(true); + + setTimeout(() => { + setAreFavoritesPrefetched(false); + setAreFavoritesFoldersPrefetched(false); + }, prefetchLoadingSetDelay); + }, [ + isInitialized, + prefetchLoadingSetDelay, + setAreFavoritesFoldersPrefetched, + setAreFavoritesPrefetched, + ]); return ; };