File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import jsHelper, {
22 SearchResults ,
33 SearchParameters ,
44} from 'algoliasearch-helper' ;
5-
5+ import { createSingleSearchResponse } from '../../../../test/mock/createAPIResponse' ;
66import connectMenu from '../connectMenu' ;
77
88describe ( 'connectMenu' , ( ) => {
@@ -266,6 +266,45 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/menu/js/#co
266266 ) ;
267267 } ) ;
268268
269+ it ( 'returns empty items if the facet is not declared' , ( ) => {
270+ const widget = makeWidget ( {
271+ attribute : 'category' ,
272+ } ) ;
273+
274+ // note that the helper is called with empty search parameters
275+ // which means this can only happen in a stale search situation
276+ // when this widget gets mounted
277+ const helper = jsHelper ( { } , '' , { } ) ;
278+
279+ widget . render ( {
280+ results : new SearchResults ( helper . state , [
281+ createSingleSearchResponse ( {
282+ hits : [ ] ,
283+ facets : {
284+ category : {
285+ Decoration : 880 ,
286+ } ,
287+ } ,
288+ } ) ,
289+ createSingleSearchResponse ( {
290+ facets : {
291+ category : {
292+ Decoration : 880 ,
293+ Outdoor : 47 ,
294+ } ,
295+ } ,
296+ } ) ,
297+ ] ) ,
298+ state : helper . state ,
299+ helper,
300+ } ) ;
301+
302+ expect ( rendering ) . toHaveBeenLastCalledWith (
303+ expect . objectContaining ( { items : [ ] } ) ,
304+ false
305+ ) ;
306+ } ) ;
307+
269308 it ( 'provides the correct transformed facet values' , ( ) => {
270309 const widget = makeWidget ( {
271310 attribute : 'category' ,
Original file line number Diff line number Diff line change @@ -190,8 +190,10 @@ export default function connectMenu(renderFn, unmountFn = noop) {
190190 } ,
191191
192192 render ( { results, instantSearchInstance } ) {
193+ const facetValues = results . getFacetValues ( attribute , { sortBy } ) ;
193194 const facetItems =
194- results . getFacetValues ( attribute , { sortBy } ) . data || [ ] ;
195+ facetValues && facetValues . data ? facetValues . data : [ ] ;
196+
195197 const items = transformItems (
196198 facetItems
197199 . slice ( 0 , this . getLimit ( ) )
You can’t perform that action at this time.
0 commit comments