Skip to content

Commit

Permalink
Merge branch 'feat/instantsearch.js/connectors' of github.com:algolia…
Browse files Browse the repository at this point in the history
…/instantsearch.js into feat/instantsearch.js/connectors
  • Loading branch information
Alexandre Stanislawski committed Mar 24, 2017
2 parents 75243b0 + d832e5f commit e480dce
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/components/InfiniteHits.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ InfiniteHits.propTypes = {
}),
hits: React.PropTypes.array,
results: React.PropTypes.object,
showMore: React.PropTypes.function,
showMore: React.PropTypes.func,
showMoreLabel: React.PropTypes.string,
templateProps: React.PropTypes.object.isRequired,
isLastPage: React.PropTypes.bool.isRequired,
Expand Down
87 changes: 56 additions & 31 deletions src/components/RefinementList/__tests__/RefinementList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import sinon from 'sinon';
import {RawRefinementList as RefinementList} from '../RefinementList';
import RefinementListItem from '../RefinementListItem';

const defaultProps = {
templateProps: {},
toggleRefinement: () => {},
};

describe('RefinementList', () => {
let createURL;

function shallowRender(extraProps = {}) {
createURL = sinon.spy();
const props = {
...defaultProps,
createURL,
facetValues: [],
...extraProps,
Expand All @@ -22,6 +28,7 @@ describe('RefinementList', () => {
it('should add the `list` class to the root element', () => {
// Given
const props = {
...defaultProps,
cssClasses: {
list: 'list',
},
Expand All @@ -37,6 +44,7 @@ describe('RefinementList', () => {
it('should set item classes to the refinements', () => {
// Given
const props = {
...defaultProps,
cssClasses: {
item: 'item',
},
Expand All @@ -55,6 +63,7 @@ describe('RefinementList', () => {
it('should set active classes to the active refinements', () => {
// Given
const props = {
...defaultProps,
cssClasses: {
active: 'active',
},
Expand All @@ -78,6 +87,7 @@ describe('RefinementList', () => {
it('should have the correct names', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
Expand All @@ -97,7 +107,8 @@ describe('RefinementList', () => {
it('understands attributeNameKey', () => {
// Given
const props = {
facetValues: [{name: 'no', youpiName: 'hello'}],
...defaultProps,
facetValues: [{name: 'no', youpiName: 'hello', isRefined: false}],
attributeNameKey: 'youpiName',
};

Expand All @@ -114,6 +125,7 @@ describe('RefinementList', () => {
it('should correctly set if refined or not', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: true},
Expand All @@ -135,9 +147,10 @@ describe('RefinementList', () => {
it('should pass the count to the templateData', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo', count: 42},
{name: 'bar', count: 16},
{name: 'foo', count: 42, isRefined: false},
{name: 'bar', count: 16, isRefined: false},
],
};

Expand All @@ -156,10 +169,11 @@ describe('RefinementList', () => {
it('displays a number of items equal to the limit when showMore: false', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: false,
limitMin: 2,
Expand All @@ -175,10 +189,11 @@ describe('RefinementList', () => {
it('displays a number of items equal to the limit when showMore: true but not enabled', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: true,
limitMin: 2,
Expand All @@ -195,10 +210,11 @@ describe('RefinementList', () => {
it('displays a number of items equal to the showMore limit when showMore: true and enabled', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
limitMin: 2,
limitMax: 3,
Expand All @@ -217,10 +233,11 @@ describe('RefinementList', () => {
it('adds a showMore link when the feature is enabled', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: true,
limitMin: 2,
Expand All @@ -238,10 +255,11 @@ describe('RefinementList', () => {
it('does not add a showMore link when the feature is disabled', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: false,
limitMin: 2,
Expand All @@ -259,10 +277,11 @@ describe('RefinementList', () => {
it('no showMore when: state = open -> values change -> values <= limitMin ', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: true,
limitMin: 2,
Expand All @@ -281,10 +300,11 @@ describe('RefinementList', () => {
it('does not add a showMore link when the facet values length is equal to the minLimit', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
showMore: true,
limitMin: 3,
Expand All @@ -302,10 +322,11 @@ describe('RefinementList', () => {
it('changing the state will toggle the number of items displayed', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{name: 'foo'},
{name: 'bar'},
{name: 'baz'},
{name: 'foo', isRefined: false},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
limitMin: 2,
limitMax: 3,
Expand All @@ -332,13 +353,15 @@ describe('RefinementList', () => {
it('should create a subList with the sub values', () => {
// Given
const props = {
...defaultProps,
facetValues: [
{
name: 'foo',
data: [
{name: 'bar'},
{name: 'baz'},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
isRefined: false,
},
],
};
Expand All @@ -358,16 +381,18 @@ describe('RefinementList', () => {
it('should add depth class for each depth', () => {
// Given
const props = {
...defaultProps,
cssClasses: {
depth: 'depth-',
},
facetValues: [
{
name: 'foo',
data: [
{name: 'bar'},
{name: 'baz'},
{name: 'bar', isRefined: false},
{name: 'baz', isRefined: false},
],
isRefined: false,
},
],
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/Slider/__tests__/Slider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Slider', () => {
props = {
range: {min: 0, max: 5000},
format: {to: () => {}, from: () => {}},
start: [0, 0],
};
});

Expand All @@ -39,6 +40,7 @@ describe('Slider', () => {
values: [0, 50, 100],
}}
range={props.range}
start={ props.start }
/>
);
});
Expand All @@ -61,6 +63,7 @@ describe('Slider', () => {
values: [0, 50, 100],
} }
range={ {min: props.range.min, max: props.range.min + 0.0001} }
start={ props.start }
disabled
/>
);
Expand Down
4 changes: 2 additions & 2 deletions src/connectors/infinite-hits/connectInfiniteHits.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
export default function connectInfiniteHits(renderFn) {
checkRendering(renderFn, usage);

return widgetParams => {
const {hitsPerPage = 20} = widgetParams || {};
return (widgetParams = {}) => {
const {hitsPerPage = 20} = widgetParams;
let hitsCache = [];
const getShowMore = helper => () => helper.nextPage().search();

Expand Down

0 comments on commit e480dce

Please sign in to comment.