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

Commit

Permalink
fix: track all index in the manager (#660)
Browse files Browse the repository at this point in the history
* fix(createInstantSearchManager): track all index

* feat(IndexStories): add story for SortBy nested in Index
  • Loading branch information
samouss authored Dec 1, 2017
1 parent 16d5b91 commit 793502b
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,82 @@ describe('createInstantSearchManager', () => {
});
});
});

it('updates the store and searches with duplicate Index & SortBy', () => {
// <InstantSearch indexName="first">
// <SearchBox defaultRefinement="query" />
//
// <Index indexName="first">
// <SortBy defaultRefinement="third" />
// </Index>
//
// <Index indexName="second" />
// </InstantSearch>;

const ism = createInstantSearchManager({
indexName: 'first',
initialState: {},
searchParameters: {},
algoliaClient: client,
});

// <SearchBox defaultRefinement="query" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('query'),
context: {},
props: {},
});

// <Index indexName="first" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('first'),
context: {},
props: {
indexName: 'first',
},
});

// <Index indexName="first">
// <SortBy defaultRefinement="third" />
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('third'),
context: { multiIndexContext: { targetedIndex: 'first' } },
props: {},
});

// <Index indexName="second" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('second'),
context: {},
props: {
indexName: 'second',
},
});

expect(ism.store.getState().results).toBe(null);

ism.widgetsManager.update();

return Promise.resolve().then(() => {
jest.runAllTimers();

expect(ism.store.getState().results).toEqual({
first: {
index: 'third',
query: 'query',
page: 0,
},
second: {
index: 'second',
query: 'query',
page: 0,
},
});
});
});
});

describe('on external updates', () => {
it('updates the store and searches', () => {
const ism = createInstantSearchManager({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export default function createInstantSearchManager({
sharedParameters
);

indexMapping[mainIndexParameters.index] = indexName;

return { sharedParameters, mainIndexParameters, derivatedWidgets };
}

Expand Down
42 changes: 42 additions & 0 deletions stories/MultiIndex.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Index,
Highlight,
SearchBox,
SortBy,
} from '../packages/react-instantsearch/dom';
import {
connectHits,
Expand Down Expand Up @@ -62,6 +63,47 @@ stories
<AutoComplete />
</InstantSearch>
))
.add('with SortBy nested in same Index as Root', () => (
<InstantSearch
appId="latency"
apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="categories"
>
<SearchBox />

<div className="multi-index_content">
<div className="multi-index_categories-or-brands">
<Index indexName="categories">
<Configure hitsPerPage={3} />

<SortBy
defaultRefinement="categories"
items={[
{ value: 'categories', label: 'Categories' },
{ value: 'bestbuy', label: 'Best buy' },
]}
/>

<CustomCategoriesOrBrands />
</Index>

<Index indexName="products">
<Configure hitsPerPage={3} />

<SortBy
defaultRefinement="products"
items={[
{ value: 'products', label: 'Products' },
{ value: 'brands', label: 'Brands' },
]}
/>

<CustomCategoriesOrBrands />
</Index>
</div>
</div>
</InstantSearch>
))
.add('with conditional rendering', () => (
<InstantSearch
appId="latency"
Expand Down

0 comments on commit 793502b

Please sign in to comment.