diff --git a/src/components/__tests__/refinement-list.js b/src/components/__tests__/refinement-list.js index a377fa12a..3b80325e3 100644 --- a/src/components/__tests__/refinement-list.js +++ b/src/components/__tests__/refinement-list.js @@ -32,7 +32,7 @@ test('renders proper HTML', () => { expect(vm.$el.outerHTML).toMatchSnapshot(); }); -test('should add a facet to the store when mounted', () => { +test('should add a facet to the store when created', () => { const Component = Vue.extend(RefinementList); const addFacetMock = jest.fn(); const store = Object.assign({}, searchStore, { addFacet: addFacetMock }); diff --git a/src/store.js b/src/store.js index 19024e862..ea3629584 100644 --- a/src/store.js +++ b/src/store.js @@ -200,7 +200,9 @@ export class Store { } addFacet(attribute, type = FACET_AND) { - assertValidFacetType(type); + if (this.hasFacet(attribute, type)) { + return; + } this.stop(); @@ -244,6 +246,21 @@ export class Store { this._helper.setState(state); } + hasFacet(attribute, type = FACET_AND) { + assertValidFacetType(type); + + switch (type) { + case FACET_AND: + return this._helper.state.isConjunctiveFacet(attribute); + case FACET_OR: + return this._helper.state.isDisjunctiveFacet(attribute); + case FACET_TREE: + return this._helper.state.isHierarchicalFacet(attribute); + default: + throw new TypeError(`${type} could not be handled.`); + } + } + addFacetRefinement(attribute, value) { if (this._helper.state.isConjunctiveFacet(attribute)) { this._helper.addFacetRefinement(attribute, value);