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

Commit

Permalink
Fix: Compute canRefine on the transformed items (#1568)
Browse files Browse the repository at this point in the history
* Fix: Compute canRefine on the transformed items

Resolves #1524

* Add tests to connectors for ensuring canRefine is based on transformed items

* style: run Prettier
  • Loading branch information
Lawson Kurtz authored and samouss committed Sep 26, 2018
1 parent e914ff6 commit c95384f
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ describe('connectCurrentRefinements', () => {
{ id: 2, index: 'something', label: 'cadabra' },
]);
});

it('computes canRefine based on the length of the transformed items list', () => {
const transformItems = () => [];
const props = getProvidedProps({ transformItems }, null, null, [
{ items: [{ label: 'one' }], id: 1, index: 'something' },
]);

expect(props.canRefine).toEqual(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,25 @@ describe('connectHierarchicalMenu', () => {
hierarchicalMenu: {},
});
});

it('computes canRefine based on the length of the transformed items list', () => {
const transformItems = () => [];
const results = {
getFacetValues: () => ({ data: [{ id: 'test' }] }),
getFacetByName: () => true,
hits: [],
};

props = getProvidedProps(
{ attributes: ['ok'], transformItems },
{},
{ results }
);

expect(props.canRefine).toEqual(false);
});
});

describe('multi index', () => {
let context = {
context: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,25 @@ describe('connectMenu', () => {
},
]);
});

it('computes canRefine based on the length of the transformed items list', () => {
const transformItems = () => [];
const results = {
getFacetValues: () => [
{ count: 1, id: 'test', isRefined: true, name: 'test' },
],
getFacetByName: () => true,
hits: [],
};

props = getProvidedProps(
{ attribute: 'ok', transformItems },
{},
{ results }
);

expect(props.canRefine).toEqual(false);
});
});
describe('multi index', () => {
let context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ describe('connectNumericMenu', () => {
another: { searchState: 'searchState' },
});
});

it('computes canRefine based on the length of the transformed items list', () => {
const transformItems = () => [];

props = getProvidedProps(
{
items: [{ label: 'Ok', start: 100 }],
transformItems,
},
{},
{ results }
);

expect(props.canRefine).toEqual(false);
});
});
describe('multi index', () => {
let context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ describe('connectRefinementList', () => {
maxFacetHits: 25,
});
});

it('computes canRefine based on the length of the transformed items list', () => {
const transformItems = () => [];

props = getProvidedProps(
{ attribute: 'ok', transformItems },
{},
{ results }
);

expect(props.canRefine).toEqual(false);
});
});

describe('multi index', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ export default createConnector({
return res;
}, []);

const transformedItems = props.transformItems
? props.transformItems(items)
: items;

return {
items: props.transformItems ? props.transformItems(items) : items,
canRefine: items.length > 0,
items: transformedItems,
canRefine: transformedItems.length > 0,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default createConnector({
return {
items: truncate(transformedItems, itemsLimit),
currentRefinement: getCurrentRefinement(props, searchState, this.context),
canRefine: items.length > 0,
canRefine: transformedItems.length > 0,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default createConnector({
currentRefinement: getCurrentRefinement(props, searchState, this.context),
isFromSearch,
searchable,
canRefine: items.length > 0,
canRefine: transformedItems.length > 0,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,16 @@ export default createConnector({
});
}

const transformedItems = props.transformItems
? props.transformItems(items)
: items;

return {
items: props.transformItems ? props.transformItems(items) : items,
items: transformedItems,
currentRefinement,
canRefine:
items.length > 0 && items.some(item => item.noRefinement === false),
transformedItems.length > 0 &&
transformedItems.some(item => item.noRefinement === false),
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default createConnector({
currentRefinement: getCurrentRefinement(props, searchState, this.context),
isFromSearch,
searchable,
canRefine: items.length > 0,
canRefine: transformedItems.length > 0,
};
},

Expand Down

0 comments on commit c95384f

Please sign in to comment.