Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connectors): replace hits for items #6486

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co

expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [],
items: [],
results: undefined,
}),
expect.anything()
Expand All @@ -146,7 +146,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co

expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits,
items: hits,
results,
}),
expect.anything()
Expand All @@ -170,7 +170,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co

expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [],
items: [],
results: undefined,
}),
expect.anything()
Expand Down Expand Up @@ -217,7 +217,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co

expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: expectedHits,
items: expectedHits,
results,
}),
expect.anything()
Expand All @@ -244,7 +244,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co

expect(renderFn).toHaveBeenNthCalledWith(
1,
expect.objectContaining({ hits: [], results: undefined }),
expect.objectContaining({ items: [], results: undefined }),
expect.anything()
);

Expand Down Expand Up @@ -272,7 +272,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
expect(renderFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
hits: expectedHits,
items: expectedHits,
results,
}),
expect.anything()
Expand Down Expand Up @@ -345,7 +345,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
expect(renderFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
hits: expectedHits,
items: expectedHits,
}),
expect.anything()
);
Expand Down Expand Up @@ -450,7 +450,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
expect(renderFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
hits: expectedHits,
items: expectedHits,
results,
}),
expect.anything()
Expand Down Expand Up @@ -505,7 +505,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
);

expect(renderState1.hits).toEqual({
hits: [],
items: [],
sendEvent: expect.any(Function),
results: undefined,
Expand Down Expand Up @@ -536,7 +535,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
];

expect(renderState2.hits).toEqual({
hits: expectedHits,
items: expectedHits,
sendEvent: renderState1.hits.sendEvent,
results,
Expand Down Expand Up @@ -566,7 +564,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
);

expect(renderState1).toEqual({
hits: [],
items: [],
banner: undefined,
sendEvent: expect.any(Function),
Expand Down Expand Up @@ -603,7 +600,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
];

expect(renderState2).toEqual({
hits: expectedHits,
items: expectedHits,
banner,
sendEvent: renderState1.sendEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
instantSearchInstance,
hits: [],
items: [],
showPrevious: expect.any(Function),
showMore: expect.any(Function),
results: undefined,
Expand Down Expand Up @@ -133,7 +133,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
instantSearchInstance,
hits: [],
items: [],
showPrevious: expect.any(Function),
showMore: expect.any(Function),
results: expect.any(Object),
Expand Down Expand Up @@ -163,7 +163,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const firstRenderOptions = renderFn.mock.calls[0][0];
expect(firstRenderOptions.hits).toEqual([]);
expect(firstRenderOptions.items).toEqual([]);
expect(firstRenderOptions.results).toBe(undefined);

const hits = [
Expand All @@ -184,7 +184,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi

const secondRenderOptions = renderFn.mock.calls[1][0];
const { showMore } = secondRenderOptions;
expect(secondRenderOptions.hits).toEqual(hits);
expect(secondRenderOptions.items).toEqual(hits);
expect(secondRenderOptions.results).toEqual(results);
showMore();
expect(helper.search).toHaveBeenCalledTimes(1);
Expand All @@ -207,7 +207,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const thirdRenderOptions = renderFn.mock.calls[2][0];
expect(thirdRenderOptions.hits).toEqual([...hits, ...otherHits]);
expect(thirdRenderOptions.items).toEqual([...hits, ...otherHits]);
expect(thirdRenderOptions.results).toEqual(otherResults);
});

Expand All @@ -230,7 +230,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const firstRenderOptions = renderFn.mock.calls[0][0];
expect(firstRenderOptions.hits).toEqual([]);
expect(firstRenderOptions.items).toEqual([]);
expect(firstRenderOptions.results).toBe(undefined);

const hits = [
Expand All @@ -251,7 +251,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi

const secondRenderOptions = renderFn.mock.calls[1][0];
const { showPrevious } = secondRenderOptions;
expect(secondRenderOptions.hits).toEqual(hits);
expect(secondRenderOptions.items).toEqual(hits);
expect(secondRenderOptions.results).toEqual(results);
showPrevious();
expect(helper.state.page).toBe(0);
Expand Down Expand Up @@ -279,7 +279,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const thirdRenderOptions = renderFn.mock.calls[2][0];
expect(thirdRenderOptions.hits).toEqual([...previousHits, ...hits]);
expect(thirdRenderOptions.items).toEqual([...previousHits, ...hits]);
expect(thirdRenderOptions.results).toEqual(previousResults);
});

Expand Down Expand Up @@ -315,7 +315,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
).toHaveBeenCalledWith(expect.objectContaining({ page: 3 }));
});

