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: use mainHelper consistently #5875

Merged
merged 2 commits into from
Oct 4, 2023
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 @@ -64,7 +64,8 @@ describe('insights', () => {
}

const getUserToken = () =>
(instantSearchInstance.helper!.state as PlainSearchParameters).userToken;
(instantSearchInstance.mainHelper!.state as PlainSearchParameters)
.userToken;

return {
analytics,
Expand Down Expand Up @@ -94,10 +95,11 @@ describe('insights', () => {
});
instantSearchInstance.start();

const helper = instantSearchInstance.helper!;
const helper = instantSearchInstance.mainHelper!;

const getUserToken = () =>
(instantSearchInstance.helper!.state as PlainSearchParameters).userToken;
(instantSearchInstance.mainHelper!.state as PlainSearchParameters)
.userToken;

return {
analytics,
Expand Down Expand Up @@ -473,17 +475,17 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f
insightsClient,
})
);
expect(instantSearchInstance.helper!.state.clickAnalytics).toBe(true);
expect(instantSearchInstance.mainHelper!.state.clickAnalytics).toBe(true);
});

it("doesn't reset page", () => {
const { insightsClient, instantSearchInstance } = createTestEnvironment();
const middleware = createInsightsMiddleware({
insightsClient,
})({ instantSearchInstance });
instantSearchInstance.helper!.setPage(100);
instantSearchInstance.mainHelper!.setPage(100);
middleware.subscribe();
expect(instantSearchInstance.helper!.state.page).toBe(100);
expect(instantSearchInstance.mainHelper!.state.page).toBe(100);
});

it('adds user agent', () => {
Expand Down Expand Up @@ -670,15 +672,15 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f

insightsClient('setUserToken', 'abc');
instantSearchInstance.start();
instantSearchInstance.helper!.setPage(100);
instantSearchInstance.mainHelper!.setPage(100);

instantSearchInstance.use(
createInsightsMiddleware({
insightsClient,
})
);

expect(instantSearchInstance.helper!.state.page).toBe(100);
expect(instantSearchInstance.mainHelper!.state.page).toBe(100);
expect(getUserToken()).toEqual('abc');
});

Expand All @@ -702,7 +704,7 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f
createTestEnvironment({ started: false });

instantSearchInstance.start();
instantSearchInstance.helper!.setPage(100);
instantSearchInstance.mainHelper!.setPage(100);

instantSearchInstance.use(
createInsightsMiddleware({
Expand All @@ -714,7 +716,7 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f

await wait(0);

expect(instantSearchInstance.helper!.state.page).toEqual(100);
expect(instantSearchInstance.mainHelper!.state.page).toEqual(100);
expect(getUserToken()).toEqual('def');
});

Expand Down Expand Up @@ -774,7 +776,8 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f
await wait(0);

expect(
(instantSearchInstance.helper!.state as PlainSearchParameters).userToken
(instantSearchInstance.mainHelper!.state as PlainSearchParameters)
.userToken
).toEqual('def');
});

Expand Down Expand Up @@ -1183,7 +1186,7 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f

instantSearchInstance
.helper!.setState({
...instantSearchInstance.helper!.state,
...instantSearchInstance.mainHelper!.state,
query: 'test',
})
.search();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function createInsightsMiddleware<
started() {
insightsClient('addAlgoliaAgent', 'insights-middleware');

helper = instantSearchInstance.helper!;
helper = instantSearchInstance.mainHelper!;

initialParameters = {
userToken: (helper.state as PlainSearchParameters).userToken,
Expand Down
5 changes: 4 additions & 1 deletion packages/instantsearch.js/src/widgets/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ const index = (widgetParams: IndexWidgetParams): IndexWidget => {
};

derivedHelper = mainHelper.derive(() =>
mergeSearchParameters(...resolveSearchParameters(this))
mergeSearchParameters(
mainHelper.state,
...resolveSearchParameters(this)
)
);

const indexInitialResults =
Expand Down
4 changes: 2 additions & 2 deletions tests/common/widgets/current-refinements/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function createOptionsTests(
<span
class="ais-CurrentRefinements-categoryLabel"
>
Apple
Samsung
</span>
<button
class="ais-CurrentRefinements-delete"
Expand All @@ -146,7 +146,7 @@ export function createOptionsTests(
<span
class="ais-CurrentRefinements-categoryLabel"
>
Samsung
Apple
</span>
<button
class="ais-CurrentRefinements-delete"
Expand Down