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

Commit

Permalink
fix(MultiIndex): ensure getResults return only hits matching index in…
Browse files Browse the repository at this point in the history
… the context (#136)
  • Loading branch information
mthuret authored Jun 26, 2017
1 parent 62cf512 commit 124ffe6
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('connectHierarchicalMenu', () => {
getFacetValues: jest.fn(),
getFacetByName: () => true,
hits: [],
index: 'index',
};

results.getFacetValues.mockImplementationOnce(() => ({}));
Expand Down Expand Up @@ -334,6 +335,7 @@ describe('connectHierarchicalMenu', () => {
first: {
getFacetValues: jest.fn(),
getFacetByName: () => true,
index: 'first',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('connectHits', () => {
it('provides the current hits to the component', () => {
const hits = [{}];
const props = getProvidedProps(null, null, {
results: { hits },
results: { hits, index: 'index' },
});
expect(props).toEqual({ hits });
});
Expand All @@ -38,7 +38,7 @@ describe('connectHits', () => {
it('provides the current hits to the component', () => {
const hits = [{}];
const props = getProvidedProps(null, null, {
results: { second: { hits } },
results: { second: { hits, index: 'second' } },
});
expect(props).toEqual({ hits });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('connectInfiniteHits', () => {
it('provides the current hits to the component', () => {
const hits = [{}];
const props = getProvidedProps(null, null, {
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3 },
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3, index: 'index' },
});
expect(props).toEqual({ hits, hasMore: true });
});
Expand All @@ -20,7 +20,7 @@ describe('connectInfiniteHits', () => {
const hits = [{}, {}];
const hits2 = [{}, {}];
const res1 = getProvidedProps(null, null, {
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3 },
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3, index: 'index' },
});
expect(res1.hits).toEqual(hits);
expect(res1.hasMore).toBe(true);
Expand All @@ -30,6 +30,7 @@ describe('connectInfiniteHits', () => {
page: 1,
hitsPerPage: 2,
nbPages: 3,
index: 'index',
},
});
expect(res2.hits).toEqual([...hits, ...hits2]);
Expand All @@ -41,7 +42,7 @@ describe('connectInfiniteHits', () => {
const hits2 = [{}, {}, {}, {}, {}, {}];
const hits3 = [{}, {}, {}, {}, {}, {}, {}, {}];
const res1 = getProvidedProps(null, null, {
results: { hits, page: 0, hitsPerPage: 6, nbPages: 10 },
results: { hits, page: 0, hitsPerPage: 6, nbPages: 10, index: 'index' },
});
expect(res1.hits).toEqual(hits);
expect(res1.hasMore).toBe(true);
Expand All @@ -51,6 +52,7 @@ describe('connectInfiniteHits', () => {
page: 1,
hitsPerPage: 6,
nbPages: 10,
index: 'index',
},
});
expect(res2.hits).toEqual([...hits, ...hits2]);
Expand All @@ -61,6 +63,7 @@ describe('connectInfiniteHits', () => {
page: 2,
hitsPerPage: 8,
nbPages: 10,
index: 'index',
},
});
expect(res3.hits).toEqual([...hits, ...hits2, ...hits3]);
Expand All @@ -71,6 +74,7 @@ describe('connectInfiniteHits', () => {
page: 2,
hitsPerPage: 8,
nbPages: 10,
index: 'index',
},
}); //re-render with the same property
expect(res3.hits).toEqual([...hits, ...hits2, ...hits3]);
Expand All @@ -90,6 +94,7 @@ describe('connectInfiniteHits', () => {
page,
hitsPerPage: hits.length,
nbPages,
index: 'index',
},
});
expect(res.hits).toEqual(allHits);
Expand All @@ -105,6 +110,7 @@ describe('connectInfiniteHits', () => {
page: nbPages - 1,
hitsPerPage: hits.length,
nbPages,
index: 'index',
},
});
expect(res.hits.length).toEqual(nbPages * 2);
Expand All @@ -117,14 +123,15 @@ describe('connectInfiniteHits', () => {
const hits2 = [{}, {}];
const hits3 = [{}];
getProvidedProps(null, null, {
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3 },
results: { hits, page: 0, hitsPerPage: 2, nbPages: 3, index: 'index' },
});
getProvidedProps(null, null, {
results: {
hits: hits2,
page: 1,
hitsPerPage: 2,
nbPages: 3,
index: 'index',
},
});
const props = getProvidedProps(null, null, {
Expand All @@ -133,6 +140,7 @@ describe('connectInfiniteHits', () => {
page: 2,
hitsPerPage: 2,
nbPages: 3,
index: 'index',
},
});
expect(props.hits).toEqual([...hits, ...hits2, ...hits3]);
Expand Down Expand Up @@ -171,7 +179,15 @@ describe('connectInfiniteHits', () => {
it('provides the current hits to the component', () => {
const hits = [{}];
const props = getProvidedProps(null, null, {
results: { second: { hits, page: 0, hitsPerPage: 2, nbPages: 3 } },
results: {
second: {
hits,
page: 0,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
expect(props).toEqual({ hits, hasMore: true });
});
Expand All @@ -180,13 +196,27 @@ describe('connectInfiniteHits', () => {
const hits = [{}, {}];
const hits2 = [{}, {}];
const res1 = getProvidedProps(null, null, {
results: { second: { hits, page: 0, hitsPerPage: 2, nbPages: 3 } },
results: {
second: {
hits,
page: 0,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
expect(res1.hits).toEqual(hits);
expect(res1.hasMore).toBe(true);
const res2 = getProvidedProps(null, null, {
results: {
second: { hits: hits2, page: 1, hitsPerPage: 2, nbPages: 3 },
second: {
hits: hits2,
page: 1,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
expect(res2.hits).toEqual([...hits, ...hits2]);
Expand All @@ -198,27 +228,53 @@ describe('connectInfiniteHits', () => {
const hits2 = [{}, {}, {}, {}, {}, {}];
const hits3 = [{}, {}, {}, {}, {}, {}, {}, {}];
const res1 = getProvidedProps(null, null, {
results: { second: { hits, page: 0, hitsPerPage: 6, nbPages: 10 } },
results: {
second: {
hits,
page: 0,
hitsPerPage: 6,
nbPages: 10,
index: 'second',
},
},
});
expect(res1.hits).toEqual(hits);
expect(res1.hasMore).toBe(true);
const res2 = getProvidedProps(null, null, {
results: {
second: { hits: hits2, page: 1, hitsPerPage: 6, nbPages: 10 },
second: {
hits: hits2,
page: 1,
hitsPerPage: 6,
nbPages: 10,
index: 'second',
},
},
});
expect(res2.hits).toEqual([...hits, ...hits2]);
expect(res2.hasMore).toBe(true);
let res3 = getProvidedProps(null, null, {
results: {
second: { hits: hits3, page: 2, hitsPerPage: 8, nbPages: 10 },
second: {
hits: hits3,
page: 2,
hitsPerPage: 8,
nbPages: 10,
index: 'second',
},
},
});
expect(res3.hits).toEqual([...hits, ...hits2, ...hits3]);
expect(res3.hasMore).toBe(true);
res3 = getProvidedProps(null, null, {
results: {
second: { hits: hits3, page: 2, hitsPerPage: 8, nbPages: 10 },
second: {
hits: hits3,
page: 2,
hitsPerPage: 8,
nbPages: 10,
index: 'second',
},
},
}); //re-render with the same property
expect(res3.hits).toEqual([...hits, ...hits2, ...hits3]);
Expand All @@ -239,6 +295,7 @@ describe('connectInfiniteHits', () => {
page,
hitsPerPage: hits.length,
nbPages,
index: 'second',
},
},
});
Expand All @@ -256,6 +313,7 @@ describe('connectInfiniteHits', () => {
page: nbPages - 1,
hitsPerPage: hits.length,
nbPages,
index: 'second',
},
},
});
Expand All @@ -269,16 +327,36 @@ describe('connectInfiniteHits', () => {
const hits2 = [{}, {}];
const hits3 = [{}];
getProvidedProps(null, null, {
results: { second: { hits, page: 0, hitsPerPage: 2, nbPages: 3 } },
results: {
second: {
hits,
page: 0,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
getProvidedProps(null, null, {
results: {
second: { hits: hits2, page: 1, hitsPerPage: 2, nbPages: 3 },
second: {
hits: hits2,
page: 1,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
const props = getProvidedProps(null, null, {
results: {
second: { hits: hits3, page: 2, hitsPerPage: 2, nbPages: 3 },
second: {
hits: hits3,
page: 2,
hitsPerPage: 2,
nbPages: 3,
index: 'second',
},
},
});
expect(props.hits).toEqual([...hits, ...hits2, ...hits3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('connectMenu', () => {
getFacetValues: jest.fn(() => []),
getFacetByName: () => true,
hits: [],
index: 'index',
};

props = getProvidedProps({ attributeName: 'ok' }, {}, {});
Expand Down Expand Up @@ -212,6 +213,7 @@ describe('connectMenu', () => {
getFacetValues: jest.fn(() => []),
getFacetByName: () => true,
hits: [],
index: 'index',
};
results.getFacetValues.mockImplementation(() => [
{
Expand Down Expand Up @@ -386,6 +388,7 @@ describe('connectMenu', () => {
getFacetValues: jest.fn(() => []),
getFacetByName: () => true,
hits: [],
index: 'index',
};
results.getFacetValues.mockClear();
results.getFacetValues.mockImplementation(() => [
Expand Down Expand Up @@ -462,6 +465,7 @@ describe('connectMenu', () => {
first: {
getFacetValues: jest.fn(() => []),
getFacetByName: () => true,
index: 'first',
},
};

Expand Down Expand Up @@ -650,6 +654,7 @@ describe('connectMenu', () => {
first: {
getFacetValues: jest.fn(() => []),
getFacetByName: () => true,
index: 'first',
},
};
results.first.getFacetValues.mockImplementation(() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('connectMultiRange', () => {
getFacetStats: () => ({ min: 0, max: 300 }),
getFacetByName: () => true,
hits: [],
index: 'index',
};

it('provides the correct props to the component', () => {
Expand Down Expand Up @@ -372,6 +373,7 @@ describe('connectMultiRange', () => {
first: {
getFacetStats: () => ({ min: 0, max: 300 }),
getFacetByName: () => true,
index: 'first',
},
};

Expand Down
Loading

0 comments on commit 124ffe6

Please sign in to comment.