File tree Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "comment" : " This is a mock of the response from Meilisearch, based on an actual search in Studio." ,
3
+ "results" : [
4
+ {
5
+ "indexUid" : " studio" ,
6
+ "hits" : [],
7
+ "query" : " " ,
8
+ "processingTimeMs" : 1 ,
9
+ "limit" : 0 ,
10
+ "offset" : 0 ,
11
+ "estimatedTotalHits" : 0 ,
12
+ "facetDistribution" : {
13
+ "block_type" : {
14
+ "chapter" : 1 ,
15
+ "html" : 2 ,
16
+ "problem" : 16 ,
17
+ "vertical" : 2 ,
18
+ "video" : 1
19
+ },
20
+ "content.problem_types" : {
21
+ "choiceresponse" : 2 ,
22
+ "multiplechoiceresponse" : 6 ,
23
+ "numericalresponse" : 3 ,
24
+ "optionresponse" : 4 ,
25
+ "stringresponse" : 1
26
+ }
27
+ },
28
+ "facetStats" : {}
29
+ }
30
+ ]
31
+ }
Original file line number Diff line number Diff line change
1
+ import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
2
+ import { waitFor } from '@testing-library/react' ;
3
+ import { renderHook } from '@testing-library/react-hooks' ;
4
+ import fetchMock from 'fetch-mock-jest' ;
5
+
6
+ import mockResult from './__mocks__/block-types.json' ;
7
+ import { mockContentSearchConfig } from './api.mock' ;
8
+ import {
9
+ useGetBlockTypes ,
10
+ } from './apiHooks' ;
11
+
12
+ mockContentSearchConfig . applyMock ( ) ;
13
+
14
+ const queryClient = new QueryClient ( {
15
+ defaultOptions : {
16
+ queries : {
17
+ retry : false ,
18
+ } ,
19
+ } ,
20
+ } ) ;
21
+
22
+ const wrapper = ( { children } ) => (
23
+ < QueryClientProvider client = { queryClient } >
24
+ { children }
25
+ </ QueryClientProvider >
26
+ ) ;
27
+
28
+ const fetchMockResponse = ( ) => {
29
+ fetchMock . post (
30
+ mockContentSearchConfig . searchEndpointUrl ,
31
+ ( ) => mockResult ,
32
+ { overwriteRoutes : true } ,
33
+ ) ;
34
+ } ;
35
+
36
+ describe ( 'search manager api hooks' , ( ) => {
37
+ afterEach ( ( ) => {
38
+ fetchMock . reset ( ) ;
39
+ } ) ;
40
+
41
+ it ( 'it should return block types facet' , async ( ) => {
42
+ fetchMockResponse ( ) ;
43
+ const { result } = renderHook ( ( ) => useGetBlockTypes ( 'filter' ) , { wrapper } ) ;
44
+ await waitFor ( ( ) => {
45
+ expect ( result . current . isLoading ) . toBeFalsy ( ) ;
46
+ } ) ;
47
+ const expectedData = {
48
+ chapter : 1 ,
49
+ html : 2 ,
50
+ problem : 16 ,
51
+ vertical : 2 ,
52
+ video : 1 ,
53
+ } ;
54
+ expect ( result . current . data ) . toEqual ( expectedData ) ;
55
+ expect ( fetchMock . calls ( ) . length ) . toEqual ( 1 ) ;
56
+ } ) ;
57
+ } ) ;
You can’t perform that action at this time.
0 commit comments