Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(toggle): ensure facet is present (#1613)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored Sep 26, 2018
1 parent 6044273 commit e914ff6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('connectToggleRefinement', () => {
expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without the facet', () => {
it('expect `canRefine` to be `false` without the facet values', () => {
const props = { attribute: 'shipping', value: true };
const searchState = {};
const searchResults = createSingleIndexSearchResults({
Expand All @@ -134,6 +134,19 @@ describe('connectToggleRefinement', () => {
expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without the facet', () => {
const props = { attribute: 'shipping', value: true };
const searchState = {};
const searchResults = createSingleIndexSearchResults({
disjunctiveFacets: [],
facets: {},
});

const actual = getProvidedProps(props, searchState, searchResults);

expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without results', () => {
const props = { attribute: 'shipping', value: true };
const searchState = {};
Expand Down Expand Up @@ -463,7 +476,7 @@ describe('connectToggleRefinement', () => {
expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without the facet', () => {
it('expect `canRefine` to be `false` without the facet values', () => {
const props = { attribute: 'shipping', value: true };
const searchState = createMultiIndexSearchState();
const searchResults = createMultiIndexSearchResults({
Expand All @@ -476,6 +489,19 @@ describe('connectToggleRefinement', () => {
expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without the facet', () => {
const props = { attribute: 'shipping', value: true };
const searchState = createMultiIndexSearchState();
const searchResults = createMultiIndexSearchResults({
disjunctiveFacets: [],
facets: {},
});

const actual = getProvidedProps(props, searchState, searchResults);

expect(actual.canRefine).toBe(false);
});

it('expect `canRefine` to be `false` without results', () => {
const props = { attribute: 'shipping', value: true };
const searchState = createMultiIndexSearchState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export default createConnector({
this.context
);

const allFacetValues = results && results.getFacetValues(attribute);
const allFacetValues =
results && results.getFacetByName(attribute)
? results.getFacetValues(attribute)
: null;

const facetValue =
// Use null to always be consistent with type of the value
// count: number | null
Expand Down

0 comments on commit e914ff6

Please sign in to comment.