From d5dd0bfe94e8aee8910572380cc82e0cca78dab7 Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:36:54 +0200 Subject: [PATCH] use setupHookTestScenario everywhere --- .../__tests__/useSearchProfiles.spec.ts | 43 ++++++++---------- .../__tests__/useSearchPublications.spec.ts | 44 +++++++------------ 2 files changed, 34 insertions(+), 53 deletions(-) diff --git a/packages/react/src/discovery/__tests__/useSearchProfiles.spec.ts b/packages/react/src/discovery/__tests__/useSearchProfiles.spec.ts index 1369fe7664..28785aef56 100644 --- a/packages/react/src/discovery/__tests__/useSearchProfiles.spec.ts +++ b/packages/react/src/discovery/__tests__/useSearchProfiles.spec.ts @@ -1,30 +1,10 @@ -import { LimitType, Profile } from '@lens-protocol/api-bindings'; -import { - mockLensApolloClient, - mockProfileFragment, - mockSearchProfilesResponse, -} from '@lens-protocol/api-bindings/mocks'; +import { mockProfileFragment, mockSearchProfilesResponse } from '@lens-protocol/api-bindings/mocks'; import { waitFor } from '@testing-library/react'; -import { renderHookWithMocks } from '../../__helpers__/testing-library'; +import { setupHookTestScenario } from '../../__helpers__/setupHookTestScenario'; +import { DEFAULT_PAGINATED_QUERY_LIMIT } from '../../utils'; import { UseSearchProfilesArgs, useSearchProfiles } from '../useSearchProfiles'; -function setupTestScenario({ result, ...args }: UseSearchProfilesArgs & { result: Profile[] }) { - return renderHookWithMocks(() => useSearchProfiles(args), { - mocks: { - apolloClient: mockLensApolloClient([ - mockSearchProfilesResponse({ - variables: { - ...args, - limit: LimitType.Ten, - }, - items: result, - }), - ]), - }, - }); -} - describe(`Given the ${useSearchProfiles.name} hook`, () => { const query = 'query_test'; const profiles = [mockProfileFragment()]; @@ -32,10 +12,23 @@ describe(`Given the ${useSearchProfiles.name} hook`, () => { describe('when the query returns data successfully', () => { it('should return profiles that match the search criteria', async () => { - const { result } = setupTestScenario({ query, result: profiles }); + const { renderHook } = setupHookTestScenario([ + mockSearchProfilesResponse({ + variables: { + query, + limit: DEFAULT_PAGINATED_QUERY_LIMIT, + }, + items: profiles, + }), + ]); - await waitFor(() => expect(result.current.loading).toBeFalsy()); + const args: UseSearchProfilesArgs = { + query, + }; + + const { result } = renderHook(() => useSearchProfiles(args)); + await waitFor(() => expect(result.current.loading).toBeFalsy()); expect(result.current.data).toMatchObject(expectations); }); }); diff --git a/packages/react/src/discovery/__tests__/useSearchPublications.spec.ts b/packages/react/src/discovery/__tests__/useSearchPublications.spec.ts index 01d46e7689..b079847343 100644 --- a/packages/react/src/discovery/__tests__/useSearchPublications.spec.ts +++ b/packages/react/src/discovery/__tests__/useSearchPublications.spec.ts @@ -1,41 +1,18 @@ import { - LimitType, - PrimaryPublication, PublicationMetadataMainFocusType, SearchPublicationType, } from '@lens-protocol/api-bindings'; import { mockCommentFragment, - mockLensApolloClient, mockPostFragment, mockSearchPublicationsResponse, } from '@lens-protocol/api-bindings/mocks'; import { waitFor } from '@testing-library/react'; -import { renderHookWithMocks } from '../../__helpers__/testing-library'; +import { setupHookTestScenario } from '../../__helpers__/setupHookTestScenario'; +import { DEFAULT_PAGINATED_QUERY_LIMIT } from '../../utils'; import { UseSearchPublicationsArgs, useSearchPublications } from '../useSearchPublications'; -function setupTestScenario({ - result, - ...args -}: UseSearchPublicationsArgs & { - result: PrimaryPublication[]; -}) { - return renderHookWithMocks(() => useSearchPublications(args), { - mocks: { - apolloClient: mockLensApolloClient([ - mockSearchPublicationsResponse({ - variables: { - ...args, - limit: LimitType.Ten, - }, - items: result, - }), - ]), - }, - }); -} - describe(`Given the ${useSearchPublications.name} hook`, () => { const query = 'query_test'; const publications = [mockPostFragment(), mockCommentFragment()]; @@ -43,7 +20,7 @@ describe(`Given the ${useSearchPublications.name} hook`, () => { describe('when the query returns data successfully', () => { it('should return publications that match the search result', async () => { - const { result } = setupTestScenario({ + const args: UseSearchPublicationsArgs = { query, where: { publicationTypes: [SearchPublicationType.Post], @@ -51,8 +28,19 @@ describe(`Given the ${useSearchPublications.name} hook`, () => { mainContentFocus: [PublicationMetadataMainFocusType.Audio], }, }, - result: publications, - }); + }; + + const { renderHook } = setupHookTestScenario([ + mockSearchPublicationsResponse({ + variables: { + ...args, + limit: DEFAULT_PAGINATED_QUERY_LIMIT, + }, + items: publications, + }), + ]); + + const { result } = renderHook(() => useSearchPublications(args)); await waitFor(() => expect(result.current.loading).toBeFalsy()); expect(result.current.data).toMatchObject(expectations);