From 1aab32432e47e7c0107bdde181ec06498c77a5a4 Mon Sep 17 00:00:00 2001 From: Marie-Laure Thuret Date: Mon, 26 Jun 2017 15:04:08 +0200 Subject: [PATCH] fix(MultiIndex): handle if namespace isn't in search state (#139) --- packages/react-instantsearch/src/core/indexUtils.js | 1 + .../react-instantsearch/src/core/indexUtils.test.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-instantsearch/src/core/indexUtils.js b/packages/react-instantsearch/src/core/indexUtils.js index 766cd03537..da34c03250 100644 --- a/packages/react-instantsearch/src/core/indexUtils.js +++ b/packages/react-instantsearch/src/core/indexUtils.js @@ -142,6 +142,7 @@ export function getCurrentRefinementValue( (hasMultipleIndex(context) && searchState.indices && namespace && + searchState.indices[`${index}`] && has(searchState.indices[`${index}`][namespace], `${attributeName}`)) || (hasMultipleIndex(context) && searchState.indices && diff --git a/packages/react-instantsearch/src/core/indexUtils.test.js b/packages/react-instantsearch/src/core/indexUtils.test.js index 2fc28c13d3..12a73fec3c 100644 --- a/packages/react-instantsearch/src/core/indexUtils.test.js +++ b/packages/react-instantsearch/src/core/indexUtils.test.js @@ -357,7 +357,7 @@ describe('utility method for manipulating the search state', () => { }, }; - expect.assertions(6); //async assertions + expect.assertions(7); //async assertions let expectedRefinement = value => expect(value).toEqual('refinement'); @@ -414,6 +414,17 @@ describe('utility method for manipulating the search state', () => { expect(value).toEqual('defaultValue'); + value = getCurrentRefinementValue( + {}, + searchState, + context, + 'anotherNamespace.refinement.top', + 'defaultValue', + () => {} + ); + + expect(value).toEqual('defaultValue'); + value = getCurrentRefinementValue( { defaultRefinement: 'defaultRefinement' }, {},