From 121d13ab9cec7a6555963bfc3c8fedc8b1afd790 Mon Sep 17 00:00:00 2001
From: Dhaya <154633+dhayab@users.noreply.github.com>
Date: Wed, 4 Oct 2023 17:02:24 +0200
Subject: [PATCH] fix: use mainHelper consistently (#5875)
---
.../__tests__/createInsightsMiddleware.ts | 27 ++++++++++---------
.../middlewares/createInsightsMiddleware.ts | 2 +-
.../src/widgets/index/index.ts | 5 +++-
.../widgets/current-refinements/options.ts | 4 +--
4 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts b/packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts
index f21dcc2958..eb76aa3434 100644
--- a/packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts
+++ b/packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts
@@ -64,7 +64,8 @@ describe('insights', () => {
}
const getUserToken = () =>
- (instantSearchInstance.helper!.state as PlainSearchParameters).userToken;
+ (instantSearchInstance.mainHelper!.state as PlainSearchParameters)
+ .userToken;
return {
analytics,
@@ -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,
@@ -473,7 +475,7 @@ 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", () => {
@@ -481,9 +483,9 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f
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', () => {
@@ -670,7 +672,7 @@ 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({
@@ -678,7 +680,7 @@ See documentation: https://www.algolia.com/doc/guides/building-search-ui/going-f
})
);
- expect(instantSearchInstance.helper!.state.page).toBe(100);
+ expect(instantSearchInstance.mainHelper!.state.page).toBe(100);
expect(getUserToken()).toEqual('abc');
});
@@ -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({
@@ -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');
});
@@ -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');
});
@@ -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();
diff --git a/packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts b/packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts
index 49a7bea30c..d9f51a475b 100644
--- a/packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts
+++ b/packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts
@@ -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,
diff --git a/packages/instantsearch.js/src/widgets/index/index.ts b/packages/instantsearch.js/src/widgets/index/index.ts
index 97912b2bc1..78042db170 100644
--- a/packages/instantsearch.js/src/widgets/index/index.ts
+++ b/packages/instantsearch.js/src/widgets/index/index.ts
@@ -492,7 +492,10 @@ const index = (widgetParams: IndexWidgetParams): IndexWidget => {
};
derivedHelper = mainHelper.derive(() =>
- mergeSearchParameters(...resolveSearchParameters(this))
+ mergeSearchParameters(
+ mainHelper.state,
+ ...resolveSearchParameters(this)
+ )
);
const indexInitialResults =
diff --git a/tests/common/widgets/current-refinements/options.ts b/tests/common/widgets/current-refinements/options.ts
index 167d7b958a..63b17537e9 100644
--- a/tests/common/widgets/current-refinements/options.ts
+++ b/tests/common/widgets/current-refinements/options.ts
@@ -131,7 +131,7 @@ export function createOptionsTests(
- Apple
+ Samsung