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

Commit

Permalink
fix(InstantSearch): update algoliaClient when it change (#70)
Browse files Browse the repository at this point in the history
* fix(core/InstantSearch): update algoliaClient when it change

* fix(InstantSearch.test): add unit test
  • Loading branch information
Mystraht authored and mthuret committed Apr 28, 2017
1 parent 16efd0c commit 9e97dbd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-instantsearch/src/core/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class InstantSearch extends Component {
if (this.props.indexName !== nextProps.indexName) {
this.aisManager.updateIndex(nextProps.indexName);
}

if (this.props.algoliaClient !== nextProps.algoliaClient) {
this.aisManager.updateClient(nextProps.algoliaClient)
}

if (this.isControlled) {
this.aisManager.onExternalStateUpdate(nextProps.searchState);
Expand Down
21 changes: 21 additions & 0 deletions packages/react-instantsearch/src/core/InstantSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ describe('InstantSearch', () => {
});
});

it('updates Algolia client when new one is given in props', () => {
const ism = {
updateClient: jest.fn(),
};

createInstantSearchManager.mockImplementation(() => ism);

const wrapper = mount(
<InstantSearch {...DEFAULT_PROPS}>
<div />
</InstantSearch>
);

expect(ism.updateClient.mock.calls.length).toBe(0);
wrapper.setProps({
...DEFAULT_PROPS,
algoliaClient: {},
});
expect(ism.updateClient.mock.calls.length).toBe(1);
});

it('works as a controlled input', () => {
const ism = {
transitionState: searchState => ({ ...searchState, transitioned: true }),
Expand Down

0 comments on commit 9e97dbd

Please sign in to comment.