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

feat(stats): implement getRenderState and getWidgetRenderState #4565

Merged
merged 8 commits into from
Nov 6, 2020
49 changes: 49 additions & 0 deletions src/connectors/stats/__tests__/connectStats-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,55 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/stats/js/#c

stats.init(createInitOptions({ helper, state: helper.state }));

const results = new SearchResults(helper.state, [
createSingleSearchResponse(),
]);

const renderState2 = stats.getWidgetRenderState(
createRenderOptions({
helper,
state: helper.state,
results,
})
);

expect(renderState2).toEqual({
hitsPerPage: results.hitsPerPage,
nbHits: results.nbHits,
nbPages: results.nbPages,
page: results.page,
processingTimeMS: results.processingTimeMS,
query: results.query,
widgetParams: {},
});
});

test('returns the widget render state with results', () => {
const renderFn = jest.fn();
const unmountFn = jest.fn();
const createStats = connectStats(renderFn, unmountFn);
const stats = createStats();
const helper = jsHelper(createSearchClient(), 'indexName', {
index: 'indexName',
});
helper.search = jest.fn();

const renderState1 = stats.getWidgetRenderState(
createInitOptions({ helper })
);

expect(renderState1).toEqual({
hitsPerPage: undefined,
nbHits: 0,
nbPages: 0,
page: 0,
processingTimeMS: -1,
query: '',
widgetParams: {},
});

stats.init(createInitOptions({ helper, state: helper.state }));

const results = new SearchResults(helper.state, [
createSingleSearchResponse({
hits: [
Expand Down