From 53b63ac27c2275262db9a04be02210a3287aa71d Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 1 Dec 2023 19:34:58 +0100 Subject: refactor(pages): refine Blog pages * replace usePostsList with useArticlesList to keep names coherent * remove useIsMounted hook * rewrite useRedirection hook * add redirect in getStaticProps to avoid unecessary fetching * move Pagination component in a noscript tag * use hooks to refresh thematics and topics lists * complete Cypress tests --- .../hooks/use-posts-list/use-posts-list.test.tsx | 74 ---------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/utils/hooks/use-posts-list/use-posts-list.test.tsx (limited to 'src/utils/hooks/use-posts-list/use-posts-list.test.tsx') diff --git a/src/utils/hooks/use-posts-list/use-posts-list.test.tsx b/src/utils/hooks/use-posts-list/use-posts-list.test.tsx deleted file mode 100644 index f23ddde..0000000 --- a/src/utils/hooks/use-posts-list/use-posts-list.test.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { - afterEach, - beforeEach, - describe, - expect, - it, - jest, -} from '@jest/globals'; -import { act, renderHook } from '@testing-library/react'; -import type { ReactNode } from 'react'; -import { SWRConfig } from 'swr'; -import { fetchPostsList } from '../../../services/graphql'; -import { usePostsList } from './use-posts-list'; - -const wrapper = ({ children }: { children?: ReactNode }) => { - const map = new Map(); - - return ( - map, - isOnline() { - return true; - }, - isVisible() { - return true; - }, - initFocus() { - /* nothing */ - }, - initReconnect() { - /* nothing */ - }, - }} - > - {children} - - ); -}; - -describe('usePostsList', () => { - beforeEach(() => { - /* Not sure why it is needed, but without it Jest was complaining with `You - * are trying to import a file after the Jest environment has been torn - * down`... Maybe because of useSWR? */ - jest.useFakeTimers({ - doNotFake: ['queueMicrotask'], - }); - }); - - afterEach(() => { - jest.runOnlyPendingTimers(); - jest.useRealTimers(); - }); - - it('can return the first new result index when loading more posts', async () => { - const perPage = 5; - const { result } = renderHook( - () => usePostsList({ fetcher: fetchPostsList, perPage }), - { wrapper } - ); - - expect.assertions(2); - - expect(result.current.firstNewResultIndex).toBeUndefined(); - - await act(async () => { - await result.current.loadMore(); - }); - - // Assuming there is more than one page. - expect(result.current.firstNewResultIndex).toBe(perPage + 1); - }); -}); -- cgit v1.2.3