@@ -58,10 +58,15 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
5858 attribute,
5959 } ) ;
6060
61- const config = widget . getConfiguration ( { } ) ;
62- expect ( config ) . toEqual ( {
63- disjunctiveFacets : [ attribute ] ,
64- } ) ;
61+ const config = widget . getConfiguration ( new SearchParameters ( { } ) ) ;
62+ expect ( config ) . toEqual (
63+ new SearchParameters ( {
64+ disjunctiveFacets : [ attribute ] ,
65+ disjunctiveFacetsRefinements : {
66+ grade : [ ] ,
67+ } ,
68+ } )
69+ ) ;
6570
6671 const helper = jsHelper ( { } , '' , config ) ;
6772 helper . search = jest . fn ( ) ;
@@ -167,7 +172,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
167172 attribute,
168173 } ) ;
169174
170- const config = widget . getConfiguration ( { } ) ;
175+ const config = widget . getConfiguration ( new SearchParameters ( { } ) ) ;
171176
172177 const helper = jsHelper ( { } , '' , config ) ;
173178 helper . search = jest . fn ( ) ;
@@ -261,6 +266,110 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
261266 }
262267 } ) ;
263268
269+ describe ( 'getConfiguration' , ( ) => {
270+ test ( 'returns initial search parameters' , ( ) => {
271+ const rendering = jest . fn ( ) ;
272+ const makeWidget = connectRatingMenu ( rendering ) ;
273+
274+ const attribute = 'grade' ;
275+ const widget = makeWidget ( {
276+ attribute,
277+ } ) ;
278+
279+ expect ( widget . getConfiguration ( new SearchParameters ( { } ) ) ) . toEqual (
280+ new SearchParameters ( {
281+ disjunctiveFacets : [ attribute ] ,
282+ disjunctiveFacetsRefinements : {
283+ grade : [ ] ,
284+ } ,
285+ } )
286+ ) ;
287+ } ) ;
288+
289+ test ( 'supports previous disjunctive facets refinements' , ( ) => {
290+ const rendering = jest . fn ( ) ;
291+ const makeWidget = connectRatingMenu ( rendering ) ;
292+
293+ const attribute = 'grade' ;
294+ const widget = makeWidget ( {
295+ attribute,
296+ } ) ;
297+
298+ expect (
299+ widget . getConfiguration (
300+ new SearchParameters ( {
301+ disjunctiveFacets : [ attribute ] ,
302+ disjunctiveFacetsRefinements : {
303+ grade : [ 4 ] ,
304+ } ,
305+ } )
306+ )
307+ ) . toEqual (
308+ new SearchParameters ( {
309+ disjunctiveFacets : [ attribute ] ,
310+ disjunctiveFacetsRefinements : {
311+ grade : [ 4 ] ,
312+ } ,
313+ } )
314+ ) ;
315+ } ) ;
316+ } ) ;
317+
318+ describe ( 'dispose' , ( ) => {
319+ test ( 'calls the unmount function' , ( ) => {
320+ const render = jest . fn ( ) ;
321+ const unmount = jest . fn ( ) ;
322+ const makeWidget = connectRatingMenu ( render , unmount ) ;
323+ const helper = jsHelper ( { } , '' , { } ) ;
324+ helper . search = jest . fn ( ) ;
325+
326+ const attribute = 'grade' ;
327+ const widget = makeWidget ( {
328+ attribute,
329+ } ) ;
330+
331+ widget . dispose ( { state : helper . state } ) ;
332+
333+ expect ( unmount ) . toHaveBeenCalledTimes ( 1 ) ;
334+ } ) ;
335+
336+ test ( 'resets the state' , ( ) => {
337+ const render = jest . fn ( ) ;
338+ const makeWidget = connectRatingMenu ( render ) ;
339+ const indexName = 'indexName' ;
340+ const attribute = 'grade' ;
341+ const helper = jsHelper ( { } , indexName , {
342+ disjunctiveFacets : [ attribute ] ,
343+ disjunctiveFacetsRefinements : {
344+ [ attribute ] : [ 4 , 5 ] ,
345+ } ,
346+ } ) ;
347+ helper . search = jest . fn ( ) ;
348+
349+ const widget = makeWidget ( {
350+ attribute,
351+ } ) ;
352+
353+ expect ( helper . state ) . toEqual (
354+ new SearchParameters ( {
355+ index : indexName ,
356+ disjunctiveFacets : [ attribute ] ,
357+ disjunctiveFacetsRefinements : {
358+ grade : [ 4 , 5 ] ,
359+ } ,
360+ } )
361+ ) ;
362+
363+ const nextState = widget . dispose ( { state : helper . state } ) ;
364+
365+ expect ( nextState ) . toEqual (
366+ new SearchParameters ( {
367+ index : indexName ,
368+ } )
369+ ) ;
370+ } ) ;
371+ } ) ;
372+
264373 describe ( 'routing' , ( ) => {
265374 const getInitializedWidget = ( config = { } ) => {
266375 const rendering = jest . fn ( ) ;
@@ -272,7 +381,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
272381 ...config ,
273382 } ) ;
274383
275- const initialConfig = widget . getConfiguration ( { } ) ;
384+ const initialConfig = widget . getConfiguration ( new SearchParameters ( { } ) ) ;
276385 const helper = jsHelper ( { } , '' , initialConfig ) ;
277386 helper . search = jest . fn ( ) ;
278387
0 commit comments