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

Commit

Permalink
fix(createInstantSearchManager): fix multi-index search (#2570)
Browse files Browse the repository at this point in the history
* fix(createInstantSearchManager): fix multi-index search

* Fix tests

* Update bundlesize

* Map indexName prop to indexId when indexId is not defined

* Add tests

* Pass indexName through variable for clarity

* Simplify test

* Simplify other tests
  • Loading branch information
yannickcr authored and samouss committed Jun 25, 2019
1 parent e7573d4 commit ba8eefc
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 60 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
},
{
"path": "packages/react-instantsearch/dist/umd/Connectors.min.js",
"maxSize": "41.75 kB"
"maxSize": "41.80 kB"
},
{
"path": "packages/react-instantsearch/dist/umd/Dom.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ describe('createInstantSearchManager with multi index', () => {
// <SearchBox defaultRefinement="first query 1" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('first query 1'),
context: {},
props: {},
});

// <Index indexName="first" indexId="first" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first',
Expand All @@ -66,18 +64,16 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setPage(3),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first',
},
},
props: {},
});

// <Index indexName="second" indexId="second" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('second'),
context: {},
props: {
indexName: 'second',
indexId: 'second',
Expand All @@ -89,12 +85,11 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('second query 1'),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'second',
},
},
props: {},
});

expect(ism.store.getState().results).toBe(null);
Expand Down Expand Up @@ -171,14 +166,12 @@ describe('createInstantSearchManager with multi index', () => {
// <SearchBox defaultRefinement="query" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('query'),
context: {},
props: {},
});

// <Index indexName="first" indexId="first" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first',
Expand All @@ -190,18 +183,16 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('third'),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first',
},
},
props: {},
});

// <Index indexName="second" indexId="second" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('second'),
context: {},
props: {
indexName: 'second',
indexId: 'second',
Expand Down Expand Up @@ -249,7 +240,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="first" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first',
Expand All @@ -259,7 +249,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="second" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('second'),
context: {},
props: {
indexName: 'second',
indexId: 'second',
Expand All @@ -269,7 +258,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="third" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('third'),
context: {},
props: {
indexName: 'third',
indexId: 'third',
Expand All @@ -279,7 +267,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="four" />
ism.widgetsManager.registerWidget({
getSearchParameters: x => x.setIndex('four'),
context: {},
props: {
indexName: 'four',
indexId: 'four',
Expand Down Expand Up @@ -327,7 +314,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="first" indexId="first_5_hits" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first_5_hits',
Expand All @@ -339,18 +325,16 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQueryParameter('hitsPerPage', 5),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first_5_hits',
},
},
props: {},
});

// <Index indexName="first" indexId="first_10_hits" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first_10_hits',
Expand All @@ -363,12 +347,11 @@ describe('createInstantSearchManager with multi index', () => {
ism.widgetsManager.registerWidget({
getSearchParameters: params =>
params.setQueryParameter('hitsPerPage', 10),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first_10_hits',
},
},
props: {},
});

expect(ism.store.getState().results).toBe(null);
Expand Down Expand Up @@ -415,14 +398,12 @@ describe('createInstantSearchManager with multi index', () => {
// <SearchBox defaultRefinement="first query 1" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('first query 1'),
context: {},
props: {},
});

// <Index indexName="first" indexId="first" />
const unregisterFirstIndexWidget = ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first',
Expand All @@ -434,18 +415,16 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
const unregisterPaginationWidget = ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setPage(3),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first',
},
},
props: {},
});

// <Index indexName="second" indexId="second" />
const unregisterSecondIndexWidget = ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('second'),
context: {},
props: {
indexName: 'second',
indexId: 'second',
Expand All @@ -457,12 +436,11 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
const unregisterSecondSearchBoxWidget = ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('second query 1'),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'second',
},
},
props: {},
});

expect(ism.store.getState().results).toBe(null);
Expand Down Expand Up @@ -506,7 +484,6 @@ describe('createInstantSearchManager with multi index', () => {
// <Index indexName="first" indexId="first" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('first'),
context: {},
props: {
indexName: 'first',
indexId: 'first',
Expand All @@ -518,18 +495,16 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setPage(3),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'first',
},
},
props: {},
});

// <Index indexName="second" indexId="second" />
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setIndex('second'),
context: {},
props: {
indexName: 'second',
indexId: 'second',
Expand All @@ -541,12 +516,11 @@ describe('createInstantSearchManager with multi index', () => {
// </Index>
ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('second query 2'),
context: {
multiIndexContext: {
props: {
indexContextValue: {
targetedIndex: 'second',
},
},
props: {},
});

await runAllMicroTasks();
Expand Down
Loading

0 comments on commit ba8eefc

Please sign in to comment.