From 5ad4d3e8a204bebf18dec6b61f29ee4157a4db50 Mon Sep 17 00:00:00 2001 From: Youcef Mammar Date: Tue, 23 Apr 2019 15:01:22 +0200 Subject: [PATCH] feat(insights): add insightsClient support on storybook (#664) * feat(insights): add insightsClient support on storybook **Summary** this prepares for the insights stories to be added illustrating the usage of Hits and InfiniteHits widgets with insights. * remove default insights definition for all stories * fix: change default insightsClient value to undefined Co-Authored-By: tkrugg * add check --- .storybook/addons.js | 1 + package.json | 1 + src/components/InstantSearch.js | 5 +++ src/components/__tests__/InstantSearch.js | 3 ++ stories/utils.js | 3 ++ yarn.lock | 37 ++++++++++++++++++++++- 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.storybook/addons.js b/.storybook/addons.js index 565910051..1d561cdfd 100644 --- a/.storybook/addons.js +++ b/.storybook/addons.js @@ -1,2 +1,3 @@ import '@storybook/addon-knobs/register'; import '@storybook/addon-options/register'; +import '@storybook/addon-actions/register'; diff --git a/package.json b/package.json index 23f09503b..6a57bc02a 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "devDependencies": { "@storybook/addon-knobs": "3.4.11", "@storybook/addon-options": "3.4.11", + "@storybook/addon-actions": "3.4.11", "@storybook/vue": "3.4.11", "@vue/test-utils": "1.0.0-beta.25", "algoliasearch": "3.32.0", diff --git a/src/components/InstantSearch.js b/src/components/InstantSearch.js index 4d7c6dec4..46ed5f335 100644 --- a/src/components/InstantSearch.js +++ b/src/components/InstantSearch.js @@ -14,6 +14,10 @@ export default createInstantSearchComponent({ type: Object, required: true, }, + insightsClient: { + type: Function, + required: false, + }, indexName: { type: String, required: true, @@ -68,6 +72,7 @@ export default createInstantSearchComponent({ return { instantSearchInstance: instantsearch({ searchClient: this.searchClient, + insightsClient: this.insightsClient, indexName: this.indexName, routing: this.routing, stalledSearchDelay: this.stalledSearchDelay, diff --git a/src/components/__tests__/InstantSearch.js b/src/components/__tests__/InstantSearch.js index b727f89fd..665869143 100644 --- a/src/components/__tests__/InstantSearch.js +++ b/src/components/__tests__/InstantSearch.js @@ -8,10 +8,12 @@ beforeEach(() => jest.clearAllMocks()); it('passes props to InstantSearch.js', () => { const searchClient = {}; + const insightsClient = jest.fn(); const searchFunction = helper => helper.search(); mount(InstantSearch, { propsData: { searchClient, + insightsClient, indexName: 'something', routing: { router: {}, @@ -29,6 +31,7 @@ it('passes props to InstantSearch.js', () => { stateMapping: {}, }, searchClient, + insightsClient, searchFunction, stalledSearchDelay: 250, }); diff --git a/stories/utils.js b/stories/utils.js index ade3ce298..4821cd849 100644 --- a/stories/utils.js +++ b/stories/utils.js @@ -2,6 +2,7 @@ import algoliasearch from 'algoliasearch/lite'; export const previewWrapper = ({ searchClient = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76'), + insightsClient, indexName = 'instant_search', hits = `
    @@ -59,6 +61,7 @@ export const previewWrapper = ({ data() { return { searchClient, + insightsClient, }; }, }); diff --git a/yarn.lock b/yarn.lock index dd9364e41..8faa813db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -95,6 +95,22 @@ resolved "https://registry.yarnpkg.com/@icons/material/-/material-0.2.4.tgz#e90c9f71768b3736e76d7dd6783fc6c2afa88bc8" integrity sha512-QPcGmICAPbGLGb6F/yNf/KzKqvFx8z5qx3D1yFqVAjoFmXK35EgyW+cJ57Te3CNsmzblwtzakLGFqHPqrfb4Tw== +"@storybook/addon-actions@3.4.11": + version "3.4.11" + resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-3.4.11.tgz#a51418c5b684fd3df2788c19ef266845d6068baf" + integrity sha512-vA7KiMg6J3SlI0U9COhyX+nxoNNXsgXTKBA7oVjE+wduNwNc86WcbYGxKIxhCjJMBoAjZYBeRL9DmYWwaHb4xQ== + dependencies: + "@storybook/components" "3.4.11" + babel-runtime "^6.26.0" + deep-equal "^1.0.1" + glamor "^2.20.40" + glamorous "^4.12.1" + global "^4.3.2" + make-error "^1.3.4" + prop-types "^15.6.1" + react-inspector "^2.2.2" + uuid "^3.2.1" + "@storybook/addon-knobs@3.4.11": version "3.4.11" resolved "https://registry.yarnpkg.com/@storybook/addon-knobs/-/addon-knobs-3.4.11.tgz#13ca0c73f19c0a3fda1a1d1ff07ef00fa3a914b3" @@ -6032,6 +6048,11 @@ is-directory@^0.3.1: resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1" integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE= +is-dom@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/is-dom/-/is-dom-1.0.9.tgz#483832d52972073de12b9fe3f60320870da8370d" + integrity sha1-SDgy1SlyBz3hK5/j9gMghw2oNw0= + is-dotfile@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1" @@ -7261,6 +7282,11 @@ make-dir@^1.0.0: dependencies: pify "^2.3.0" +make-error@^1.3.4: + version "1.3.5" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8" + integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g== + makeerror@1.0.x: version "1.0.11" resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c" @@ -9525,6 +9551,15 @@ react-icons@^2.2.7: dependencies: react-icon-base "2.1.0" +react-inspector@^2.2.2: + version "2.3.1" + resolved "https://registry.yarnpkg.com/react-inspector/-/react-inspector-2.3.1.tgz#f0eb7f520669b545b441af9d38ec6d706e5f649c" + integrity sha512-tUUK7t3KWgZEIUktOYko5Ic/oYwvjEvQUFAGC1UeMeDaQ5za2yZFtItJa2RTwBJB//NxPr000WQK6sEbqC6y0Q== + dependencies: + babel-runtime "^6.26.0" + is-dom "^1.0.9" + prop-types "^15.6.1" + react-is@^16.8.1: version "16.8.3" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.3.tgz#4ad8b029c2a718fc0cfc746c8d4e1b7221e5387d" @@ -11902,7 +11937,7 @@ uuid@^3.1.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" integrity sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g== -uuid@^3.3.2: +uuid@^3.2.1, uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==