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

Commit

Permalink
feat(connectStateResults): expose isSearchStalled (#933)
Browse files Browse the repository at this point in the history
* refactor(connectStateResults): dont rely on mutable value

* feat(connectStateResults): expose isSearchStalled through the connector
  • Loading branch information
samouss authored Feb 2, 2018
1 parent 438a28b commit f45ba27
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getResults } from '../core/indexUtils';
* @providedPropType {object} allSearchResults - In case of multiple indices you can retrieve all the results
* @providedPropType {string} error - If the search failed, the error will be logged here.
* @providedPropType {boolean} searching - If there is a search in progress.
* @providedPropType {boolean} isSearchStalled - Flag that indicates if React InstantSearch has detected that searches are stalled.
* @providedPropType {boolean} searchingForFacetValues - If there is a search in a list in progress.
* @providedPropType {object} props - component props.
* @example
Expand Down Expand Up @@ -46,11 +47,13 @@ export default createConnector({

getProvidedProps(props, searchState, searchResults) {
const results = getResults(searchResults, this.context);

return {
searchState,
searchResults: results,
allSearchResults: searchResults.results,
searching: searchResults.searching,
isSearchStalled: searchResults.isSearchStalled,
error: searchResults.error,
searchingForFacetValues: searchResults.searchingForFacetValues,
props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,67 @@
/* eslint-env jest, jasmine */

import connect from './connectStateResults';
jest.mock('../core/createConnector');

let props;
jest.mock('../core/createConnector');

describe('connectStateResults', () => {
describe('single index', () => {
const context = { context: { ais: { mainTargetedIndex: 'index' } } };
const context = {
context: {
ais: { mainTargetedIndex: 'index' },
},
};

const getProvidedProps = connect.getProvidedProps.bind(context);

it('provides the correct props to the component', () => {
const searchState = { state: 'state' };
const error = 'error';
const searching = true;
const isSearchStalled = true;
const searchingForFacetValues = true;
const searchResults = {
results: { nbHits: 25, hits: [] },
error,
searching,
isSearchStalled,
searchingForFacetValues,
};

props = getProvidedProps({ props: 'props' }, searchState, searchResults);
expect(props).toEqual({
const expectation = {
searchState,
searchResults: searchResults.results,
allSearchResults: searchResults.results,
props: { props: 'props' },
error,
searching,
isSearchStalled,
searchingForFacetValues,
props: { props: 'props' },
});
};

const actual = getProvidedProps(
{ props: 'props' },
searchState,
searchResults
);

expect(actual).toEqual(expectation);
});
});

describe('multi index', () => {
const context = {
context: {
ais: { mainTargetedIndex: 'first' },
multiIndexContext: { targetedIndex: 'first' },
},
};

const getProvidedProps = connect.getProvidedProps.bind(context);

it('provides the correct props to the component', () => {
const searchState = { state: 'state' };
const error = 'error';
const searching = true;
const isSearchStalled = true;
const searchingForFacetValues = true;
const searchResults = {
results: {
Expand All @@ -53,19 +70,28 @@ describe('connectStateResults', () => {
},
error,
searching,
isSearchStalled,
searchingForFacetValues,
};

props = getProvidedProps({ props: 'props' }, searchState, searchResults);
expect(props).toEqual({
const expectation = {
searchState,
searchResults: searchResults.results.first,
allSearchResults: searchResults.results,
props: { props: 'props' },
error,
searching,
isSearchStalled,
searchingForFacetValues,
props: { props: 'props' },
});
};

const actual = getProvidedProps(
{ props: 'props' },
searchState,
searchResults
);

expect(actual).toEqual(expectation);
});
});
});

0 comments on commit f45ba27

Please sign in to comment.