File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export async function mockContentSearchConfig(): ReturnType<typeof api.getConten
1616 } ;
1717}
1818mockContentSearchConfig . multisearchEndpointUrl = 'http://mock.meilisearch.local/multi-search' ;
19+ mockContentSearchConfig . searchEndpointUrl = 'http://mock.meilisearch.local/indexes/studio/search' ;
1920mockContentSearchConfig . applyMock = ( ) => (
2021 jest . spyOn ( api , 'getContentSearchConfig' ) . mockImplementation ( mockContentSearchConfig )
2122) ;
@@ -102,3 +103,24 @@ mockFetchIndexDocuments.applyMock = () => {
102103 { overwriteRoutes : true } ,
103104 ) ;
104105} ;
106+
107+ /**
108+ * Mock the useGetContentHits
109+ */
110+ export async function mockGetContentHits (
111+ mockResponse : 'noHits' | 'someHits' ,
112+ ) {
113+ fetchMock . post ( mockContentSearchConfig . searchEndpointUrl , ( ) => {
114+ const mockResponseMap = {
115+ noHits : {
116+ hits : [ ] ,
117+ estimatedTotalHits : 0 ,
118+ } ,
119+ someHits : {
120+ hits : [ { usage_key : 'some-key' } , { usage_key : 'other-key' } ] ,
121+ estimatedTotalHits : 2 ,
122+ } ,
123+ } ;
124+ return mockResponseMap [ mockResponse ] ;
125+ } ) ;
126+ }
Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ import { renderHook, waitFor } from '@testing-library/react';
33import fetchMock from 'fetch-mock-jest' ;
44
55import mockResult from './__mocks__/block-types.json' ;
6- import { mockContentSearchConfig } from './api.mock' ;
6+ import { mockContentSearchConfig , mockGetContentHits } from './api.mock' ;
77import {
8- useGetBlockTypes ,
8+ useGetBlockTypes , useGetContentHits ,
99} from './apiHooks' ;
1010
1111mockContentSearchConfig . applyMock ( ) ;
@@ -53,4 +53,17 @@ describe('search manager api hooks', () => {
5353 expect ( result . current . data ) . toEqual ( expectedData ) ;
5454 expect ( fetchMock . calls ( ) . length ) . toEqual ( 1 ) ;
5555 } ) ;
56+
57+ it ( 'useGetContentHits should return hits' , async ( ) => {
58+ mockGetContentHits ( 'someHits' ) ;
59+ const { result } = renderHook ( ( ) => useGetContentHits ( 'filter' ) , { wrapper } ) ;
60+ await waitFor ( ( ) => {
61+ expect ( result . current . isPending ) . toBeFalsy ( ) ;
62+ } ) ;
63+ const expectedData = {
64+ hits : [ { usage_key : 'some-key' } , { usage_key : 'other-key' } ] ,
65+ estimatedTotalHits : 2 ,
66+ } ;
67+ expect ( result . current . data ) . toEqual ( expectedData ) ;
68+ } ) ;
5669} ) ;
You can’t perform that action at this time.
0 commit comments