File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -230,4 +230,51 @@ describe('connectMenu', () => {
230230 } ,
231231 ] ) ;
232232 } ) ;
233+
234+ it ( 'provides the correct `currentRefinement` value' , ( ) => {
235+ const widget = makeWidget ( { attributeName : 'category' } ) ;
236+
237+ const helper = algoliasearchHelper ( fakeClient , '' , widget . getConfiguration ( { } ) ) ;
238+ helper . search = jest . fn ( ) ;
239+
240+ helper . toggleRefinement ( 'category' , 'Decoration' ) ;
241+
242+ widget . init ( {
243+ helper,
244+ state : helper . state ,
245+ createURL : ( ) => '#' ,
246+ onHistoryChange : ( ) => { } ,
247+ } ) ;
248+
249+ expect ( rendering . lastCall . args [ 0 ] . currentRefinement ) . toBe ( null ) ;
250+
251+ widget . render ( {
252+ results : new SearchResults ( helper . state , [ {
253+ hits : [ ] ,
254+ facets : {
255+ category : {
256+ Decoration : 880 ,
257+ } ,
258+ } ,
259+ } , {
260+ facets : {
261+ category : {
262+ Decoration : 880 ,
263+ Outdoor : 47 ,
264+ } ,
265+ } ,
266+ } ] ) ,
267+ state : helper . state ,
268+ helper,
269+ createURL : ( ) => '#' ,
270+ } ) ;
271+
272+ expect ( rendering . lastCall . args [ 0 ] . currentRefinement ) . toEqual ( {
273+ name : 'Decoration' ,
274+ path : 'Decoration' ,
275+ count : 880 ,
276+ isRefined : true ,
277+ data : null ,
278+ } ) ;
279+ } ) ;
233280} ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ var customMenu = connectMenu(function render(params, isFirstRendering) {
1111 // instantSearchInstance,
1212 // canRefine,
1313 // widgetParams,
14+ // currentRefinement,
1415 // }
1516});
1617search.addWidget(
@@ -39,6 +40,7 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
3940 * @property {boolean } canRefine true if refinement can be applied
4041 * @property {Object } widgetParams all original options forwarded to rendering
4142 * @property {InstantSearch } instantSearchInstance the instance of instantsearch on which the widget is attached
43+ * @property {Object } currentRefinement the refinement currently applied
4244 */
4345
4446 /**
@@ -92,6 +94,7 @@ export default function connectMenu(renderFn) {
9294 instantSearchInstance,
9395 canRefine : false ,
9496 widgetParams,
97+ currentRefinement : null ,
9598 } , true ) ;
9699 } ,
97100
@@ -105,6 +108,7 @@ export default function connectMenu(renderFn) {
105108 instantSearchInstance,
106109 canRefine : items . length > 0 ,
107110 widgetParams,
111+ currentRefinement : items . find ( ( { isRefined} ) => isRefined ) ,
108112 } , false ) ;
109113 } ,
110114 } ;
You can’t perform that action at this time.
0 commit comments