it('Provides the hits and flush hists cache on query changes', () => {
it('Provides the hits and flush hits cache on query changes', () => {
const renderFn = jest.fn();
const makeWidget = connectInfiniteHits(renderFn);
const widget = makeWidget({});
Expand All @@ -331,7 +331,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const firstRenderOptions = renderFn.mock.calls[0][0];
expect(firstRenderOptions.hits).toEqual([]);
expect(firstRenderOptions.items).toEqual([]);
expect(firstRenderOptions.results).toBe(undefined);

const hits = [
Expand All @@ -351,7 +351,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const secondRenderOptions = renderFn.mock.calls[1][0];
expect(secondRenderOptions.hits).toEqual(hits);
expect(secondRenderOptions.items).toEqual(hits);
expect(secondRenderOptions.results).toEqual(results);

helper.setQuery('data');
Expand All @@ -374,7 +374,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const thirdRenderOptions = renderFn.mock.calls[2][0];
expect(thirdRenderOptions.hits).toEqual(otherHits);
expect(thirdRenderOptions.items).toEqual(otherHits);
expect(thirdRenderOptions.results).toEqual(otherResults);
});

Expand Down Expand Up @@ -480,7 +480,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const firstRenderOptions = renderFn.mock.calls[0][0];
expect(firstRenderOptions.hits).toEqual([]);
expect(firstRenderOptions.items).toEqual([]);
expect(firstRenderOptions.results).toBe(undefined);

const hits = [
Expand Down Expand Up @@ -524,7 +524,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
];

const secondRenderOptions = renderFn.mock.calls[1][0];
expect(secondRenderOptions.hits).toEqual(escapedHits);
expect(secondRenderOptions.items).toEqual(escapedHits);
expect(secondRenderOptions.results).toEqual(results);
});

Expand All @@ -548,7 +548,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
);

const firstRenderOptions = renderFn.mock.calls[0][0];
expect(firstRenderOptions.hits).toEqual([]);
expect(firstRenderOptions.items).toEqual([]);
expect(firstRenderOptions.results).toBe(undefined);

const hits = [
Expand Down Expand Up @@ -586,7 +586,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
];

const secondRenderOptions = renderFn.mock.calls[1][0];
expect(secondRenderOptions.hits).toEqual(transformedHits);
expect(secondRenderOptions.items).toEqual(transformedHits);
expect(secondRenderOptions.results).toEqual(results);
});

Expand Down Expand Up @@ -683,7 +683,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
hits: [
items: [
{
name: 'hello',
_highlightResult: {
Expand Down Expand Up @@ -754,7 +754,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
hits: [
items: [
{
name: 'name 1',
objectID: '1',
Expand Down Expand Up @@ -819,7 +819,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenCalledTimes(3);
expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [{ objectID: 'a' }, { objectID: 'b' }],
items: [{ objectID: 'a' }, { objectID: 'b' }],
}),
false
);
Expand All @@ -841,7 +841,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(renderFn).toHaveBeenCalledTimes(4);
expect(renderFn).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [{ objectID: 'a' }, { objectID: 'b' }],
items: [{ objectID: 'a' }, { objectID: 'b' }],
}),
false
);
Expand Down Expand Up @@ -947,7 +947,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

let renderOptions = renderFn.mock.calls[2][0];
expect(renderOptions.hits).toEqual(firstPageHits);
expect(renderOptions.items).toEqual(firstPageHits);
expect(renderOptions.results).toEqual(searchResults);

// Search: page 2
Expand All @@ -964,7 +964,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

renderOptions = renderFn.mock.calls[3][0];
expect(renderOptions.hits).toEqual([...firstPageHits, ...secondPageHits]);
expect(renderOptions.items).toEqual([
...firstPageHits,
...secondPageHits,
]);
expect(renderOptions.results).toEqual(searchResults);
}

Expand All @@ -991,7 +994,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

const renderOptions = renderFn.mock.calls[2][0];
expect(renderOptions.hits).toEqual([...firstPageHits, ...secondPageHits]);
expect(renderOptions.items).toEqual([
...firstPageHits,
...secondPageHits,
]);
expect(renderOptions.results).toEqual(searchResults);
}
});
Expand Down Expand Up @@ -1063,7 +1069,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

let renderOptions = renderFn.mock.calls[2][0];
expect(renderOptions.hits).toEqual(firstPageHits);
expect(renderOptions.items).toEqual(firstPageHits);
expect(renderOptions.results).toEqual(searchResults);

// Search: page 2
Expand All @@ -1081,7 +1087,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

renderOptions = renderFn.mock.calls[3][0];
expect(renderOptions.hits).toEqual([...firstPageHits, ...secondPageHits]);
expect(renderOptions.items).toEqual([
...firstPageHits,
...secondPageHits,
]);
expect(renderOptions.results).toEqual(searchResults);
}

Expand Down Expand Up @@ -1109,7 +1118,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
renderWidget({ results: searchResults });

const renderOptions = renderFn.mock.calls[2][0];
expect(renderOptions.hits).toEqual([...firstPageHits, ...secondPageHits]);
expect(renderOptions.items).toEqual([
...firstPageHits,
...secondPageHits,
]);
expect(renderOptions.results).toEqual(searchResults);
}
});
Expand Down Expand Up @@ -1323,7 +1335,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
const renderState1 = infiniteHitsWidget.getRenderState({}, initOptions);

expect(renderState1.infiniteHits).toEqual({
hits: [],
items: [],
currentPageHits: [],
sendEvent: expect.any(Function),
Expand Down Expand Up @@ -1386,7 +1397,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
];

expect(renderState2.infiniteHits).toEqual({
hits: expectedHits,
items: expectedHits,
currentPageHits: expectedCurrentPageHits,
sendEvent: renderState1.infiniteHits.sendEvent,
Expand Down Expand Up @@ -1416,7 +1426,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
const renderState1 = infiniteHitsWidget.getWidgetRenderState(initOptions);

expect(renderState1).toEqual({
hits: [],
items: [],
currentPageHits: [],
sendEvent: expect.any(Function),
Expand Down Expand Up @@ -1492,7 +1501,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
];

expect(renderState2).toEqual({
hits: expectedHits,
items: expectedHits,
currentPageHits: expectedCurrentPageHits,
sendEvent: renderState1.sendEvent,
Expand Down
Loading