@@ -6,182 +6,187 @@ const DEFAULT_CONTEXT = {
66 defaultFacetDistribution : { } ,
77}
88
9- test ( 'adapting a basic searchContext ' , ( ) => {
10- const searchParams = adaptSearchParams ( {
11- ...DEFAULT_CONTEXT ,
12- finitePagination : false ,
9+ describe ( 'Parameters adapter' , ( ) => {
10+ test ( 'adapting a basic searchContext ' , ( ) => {
11+ const searchParams = adaptSearchParams ( {
12+ ...DEFAULT_CONTEXT ,
13+ finitePagination : false ,
14+ } )
15+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
16+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
1317 } )
14- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
15- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
16- } )
17-
18- test ( 'adapting a searchContext with filters, sort and no geo rules ' , ( ) => {
19- const searchParams = adaptSearchParams ( {
20- ...DEFAULT_CONTEXT ,
21- facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
22- sort : 'id < 1' ,
23- finitePagination : false ,
18+ test ( 'adapting a searchContext with filters and sort' , ( ) => {
19+ const searchParams = adaptSearchParams ( {
20+ ...DEFAULT_CONTEXT ,
21+ facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
22+ sort : 'id < 1' ,
23+ finitePagination : false ,
24+ } )
25+
26+ expect ( searchParams . filter ) . toStrictEqual ( [
27+ [ 'genres="Drama"' , 'genres="Thriller"' ] ,
28+ [ 'title="Ariel"' ] ,
29+ ] )
30+ expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
31+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
32+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
2433 } )
25-
26- expect ( searchParams . filter ) . toStrictEqual ( [
27- [ 'genres="Drama"' , 'genres="Thriller"' ] ,
28- [ 'title="Ariel"' ] ,
29- ] )
30- expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
31- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
32- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
3334} )
3435
35- test ( 'adapting a searchContext with filters, sort and geo rules ' , ( ) => {
36- const searchParams = adaptSearchParams ( {
37- ...DEFAULT_CONTEXT ,
38- facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
39- insideBoundingBox : '0,0,0,0' ,
40- sort : 'id < 1' ,
41- finitePagination : false ,
36+ describe ( 'Geo rules adapter' , ( ) => {
37+ test ( 'adapting a searchContext with filters, sort and geo rules ' , ( ) => {
38+ const searchParams = adaptSearchParams ( {
39+ ...DEFAULT_CONTEXT ,
40+ facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
41+ insideBoundingBox : '0,0,0,0' ,
42+ sort : 'id < 1' ,
43+ finitePagination : false ,
44+ } )
45+
46+ expect ( searchParams . filter ) . toStrictEqual ( [
47+ '_geoRadius(0.00000, 0.00000, 0)' ,
48+ [ 'genres="Drama"' , 'genres="Thriller"' ] ,
49+ [ 'title="Ariel"' ] ,
50+ ] )
51+ expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
52+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
53+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
4254 } )
4355
44- expect ( searchParams . filter ) . toStrictEqual ( [
45- '_geoRadius(0.00000, 0.00000, 0)' ,
46- [ 'genres="Drama"' , 'genres="Thriller"' ] ,
47- [ 'title="Ariel"' ] ,
48- ] )
49- expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
50- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
51- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
52- } )
53-
54- test ( 'adapting a searchContext with only facetFilters and geo rules ' , ( ) => {
55- const searchParams = adaptSearchParams ( {
56- ...DEFAULT_CONTEXT ,
57- facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
58- insideBoundingBox : '0,0,0,0' ,
59- finitePagination : false ,
56+ test ( 'adapting a searchContext with only facetFilters and geo rules ' , ( ) => {
57+ const searchParams = adaptSearchParams ( {
58+ ...DEFAULT_CONTEXT ,
59+ facetFilters : [ [ 'genres:Drama' , 'genres:Thriller' ] , [ 'title:Ariel' ] ] ,
60+ insideBoundingBox : '0,0,0,0' ,
61+ finitePagination : false ,
62+ } )
63+
64+ expect ( searchParams . filter ) . toEqual ( [
65+ '_geoRadius(0.00000, 0.00000, 0)' ,
66+ [ 'genres="Drama"' , 'genres="Thriller"' ] ,
67+ [ 'title="Ariel"' ] ,
68+ ] )
69+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
70+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
6071 } )
6172
62- expect ( searchParams . filter ) . toEqual ( [
63- '_geoRadius(0.00000, 0.00000, 0)' ,
64- [ 'genres="Drama"' , 'genres="Thriller"' ] ,
65- [ 'title="Ariel"' ] ,
66- ] )
67- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
68- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
69- } )
70-
71- test ( 'adapting a searchContext with only sort and geo rules ' , ( ) => {
72- const searchParams = adaptSearchParams ( {
73- ...DEFAULT_CONTEXT ,
74- insideBoundingBox : '0,0,0,0' ,
75- sort : 'id < 1' ,
76- finitePagination : false ,
73+ test ( 'adapting a searchContext with only sort and geo rules ' , ( ) => {
74+ const searchParams = adaptSearchParams ( {
75+ ...DEFAULT_CONTEXT ,
76+ insideBoundingBox : '0,0,0,0' ,
77+ sort : 'id < 1' ,
78+ finitePagination : false ,
79+ } )
80+
81+ expect ( searchParams . filter ) . toEqual ( [ '_geoRadius(0.00000, 0.00000, 0)' ] )
82+ expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
83+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
84+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
7785 } )
7886
79- expect ( searchParams . filter ) . toEqual ( [ '_geoRadius(0.00000, 0.00000, 0)' ] )
80- expect ( searchParams . sort ) . toStrictEqual ( [ 'id < 1' ] )
81- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
82- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
83- } )
87+ test ( 'adapting a searchContext with no sort and no filters and geo rules ' , ( ) => {
88+ const searchParams = adaptSearchParams ( {
89+ ...DEFAULT_CONTEXT ,
90+ insideBoundingBox : '0,0,0,0' ,
91+ finitePagination : false ,
92+ } )
8493
85- test ( 'adapting a searchContext with no sort and no filters and geo rules ' , ( ) => {
86- const searchParams = adaptSearchParams ( {
87- ...DEFAULT_CONTEXT ,
88- insideBoundingBox : '0,0,0,0' ,
89- finitePagination : false ,
94+ expect ( searchParams . filter ) . toEqual ( [ '_geoRadius(0.00000, 0.00000, 0)' ] )
95+ expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
96+ expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
9097 } )
91-
92- expect ( searchParams . filter ) . toEqual ( [ '_geoRadius(0.00000, 0.00000, 0)' ] )
93- expect ( searchParams . attributesToHighlight ) . toContain ( '*' )
94- expect ( searchParams . attributesToHighlight ?. length ) . toBe ( 1 )
9598} )
9699
97- test ( 'adapting a searchContext with finite pagination' , ( ) => {
98- const searchParams = adaptSearchParams ( {
99- ...DEFAULT_CONTEXT ,
100- finitePagination : true ,
100+ describe ( 'Pagination adapter' , ( ) => {
101+ test ( 'adapting a searchContext with finite pagination' , ( ) => {
102+ const searchParams = adaptSearchParams ( {
103+ ...DEFAULT_CONTEXT ,
104+ finitePagination : true ,
105+ } )
106+
107+ expect ( searchParams . limit ) . toBe ( 20 )
101108 } )
102109
103- expect ( searchParams . limit ) . toBe ( 20 )
104- } )
110+ test ( 'adapting a searchContext with finite pagination on a later page' , ( ) => {
111+ const searchParams = adaptSearchParams ( {
112+ ...DEFAULT_CONTEXT ,
113+ pagination : { paginationTotalHits : 20 , page : 10 , hitsPerPage : 6 } ,
114+ finitePagination : true ,
115+ } )
105116
106- test ( 'adapting a searchContext with finite pagination on a later page' , ( ) => {
107- const searchParams = adaptSearchParams ( {
108- ...DEFAULT_CONTEXT ,
109- pagination : { paginationTotalHits : 20 , page : 10 , hitsPerPage : 6 } ,
110- finitePagination : true ,
117+ expect ( searchParams . limit ) . toBe ( 20 )
111118 } )
112119
113- expect ( searchParams . limit ) . toBe ( 20 )
114- } )
120+ test ( 'adapting a searchContext with finite pagination and pagination total hits lower than hitsPerPage' , ( ) => {
121+ const searchParams = adaptSearchParams ( {
122+ ...DEFAULT_CONTEXT ,
123+ pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
124+ finitePagination : true ,
125+ } )
115126
116- test ( 'adapting a searchContext with finite pagination and pagination total hits lower than hitsPerPage' , ( ) => {
117- const searchParams = adaptSearchParams ( {
118- ...DEFAULT_CONTEXT ,
119- pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
120- finitePagination : true ,
127+ expect ( searchParams . limit ) . toBe ( 4 )
121128 } )
122129
123- expect ( searchParams . limit ) . toBe ( 4 )
124- } )
130+ test ( 'adapting a searchContext with no finite pagination' , ( ) => {
131+ const searchParams = adaptSearchParams ( {
132+ ...DEFAULT_CONTEXT ,
133+ finitePagination : false ,
134+ } )
125135
126- test ( 'adapting a searchContext with no finite pagination' , ( ) => {
127- const searchParams = adaptSearchParams ( {
128- ...DEFAULT_CONTEXT ,
129- finitePagination : false ,
136+ expect ( searchParams . limit ) . toBe ( 7 )
130137 } )
131138
132- expect ( searchParams . limit ) . toBe ( 7 )
133- } )
139+ test ( 'adapting a searchContext with no finite pagination on page 2' , ( ) => {
140+ const searchParams = adaptSearchParams ( {
141+ ...DEFAULT_CONTEXT ,
142+ pagination : { paginationTotalHits : 20 , page : 1 , hitsPerPage : 6 } ,
143+ finitePagination : false ,
144+ } )
134145
135- test ( 'adapting a searchContext with no finite pagination on page 2' , ( ) => {
136- const searchParams = adaptSearchParams ( {
137- ...DEFAULT_CONTEXT ,
138- pagination : { paginationTotalHits : 20 , page : 1 , hitsPerPage : 6 } ,
139- finitePagination : false ,
146+ expect ( searchParams . limit ) . toBe ( 13 )
140147 } )
141148
142- expect ( searchParams . limit ) . toBe ( 13 )
143- } )
149+ test ( 'adapting a searchContext with no finite pagination on page higher than paginationTotalHits' , ( ) => {
150+ const searchParams = adaptSearchParams ( {
151+ ...DEFAULT_CONTEXT ,
152+ pagination : { paginationTotalHits : 20 , page : 40 , hitsPerPage : 6 } ,
153+ finitePagination : false ,
154+ } )
144155
145- test ( 'adapting a searchContext with no finite pagination on page higher than paginationTotalHits' , ( ) => {
146- const searchParams = adaptSearchParams ( {
147- ...DEFAULT_CONTEXT ,
148- pagination : { paginationTotalHits : 20 , page : 40 , hitsPerPage : 6 } ,
149- finitePagination : false ,
156+ expect ( searchParams . limit ) . toBe ( 20 )
150157 } )
151158
152- expect ( searchParams . limit ) . toBe ( 20 )
153- } )
159+ test ( 'adapting a searchContext with no finite pagination and pagination total hits lower than hitsPerPage' , ( ) => {
160+ const searchParams = adaptSearchParams ( {
161+ ...DEFAULT_CONTEXT ,
162+ pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
163+ finitePagination : false ,
164+ } )
154165
155- test ( 'adapting a searchContext with no finite pagination and pagination total hits lower than hitsPerPage' , ( ) => {
156- const searchParams = adaptSearchParams ( {
157- ...DEFAULT_CONTEXT ,
158- pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
159- finitePagination : false ,
166+ expect ( searchParams . limit ) . toBe ( 4 )
160167 } )
161168
162- expect ( searchParams . limit ) . toBe ( 4 )
163- } )
169+ test ( 'adapting a searchContext placeholderSearch set to false' , ( ) => {
170+ const searchParams = adaptSearchParams ( {
171+ ...DEFAULT_CONTEXT ,
172+ query : '' ,
173+ pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
174+ finitePagination : false ,
175+ placeholderSearch : false ,
176+ } )
164177
165- test ( 'adapting a searchContext placeholderSearch set to false' , ( ) => {
166- const searchParams = adaptSearchParams ( {
167- ...DEFAULT_CONTEXT ,
168- query : '' ,
169- pagination : { paginationTotalHits : 4 , page : 0 , hitsPerPage : 6 } ,
170- finitePagination : false ,
171- placeholderSearch : false ,
178+ expect ( searchParams . limit ) . toBe ( 0 )
172179 } )
173180
174- expect ( searchParams . limit ) . toBe ( 0 )
175- } )
181+ test ( 'adapting a searchContext placeholderSearch set to false' , ( ) => {
182+ const searchParams = adaptSearchParams ( {
183+ ...DEFAULT_CONTEXT ,
184+ query : '' ,
185+ pagination : { paginationTotalHits : 200 , page : 0 , hitsPerPage : 6 } ,
186+ finitePagination : false ,
187+ placeholderSearch : true ,
188+ } )
176189
177- test ( 'adapting a searchContext placeholderSearch set to false' , ( ) => {
178- const searchParams = adaptSearchParams ( {
179- ...DEFAULT_CONTEXT ,
180- query : '' ,
181- pagination : { paginationTotalHits : 200 , page : 0 , hitsPerPage : 6 } ,
182- finitePagination : false ,
183- placeholderSearch : true ,
190+ expect ( searchParams . limit ) . toBe ( 7 )
184191 } )
185-
186- expect ( searchParams . limit ) . toBe ( 7 )
187192} )
0 commit comments