diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index fc40fefaecd..00000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,46 +0,0 @@ - - -**Do you want to request a *feature* or report a *bug*?** - - - -**Bug: What is the current behavior?** - -**Bug: What is the expected behavior?** - -**Bug: What browsers are impacted? Which versions?** - -**Bug: What is the proposed solution?** - -**Feature: What is your use case for such a feature?** - -**Feature: What is your proposed API entry? The new option to add? What is the behavior?** - -**What is the version you are using? Always use the latest one before opening a bug issue.** - - diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md new file mode 100644 index 00000000000..460c99a7ca1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -0,0 +1,36 @@ +--- +name: Bug report +about: Create a report to help us improve InstantSearch.js + +--- + + + +**Describe the bug 🐛** +A clear and concise description of what the bug is. + +**To Reproduce 🔍** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +A live example helps a lot! We have a simple online template for you to use for your explanations: + https://codesandbox.io/s/github/algolia/instantsearch-templates/tree/master/src/InstantSearch.js + +**Expected behavior 💭** +A clear and concise description of what you expected to happen. + +**Screenshots 🖥** +If applicable, add screenshots to help explain your problem. + +**Environment:** + - OS: [e.g. iOS / windows / mac / android] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md new file mode 100644 index 00000000000..4a2c82bab54 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -0,0 +1,21 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + + + +**Is your feature request related to a problem? Please describe 🙏** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like 🤔** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered ✨** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/CHANGELOG.md b/CHANGELOG.md index f1849d7003c..6c97d5444eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ + +## [2.7.4](https://github.com/algolia/instantsearch.js/compare/v2.7.3...v2.7.4) (2018-05-03) + + +### Bug Fixes + +* **searchFunction:** Fix unresolved returned Promise ([#2913](https://github.com/algolia/instantsearch.js/issues/2913)) ([5286c7c](https://github.com/algolia/instantsearch.js/commit/5286c7c)) + + + + +## [2.7.3](https://github.com/algolia/instantsearch.js/compare/v2.7.2...v2.7.3) (2018-04-26) + + +### Bug Fixes + +* **index.es6:** avoid use of Object.assign for IE ([#2908](https://github.com/algolia/instantsearch.js/issues/2908)) ([228b02e](https://github.com/algolia/instantsearch.js/commit/228b02e)) + + + + +## [2.7.2](https://github.com/algolia/instantsearch.js/compare/v2.7.1...v2.7.2) (2018-04-18) + +### Bug Fixes + +* **routing:** should apply stateMapping when doing initial write ([#2892](https://github.com/algolia/instantsearch.js/issues/2892)) ([7f62e6dc](https://github.com/algolia/instantsearch.js/commit/7f62e6dc)) +* **ie:** do not rely on Object.assign ([#2885](https://github.com/algolia/instantsearch.js/issues/2885)) ([88497e56](https://github.com/algolia/instantsearch.js/commit/88497e56)) + + + ## [2.7.1](https://github.com/algolia/instantsearch.js/compare/v2.7.0...v2.7.1) (2018-04-11) diff --git a/dev/app/builtin/stories/geo-search.stories.js b/dev/app/builtin/stories/geo-search.stories.js index e6e7786501f..65c473d1dc3 100644 --- a/dev/app/builtin/stories/geo-search.stories.js +++ b/dev/app/builtin/stories/geo-search.stories.js @@ -7,6 +7,8 @@ import instantsearch from '../../../../index'; import { wrapWithHits } from '../../utils/wrap-with-hits'; import createInfoBox from '../../utils/create-info-box'; +const API_KEY = 'AIzaSyBawL8VbstJDdU5397SUX7pEt9DslAwWgQ'; + const wrapWithHitsAndConfiguration = (story, searchParameters) => wrapWithHits(story, { indexName: 'airbnb', @@ -18,7 +20,7 @@ const wrapWithHitsAndConfiguration = (story, searchParameters) => const injectGoogleMaps = fn => { injectScript( - 'https://maps.googleapis.com/maps/api/js?v=3.31&key=AIzaSyCl2TTJXpwxGuuc2zQZkAlIkWhpYbyjjP8', + `https://maps.googleapis.com/maps/api/js?v=3.31&key=${API_KEY}`, fn ); }; diff --git a/docgen/assets/js/main.js b/docgen/assets/js/main.js index 67346449743..2e95a81e42b 100644 --- a/docgen/assets/js/main.js +++ b/docgen/assets/js/main.js @@ -59,3 +59,11 @@ toggleDocumentationSidebar(); window.addEventListener('resize', () => { toggleDocumentationSidebar(); }); + +const openIssueLink = document.querySelector('#link-open-issue'); +if (openIssueLink) { + openIssueLink.href = openIssueLink.href.replace( + /__LOCATION__/g, + window.location.href + ); +} diff --git a/docgen/layouts/archetypes/content-with-menu.pug b/docgen/layouts/archetypes/content-with-menu.pug index c9a4a663423..7d3d5261e5e 100644 --- a/docgen/layouts/archetypes/content-with-menu.pug +++ b/docgen/layouts/archetypes/content-with-menu.pug @@ -14,7 +14,7 @@ body.documentation block content hr p - strong Can't find what you are looking for? #[a(href="https://github.com/algolia/instantsearch.js/issues/new?title=I could not find what I was looking for&body=Hi! I have a documentation issue on InstantSearch.js, I could not find what I was looking for which is: -- PLEASE FILL IN HERE --") Open an issue], we'll get back to you. + strong Can't find what you are looking for? #[a(href=`https://github.com/algolia/instantsearch.js/issues/new?title=Question on the page "${title}"&body=Hi! I have a documentation issue on InstantSearch.js. I could not find what I was looking for on the page "[${title}](__LOCATION__)".%0A%0A&labels=Doc: question`, id="link-open-issue") Open an issue], we'll get back to you. include ../common/footer.pug script(src=webpack.assets['js/main.js']) diff --git a/docgen/layouts/instantsearch.pug b/docgen/layouts/instantsearch.pug index 8353addd239..ffc08fda6c5 100644 --- a/docgen/layouts/instantsearch.pug +++ b/docgen/layouts/instantsearch.pug @@ -37,10 +37,10 @@ block content p InstantSearch is an EventEmitter and as such it emits events on specific parts of the lifecycle. h3 render p - | The `render` event is triggered when the rendering of all the widgets is done. This + | Triggered when the rendering of all the widgets is done. This | happens after a search result comes back from Algolia - which means that it is - | triggered for the first once everything after all the widgets went through all + | triggered for the first time once everything after all the widgets went through all | there lifecycle steps once (getConfiguration, init, render). h3 error p - | The `error` event is triggered when an error is reported when calling the API. + | Triggered when an error is reported when calling the API. diff --git a/docgen/src/data/communityHeader.json b/docgen/src/data/communityHeader.json index 095045e9740..75f4a8595e3 100644 --- a/docgen/src/data/communityHeader.json +++ b/docgen/src/data/communityHeader.json @@ -21,7 +21,7 @@ "logo": "https://community.algolia.com/img/illus-autocomplete.svg", "backgroundColor": "#00587f" }, { - "name": "InstantSearch React", + "name": "React InstantSearch", "url": "https://community.algolia.com/instantsearch.js/react", "logo": "https://community.algolia.com/img/logo-react-instantsearch.svg", "backgroundColor": "linear-gradient(45deg, #3369e7, #00aeff), linear-gradient(#fafafa, #fafafa)" diff --git a/docgen/src/examples/tourism/index.html b/docgen/src/examples/tourism/index.html index 60e7d4d3a1f..05126caf171 100644 --- a/docgen/src/examples/tourism/index.html +++ b/docgen/src/examples/tourism/index.html @@ -70,7 +70,7 @@ - + diff --git a/docgen/src/stylesheets/vendors/bootstrap/_code.scss b/docgen/src/stylesheets/vendors/bootstrap/_code.scss index caa5f06304c..85db24f8947 100755 --- a/docgen/src/stylesheets/vendors/bootstrap/_code.scss +++ b/docgen/src/stylesheets/vendors/bootstrap/_code.scss @@ -12,6 +12,10 @@ samp { } // Inline code +code:empty { + display: none; +} + code { padding: 2px 4px; font-size: 90%; diff --git a/docgen/src/widgets-common-api.md b/docgen/src/widgets-common-api.md index e3d46f49820..5ef503a3d9e 100644 --- a/docgen/src/widgets-common-api.md +++ b/docgen/src/widgets-common-api.md @@ -37,7 +37,7 @@ search.addWidget(instantsearch.searchbox({ `cssClasses` is a parameter that let you specify one or more classes to add to some specific element of the rendered widget. When available, this parameter is an object of either string or array of strings. The different keys available -is define in the widget reference. +is defined in the widget reference. ```javascript const search = instantsearch(/* parameters here */); @@ -79,8 +79,8 @@ search.addWidget(instantsearch.refinementList({ ## transformData `transformData` is used to provide function that will transform the data -passed to the templates. This is particularly handy when using using mustache -because it only accepts conditionnals over `boolean` value. +passed to the templates. This is particularly handy when using mustache +because it only accepts conditionals over `Boolean` values. Those function map the different template keys available, when it makes sense. For example, if a widget accepts an `item` template, you can provide an `item` diff --git a/index.es6.js b/index.es6.js index 3d2d7892107..d54916150b9 100644 --- a/index.es6.js +++ b/index.es6.js @@ -9,10 +9,11 @@ import version from './lib/version.js'; // import instantsearch from 'instantsearch.js'; // -> provides instantsearch object without connectors and widgets -const instantSearchFactory = Object.assign(toFactory(InstantSearch), { - version, - createQueryString: algoliasearchHelper.url.getQueryStringFromState, -}); +const instantSearchFactory = toFactory(InstantSearch); + +instantSearchFactory.version = version; +instantSearchFactory.createQueryString = + algoliasearchHelper.url.getQueryStringFromState; Object.defineProperty(instantSearchFactory, 'widgets', { get() { diff --git a/package.json b/package.json index 74c501f2050..39251beff1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "instantsearch.js", - "version": "2.7.1", + "version": "2.7.4", "description": "instantsearch.js is a library of widgets to build high performance instant search experiences using Algolia", "homepage": "https://community.algolia.com/instantsearch.js/", "keywords": [ @@ -130,8 +130,8 @@ "webpack-dev-server": "2.11.2" }, "dependencies": { - "algoliasearch": "3.25.1", - "algoliasearch-helper": "2.24.0", + "algoliasearch": "3.27.0", + "algoliasearch-helper": "2.26.0", "classnames": "2.2.5", "events": "1.1.0", "hogan.js": "3.0.2", diff --git a/src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.js b/src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.js index b1e7e59e22b..9a03124468d 100644 --- a/src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.js +++ b/src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.js @@ -75,7 +75,7 @@ describe('connectBreadcrumb', () => { // Verify that the widget has not been rendered yet at this point expect(rendering.mock.calls).toHaveLength(0); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -154,7 +154,7 @@ describe('connectBreadcrumb', () => { const widget = makeWidget({ attributes: ['category', 'sub_category'] }); const config = widget.getConfiguration({}); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); helper.toggleRefinement('category', 'Decoration'); @@ -208,7 +208,7 @@ describe('connectBreadcrumb', () => { const widget = makeWidget({ attributes: ['category', 'sub_category'] }); const config = widget.getConfiguration({}); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -267,7 +267,7 @@ describe('connectBreadcrumb', () => { }); const config = widget.getConfiguration({}); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -427,7 +427,7 @@ describe('connectBreadcrumb', () => { const widget = makeWidget({ attributes: ['category', 'sub_category'] }); const config = widget.getConfiguration({}); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/clear-all/__tests__/connectClearAll-test.js b/src/connectors/clear-all/__tests__/connectClearAll-test.js index d51a9abee0e..4e8500b68bf 100644 --- a/src/connectors/clear-all/__tests__/connectClearAll-test.js +++ b/src/connectors/clear-all/__tests__/connectClearAll-test.js @@ -7,7 +7,7 @@ import connectClearAll from '../connectClearAll.js'; describe('connectClearAll', () => { it('Renders during init and render', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); helper.search = sinon.stub(); // test that the dummyRendering is called with the isFirstRendering // flag set accordingly @@ -58,7 +58,7 @@ describe('connectClearAll', () => { // test the function received by the rendering function // to clear the refinements - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', { + const helper = jsHelper({}, '', { facets: ['myFacet'], }); helper.search = sinon.stub(); @@ -105,7 +105,7 @@ describe('connectClearAll', () => { // test the function received by the rendering function // to clear the refinements - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', { + const helper = jsHelper({}, '', { facets: ['myFacet'], }); helper.search = sinon.stub(); @@ -152,7 +152,7 @@ describe('connectClearAll', () => { it('some refinements from results <=> hasRefinements = true', () => { // test if the values sent to the rendering function // are consistent with the search state - const helper = jsHelper({ addAlgoliaAgent: () => {} }, undefined, { + const helper = jsHelper({}, undefined, { facets: ['aFacet'], }); helper.toggleRefinement('aFacet', 'some value'); @@ -184,7 +184,7 @@ describe('connectClearAll', () => { it('(clearsQuery: true) query not empty <=> hasRefinements = true', () => { // test if the values sent to the rendering function // are consistent with the search state - const helper = jsHelper({ addAlgoliaAgent: () => {} }, undefined, { + const helper = jsHelper({}, undefined, { facets: ['aFacet'], }); helper.setQuery('no empty'); @@ -219,7 +219,7 @@ describe('connectClearAll', () => { // test if the values sent to the rendering function // are consistent with the search state - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); helper.setQuery('not empty'); helper.search = sinon.stub(); diff --git a/src/connectors/configure/__tests__/connectConfigure-test.js b/src/connectors/configure/__tests__/connectConfigure-test.js index 98055d86e3b..f031e04ff8d 100644 --- a/src/connectors/configure/__tests__/connectConfigure-test.js +++ b/src/connectors/configure/__tests__/connectConfigure-test.js @@ -2,7 +2,9 @@ import algoliasearchHelper, { SearchParameters } from 'algoliasearch-helper'; import connectConfigure from '../connectConfigure.js'; -const fakeClient = { addAlgoliaAgent: () => {}, search: jest.fn() }; +const fakeClient = { + search: jest.fn(() => Promise.resolve({ results: [{}] })), +}; describe('connectConfigure', () => { let helper; diff --git a/src/connectors/current-refined-values/__tests__/connectCurrentRefinedValues-test.js b/src/connectors/current-refined-values/__tests__/connectCurrentRefinedValues-test.js index 683a4d5ab13..3510acabef9 100644 --- a/src/connectors/current-refined-values/__tests__/connectCurrentRefinedValues-test.js +++ b/src/connectors/current-refined-values/__tests__/connectCurrentRefinedValues-test.js @@ -5,7 +5,7 @@ import connectCurrentRefinedValues from '../connectCurrentRefinedValues.js'; describe('connectCurrentRefinedValues', () => { it('Renders during init and render', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); helper.search = sinon.stub(); // test that the dummyRendering is called with the isFirstRendering // flag set accordingly @@ -58,7 +58,7 @@ describe('connectCurrentRefinedValues', () => { it('Provide a function to clear the refinement', () => { // For each refinements we get a function that we can call // for removing a single refinement - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', { + const helper = jsHelper({}, '', { facets: ['myFacet'], }); helper.search = sinon.stub(); @@ -100,7 +100,7 @@ describe('connectCurrentRefinedValues', () => { }); it('should clear also the search query', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', {}); + const helper = jsHelper({}, '', {}); helper.search = jest.fn(); const rendering = jest.fn(); @@ -128,7 +128,7 @@ describe('connectCurrentRefinedValues', () => { }); it('should provide the query as a refinement if clearsQuery is true', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', {}); + const helper = jsHelper({}, '', {}); helper.search = jest.fn(); const rendering = jest.fn(); diff --git a/src/connectors/geo-search/__tests__/connectGeoSearch-test.js b/src/connectors/geo-search/__tests__/connectGeoSearch-test.js index 038f5063817..c9fc8518f64 100644 --- a/src/connectors/geo-search/__tests__/connectGeoSearch-test.js +++ b/src/connectors/geo-search/__tests__/connectGeoSearch-test.js @@ -6,10 +6,6 @@ import algoliasearchHelper, { } from 'algoliasearch-helper'; import connectGeoSearch from '../connectGeoSearch'; -const createFakeClient = () => ({ - addAlgoliaAgent: () => {}, -}); - const createFakeHelper = client => { const helper = algoliasearchHelper(client); @@ -44,7 +40,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); + const client = {}; const helper = createFakeHelper(client); const instantSearchInstance = { client, helper }; @@ -123,8 +119,7 @@ describe('connectGeoSearch - rendering', () => { enableRefineOnMapMove: false, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); widget.init({ state: helper.state, @@ -154,8 +149,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); widget.render({ results: new SearchResults(helper.getState(), [ @@ -193,8 +187,7 @@ describe('connectGeoSearch - rendering', () => { }, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); // Simulate the configuration or external setter helper.setQueryParameter('aroundLatLng', '10, 12'); @@ -271,8 +264,7 @@ describe('connectGeoSearch - rendering', () => { }, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); // Simulate the configuration or external setter helper.setQueryParameter('insideBoundingBox', [ @@ -327,8 +319,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -393,8 +384,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -459,8 +449,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -525,8 +514,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -592,8 +580,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -643,8 +630,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -696,8 +682,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -760,8 +745,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const northEast = { lat: 12, @@ -826,8 +810,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); widget.init({ state: helper.state, @@ -865,8 +848,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); widget.render({ results: new SearchResults(helper.getState(), [ @@ -898,8 +880,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); widget.init({ state: helper.state, @@ -937,8 +918,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const results = new SearchResults(helper.getState(), [ { @@ -970,8 +950,7 @@ describe('connectGeoSearch - rendering', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); const results = new SearchResults(helper.getState(), [ { @@ -1277,8 +1256,7 @@ describe('connectGeoSearch - dispose', () => { enableGeolocationWithIP: false, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) @@ -1308,8 +1286,7 @@ describe('connectGeoSearch - dispose', () => { }, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper.setState(widget.getConfiguration(new SearchParameters())); @@ -1333,8 +1310,7 @@ describe('connectGeoSearch - dispose', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper.setState(widget.getConfiguration(new SearchParameters())); @@ -1357,8 +1333,7 @@ describe('connectGeoSearch - dispose', () => { enableGeolocationWithIP: false, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) @@ -1386,8 +1361,7 @@ describe('connectGeoSearch - dispose', () => { }, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) @@ -1417,8 +1391,7 @@ describe('connectGeoSearch - dispose', () => { }, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper.setState(widget.getConfiguration(new SearchParameters())); @@ -1439,8 +1412,7 @@ describe('connectGeoSearch - dispose', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) @@ -1467,8 +1439,7 @@ describe('connectGeoSearch - dispose', () => { radius: 1000, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper.setState(widget.getConfiguration(new SearchParameters())); @@ -1489,8 +1460,7 @@ describe('connectGeoSearch - dispose', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) @@ -1517,8 +1487,7 @@ describe('connectGeoSearch - dispose', () => { precision: 1000, }); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper.setState(widget.getConfiguration(new SearchParameters())); @@ -1539,8 +1508,7 @@ describe('connectGeoSearch - dispose', () => { const customGeoSearch = connectGeoSearch(render, unmount); const widget = customGeoSearch(); - const client = createFakeClient(); - const helper = createFakeHelper(client); + const helper = createFakeHelper({}); helper .setState(widget.getConfiguration(new SearchParameters())) diff --git a/src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.js b/src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.js index 5996d27e57f..99895a54aba 100644 --- a/src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.js +++ b/src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.js @@ -88,7 +88,7 @@ describe('connectHierarchicalMenu', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -128,11 +128,7 @@ describe('connectHierarchicalMenu', () => { attributes: ['category', 'sub_category'], }); - const helper = jsHelper( - { addAlgoliaAgent: () => {} }, - '', - widget.getConfiguration({}) - ); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); helper.toggleRefinement('category', 'value'); @@ -173,11 +169,7 @@ describe('connectHierarchicalMenu', () => { attributes: ['category', 'subCategory'], }); - const helper = jsHelper( - { addAlgoliaAgent: () => {} }, - '', - widget.getConfiguration({}) - ); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); helper.toggleRefinement('category', 'Decoration'); @@ -265,11 +257,7 @@ describe('connectHierarchicalMenu', () => { attributes: ['category', 'subCategory'], }); - const helper = jsHelper( - { addAlgoliaAgent: () => {} }, - '', - widget.getConfiguration({}) - ); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js b/src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js index ca71587c7aa..24f9a56e873 100644 --- a/src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js +++ b/src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js @@ -5,8 +5,6 @@ const SearchParameters = jsHelper.SearchParameters; import connectHitsPerPage from '../connectHitsPerPage.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectHitsPerPage', () => { it('should throw when there is two default items defined', () => { expect(() => { @@ -37,7 +35,7 @@ describe('connectHitsPerPage', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { hitsPerPage: 3, }); helper.search = sinon.stub(); @@ -117,7 +115,7 @@ describe('connectHitsPerPage', () => { ], }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { hitsPerPage: 11, }); helper.search = sinon.stub(); @@ -162,7 +160,7 @@ describe('connectHitsPerPage', () => { ], }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { hitsPerPage: 7, }); helper.search = sinon.stub(); @@ -199,7 +197,7 @@ describe('connectHitsPerPage', () => { ], }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { hitsPerPage: 7, }); helper.search = sinon.stub(); @@ -243,11 +241,7 @@ describe('connectHitsPerPage', () => { ], }); - const helper = jsHelper( - { addAlgoliaAgent: () => {} }, - '', - widget.getConfiguration({}) - ); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/hits/__tests__/connectHits-test.js b/src/connectors/hits/__tests__/connectHits-test.js index 57c72da68c8..a574696ae02 100644 --- a/src/connectors/hits/__tests__/connectHits-test.js +++ b/src/connectors/hits/__tests__/connectHits-test.js @@ -5,8 +5,6 @@ const SearchResults = jsHelper.SearchResults; import connectHits from '../connectHits.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectHits', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -23,7 +21,7 @@ describe('connectHits', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper(fakeClient, '', {}); + const helper = jsHelper({}, '', {}); helper.search = sinon.stub(); widget.init({ @@ -61,7 +59,7 @@ describe('connectHits', () => { const makeWidget = connectHits(rendering); const widget = makeWidget({}); - const helper = jsHelper(fakeClient, '', {}); + const helper = jsHelper({}, '', {}); helper.search = sinon.stub(); widget.init({ @@ -97,7 +95,7 @@ describe('connectHits', () => { const makeWidget = connectHits(rendering); const widget = makeWidget({ escapeHits: true }); - const helper = jsHelper(fakeClient, '', {}); + const helper = jsHelper({}, '', {}); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js b/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js index ab677c2fa42..85cbc3382f0 100644 --- a/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js +++ b/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js @@ -5,8 +5,6 @@ const SearchResults = jsHelper.SearchResults; import connectInfiniteHits from '../connectInfiniteHits.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectInfiniteHits', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -26,7 +24,7 @@ describe('connectInfiniteHits', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper(fakeClient, ''); + const helper = jsHelper({}, ''); helper.search = sinon.stub(); widget.init({ @@ -70,7 +68,7 @@ describe('connectInfiniteHits', () => { const makeWidget = connectInfiniteHits(rendering); const widget = makeWidget(); - const helper = jsHelper(fakeClient, '', {}); + const helper = jsHelper({}, '', {}); helper.search = sinon.stub(); widget.init({ @@ -145,7 +143,7 @@ describe('connectInfiniteHits', () => { const makeWidget = connectInfiniteHits(rendering); const widget = makeWidget({ escapeHits: true }); - const helper = jsHelper(fakeClient, '', {}); + const helper = jsHelper({}, '', {}); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/menu/__tests__/connectMenu-test.js b/src/connectors/menu/__tests__/connectMenu-test.js index 302b8a0a4c5..2fa6451cf0d 100644 --- a/src/connectors/menu/__tests__/connectMenu-test.js +++ b/src/connectors/menu/__tests__/connectMenu-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectMenu from '../connectMenu.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectMenu', () => { let rendering; let makeWidget; @@ -86,7 +84,7 @@ describe('connectMenu', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -132,7 +130,7 @@ describe('connectMenu', () => { attributeName: 'category', }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); helper.toggleRefinement('category', 'value'); @@ -171,7 +169,7 @@ describe('connectMenu', () => { attributeName: 'category', }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); helper.toggleRefinement('category', 'Decoration'); @@ -271,7 +269,7 @@ describe('connectMenu', () => { // When const config = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -296,7 +294,7 @@ describe('connectMenu', () => { // When const config = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); helper.toggleRefinement('category', 'Decoration'); @@ -358,7 +356,7 @@ describe('connectMenu', () => { // When const config = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); helper.toggleRefinement('category', 'Decoration'); @@ -407,11 +405,7 @@ describe('connectMenu', () => { attributeName: 'category', }); - const helper = jsHelper( - { addAlgoliaAgent: () => {} }, - '', - widget.getConfiguration({}) - ); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/numeric-refinement-list/__tests__/connectNumericRefinementList-test.js b/src/connectors/numeric-refinement-list/__tests__/connectNumericRefinementList-test.js index 44d613e26de..7cc456f3d38 100644 --- a/src/connectors/numeric-refinement-list/__tests__/connectNumericRefinementList-test.js +++ b/src/connectors/numeric-refinement-list/__tests__/connectNumericRefinementList-test.js @@ -6,8 +6,6 @@ import jsHelper, { import connectNumericRefinementList from '../connectNumericRefinementList.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - const encodeValue = (start, end) => window.encodeURI(JSON.stringify({ start, end })); const mapOptionsToItems = ({ start, end, name: label }) => ({ @@ -36,7 +34,7 @@ describe('connectNumericRefinementList', () => { // test if widget is not rendered yet at this point expect(rendering.callCount).toBe(0); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -93,7 +91,7 @@ describe('connectNumericRefinementList', () => { ], }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -172,7 +170,7 @@ describe('connectNumericRefinementList', () => { ], }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -227,7 +225,7 @@ describe('connectNumericRefinementList', () => { options: listOptions, }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -278,7 +276,7 @@ describe('connectNumericRefinementList', () => { options: listOptions, }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -339,7 +337,7 @@ describe('connectNumericRefinementList', () => { options: listOptions, }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); widget.init({ @@ -383,7 +381,7 @@ describe('connectNumericRefinementList', () => { ], }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); helper.setPage(2); @@ -417,7 +415,7 @@ describe('connectNumericRefinementList', () => { ], }); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, ''); + const helper = jsHelper({}, ''); helper.search = () => {}; widget.init({ diff --git a/src/connectors/numeric-selector/__tests__/connectNumericSelector-test.js b/src/connectors/numeric-selector/__tests__/connectNumericSelector-test.js index 2db44051cdc..d43e215a6fc 100644 --- a/src/connectors/numeric-selector/__tests__/connectNumericSelector-test.js +++ b/src/connectors/numeric-selector/__tests__/connectNumericSelector-test.js @@ -5,8 +5,6 @@ import jsHelper, { import connectNumericSelector from '../connectNumericSelector.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectNumericSelector', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -35,7 +33,7 @@ describe('connectNumericSelector', () => { // test if widget is not rendered yet at this point expect(rendering).not.toHaveBeenCalled(); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -133,7 +131,7 @@ describe('connectNumericSelector', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -201,7 +199,7 @@ describe('connectNumericSelector', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -251,7 +249,7 @@ describe('connectNumericSelector', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -304,7 +302,7 @@ describe('connectNumericSelector', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/pagination/__tests__/connectPagination-test.js b/src/connectors/pagination/__tests__/connectPagination-test.js index 08f00a1bffc..d69388289bc 100644 --- a/src/connectors/pagination/__tests__/connectPagination-test.js +++ b/src/connectors/pagination/__tests__/connectPagination-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectPagination from '../connectPagination.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectPagination', () => { it('connectPagination - Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -22,7 +20,7 @@ describe('connectPagination', () => { // does not have a getConfiguration method expect(widget.getConfiguration).toBe(undefined); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -82,7 +80,7 @@ describe('connectPagination', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ @@ -124,7 +122,7 @@ describe('connectPagination', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); widget.init({ @@ -190,7 +188,7 @@ describe('connectPagination', () => { padding: 5, }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); widget.init({ @@ -254,7 +252,7 @@ describe('connectPagination', () => { const makeWidget = connectPagination(rendering); const widget = makeWidget({}); - const helper = jsHelper(fakeClient, ''); + const helper = jsHelper({}, ''); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/price-ranges/__tests__/connectPriceRanges-test.js b/src/connectors/price-ranges/__tests__/connectPriceRanges-test.js index 9351ee8bd84..e81e86881cc 100644 --- a/src/connectors/price-ranges/__tests__/connectPriceRanges-test.js +++ b/src/connectors/price-ranges/__tests__/connectPriceRanges-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectPriceRanges from '../connectPriceRanges.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectPriceRanges', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -25,7 +23,7 @@ describe('connectPriceRanges', () => { const config = widget.getConfiguration(); expect(config).toEqual({ facets: [attributeName] }); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -51,7 +49,8 @@ describe('connectPriceRanges', () => { { hits: [{ test: 'oneTime' }], facets: { price: { 10: 1, 20: 1, 30: 1 } }, - facets_stats: { // eslint-disable-line + // eslint-disable-next-line + facets_stats: { price: { avg: 20, max: 30, @@ -102,7 +101,7 @@ describe('connectPriceRanges', () => { attributeName, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -129,7 +128,8 @@ describe('connectPriceRanges', () => { { hits: [{ test: 'oneTime' }], facets: { price: { 10: 1, 20: 1, 30: 1 } }, - facets_stats: { // eslint-disable-line + // eslint-disable-next-line + facets_stats: { price: { avg: 20, max: 30, @@ -169,7 +169,7 @@ describe('connectPriceRanges', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/range/__tests__/connectRange-test.js b/src/connectors/range/__tests__/connectRange-test.js index e06a81eaa9e..28fb567b917 100644 --- a/src/connectors/range/__tests__/connectRange-test.js +++ b/src/connectors/range/__tests__/connectRange-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectRange from '../connectRange.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectRange', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -26,7 +24,7 @@ describe('connectRange', () => { disjunctiveFacets: [attributeName], }); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -134,7 +132,7 @@ describe('connectRange', () => { attributeName, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -201,7 +199,7 @@ describe('connectRange', () => { const attributeName = 'price'; const widget = makeWidget({ attributeName, min: 0, max: 500 }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -240,7 +238,7 @@ describe('connectRange', () => { indexName: 'movie', }); - const helper = jsHelper(fakeClient, '', configuration); + const helper = jsHelper({}, '', configuration); helper.search = sinon.stub(); widget.init({ @@ -276,7 +274,7 @@ describe('connectRange', () => { const attributeName = 'price'; const widget = makeWidget({ attributeName }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -524,7 +522,7 @@ describe('connectRange', () => { describe('_getCurrentRefinement', () => { const attributeName = 'price'; const rendering = () => {}; - const createHelper = () => jsHelper(fakeClient); + const createHelper = () => jsHelper({}); it('expect to return default refinement', () => { const widget = connectRange(rendering)({ attributeName }); @@ -567,7 +565,7 @@ describe('connectRange', () => { const attributeName = 'price'; const rendering = () => {}; const createHelper = () => { - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); const initialClearRefinements = helper.clearRefinements; helper.clearRefinements = jest.fn((...args) => @@ -918,7 +916,7 @@ describe('connectRange', () => { }); const config = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/refinement-list/__tests__/connectRefinementList-test.js b/src/connectors/refinement-list/__tests__/connectRefinementList-test.js index 9910bc015ef..00b1924a1ba 100644 --- a/src/connectors/refinement-list/__tests__/connectRefinementList-test.js +++ b/src/connectors/refinement-list/__tests__/connectRefinementList-test.js @@ -6,8 +6,6 @@ import { tagConfig } from '../../../lib/escape-highlight.js'; import connectRefinementList from '../connectRefinementList.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectRefinementList', () => { const createWidgetFactory = () => { const rendering = jest.fn(); @@ -106,7 +104,7 @@ describe('connectRefinementList', () => { // test if widget is not rendered yet at this point expect(rendering).not.toHaveBeenCalled(); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = jest.fn(); widget.init({ @@ -153,7 +151,7 @@ describe('connectRefinementList', () => { attributeName: 'category', }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); helper.toggleRefinement('category', 'value'); @@ -195,7 +193,7 @@ describe('connectRefinementList', () => { showMoreLimit: 10, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -241,7 +239,7 @@ describe('connectRefinementList', () => { limit: 1, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -292,7 +290,7 @@ describe('connectRefinementList', () => { showMoreLimit: 10, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -343,7 +341,7 @@ describe('connectRefinementList', () => { showMoreLimit: 10, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -397,7 +395,7 @@ describe('connectRefinementList', () => { showMoreLimit: 3, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -489,7 +487,7 @@ describe('connectRefinementList', () => { limit: 2, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); widget.init({ @@ -566,7 +564,7 @@ describe('connectRefinementList', () => { limit: 2, }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { ...widget.getConfiguration({}), maxValuesPerFacet: 3, }); @@ -647,7 +645,7 @@ describe('connectRefinementList', () => { limit: 2, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + const helper = jsHelper({}, '', widget.getConfiguration({})); helper.search = jest.fn(); helper.searchForFacetValues = jest.fn().mockReturnValue( Promise.resolve({ @@ -746,7 +744,7 @@ describe('connectRefinementList', () => { limit: 2, }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { ...widget.getConfiguration({}), // Here we simulate that another widget has set some highlight tags ...tagConfig, @@ -850,7 +848,7 @@ describe('connectRefinementList', () => { escapeFacetValues: true, }); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { ...widget.getConfiguration({}), // Here we simulate that another widget has set some highlight tags ...tagConfig, @@ -958,7 +956,7 @@ describe('connectRefinementList', () => { }); const initialConfig = widget.getConfiguration({}, {}); - const helper = jsHelper(fakeClient, '', initialConfig); + const helper = jsHelper({}, '', initialConfig); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/search-box/__tests__/connectSearchBox-test.js b/src/connectors/search-box/__tests__/connectSearchBox-test.js index e4683a58d38..888ee3d6bc7 100644 --- a/src/connectors/search-box/__tests__/connectSearchBox-test.js +++ b/src/connectors/search-box/__tests__/connectSearchBox-test.js @@ -5,8 +5,6 @@ import jsHelper, { import connectSearchBox from '../connectSearchBox.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectSearchBox', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -20,7 +18,7 @@ describe('connectSearchBox', () => { expect(widget.getConfiguration).toBe(undefined); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = () => {}; widget.init({ @@ -67,7 +65,7 @@ describe('connectSearchBox', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); widget.init({ @@ -111,7 +109,7 @@ describe('connectSearchBox', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient, '', { + const helper = jsHelper({}, '', { query: 'bup', }); helper.search = jest.fn(); @@ -166,7 +164,7 @@ describe('connectSearchBox', () => { queryHook, }); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); widget.init({ @@ -226,7 +224,7 @@ describe('connectSearchBox', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = () => {}; widget.init({ @@ -266,7 +264,7 @@ describe('connectSearchBox', () => { const widget = makeWidget(); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = jest.fn(); helper.setQuery('foobar'); @@ -296,7 +294,7 @@ describe('connectSearchBox', () => { }); const initialConfig = {}; - const helper = jsHelper(fakeClient, '', initialConfig); + const helper = jsHelper({}, '', initialConfig); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/sort-by-selector/__tests__/connectSortBySelector-test.js b/src/connectors/sort-by-selector/__tests__/connectSortBySelector-test.js index 3cc6ae330bc..4a8afaefd75 100644 --- a/src/connectors/sort-by-selector/__tests__/connectSortBySelector-test.js +++ b/src/connectors/sort-by-selector/__tests__/connectSortBySelector-test.js @@ -8,8 +8,6 @@ import jsHelper, { import connectSortBySelector from '../connectSortBySelector.js'; import instantSearch from '../../../lib/main.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectSortBySelector', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -20,7 +18,7 @@ describe('connectSortBySelector', () => { apiKey: '', appId: '', indexName: 'defaultIndex', - createAlgoliaClient: () => fakeClient, + createAlgoliaClient: () => ({}), }); const indices = [ @@ -31,7 +29,7 @@ describe('connectSortBySelector', () => { expect(widget.getConfiguration).toBe(undefined); - const helper = jsHelper(fakeClient, indices[0].name); + const helper = jsHelper({}, indices[0].name); helper.search = sinon.stub(); widget.init({ @@ -92,7 +90,7 @@ describe('connectSortBySelector', () => { apiKey: '', appId: '', indexName: 'defaultIndex', - createAlgoliaClient: () => fakeClient, + createAlgoliaClient: () => ({}), }); const indices = [ @@ -103,7 +101,7 @@ describe('connectSortBySelector', () => { indices, }); - const helper = jsHelper(fakeClient, indices[0].name); + const helper = jsHelper({}, indices[0].name); helper.search = sinon.stub(); widget.init({ @@ -152,7 +150,7 @@ describe('connectSortBySelector', () => { apiKey: '', appId: '', indexName: 'relevance', - createAlgoliaClient: () => fakeClient, + createAlgoliaClient: () => ({}), }); const indices = [ { label: 'Sort products by relevance', name: 'relevance' }, @@ -166,7 +164,7 @@ describe('connectSortBySelector', () => { }); const initialConfig = {}; - const helper = jsHelper(fakeClient, 'relevance', initialConfig); + const helper = jsHelper({}, 'relevance', initialConfig); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/star-rating/__tests__/connectStarRating-test.js b/src/connectors/star-rating/__tests__/connectStarRating-test.js index 1f83f6c47ae..8a3f3c6df19 100644 --- a/src/connectors/star-rating/__tests__/connectStarRating-test.js +++ b/src/connectors/star-rating/__tests__/connectStarRating-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectStarRating from '../connectStarRating.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectStarRating', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -26,7 +24,7 @@ describe('connectStarRating', () => { disjunctiveFacets: [attributeName], }); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -114,7 +112,7 @@ describe('connectStarRating', () => { const config = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -217,7 +215,7 @@ describe('connectStarRating', () => { }); const initialConfig = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', initialConfig); + const helper = jsHelper({}, '', initialConfig); helper.search = jest.fn(); widget.init({ diff --git a/src/connectors/stats/__tests__/connectStats-test.js b/src/connectors/stats/__tests__/connectStats-test.js index 4287bff8487..57cc2182ff0 100644 --- a/src/connectors/stats/__tests__/connectStats-test.js +++ b/src/connectors/stats/__tests__/connectStats-test.js @@ -5,8 +5,6 @@ const SearchResults = jsHelper.SearchResults; import connectStats from '../connectStats.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectStats', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -20,7 +18,7 @@ describe('connectStats', () => { expect(widget.getConfiguration).toEqual(undefined); - const helper = jsHelper(fakeClient); + const helper = jsHelper({}); helper.search = sinon.stub(); widget.init({ diff --git a/src/connectors/toggle/__tests__/connectToggle-test.js b/src/connectors/toggle/__tests__/connectToggle-test.js index 5186891c18d..b3e7da4d781 100644 --- a/src/connectors/toggle/__tests__/connectToggle-test.js +++ b/src/connectors/toggle/__tests__/connectToggle-test.js @@ -7,8 +7,6 @@ import jsHelper, { import connectToggle from '../connectToggle.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('connectToggle', () => { it('Renders during init and render', () => { // test that the dummyRendering is called with the isFirstRendering @@ -28,7 +26,7 @@ describe('connectToggle', () => { disjunctiveFacets: [attributeName], }); - const helper = jsHelper(fakeClient, '', config); + const helper = jsHelper({}, '', config); helper.search = sinon.stub(); widget.init({ @@ -73,8 +71,8 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line - 'false': 40, // eslint-disable-line + true: 45, + false: 40, }, }, nbHits: 85, @@ -122,7 +120,7 @@ describe('connectToggle', () => { label, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -169,8 +167,8 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line - 'false': 40, // eslint-disable-line + true: 45, + false: 40, }, }, nbHits: 85, @@ -214,7 +212,7 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line + true: 45, }, }, nbHits: 85, @@ -222,8 +220,8 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line - 'false': 40, // eslint-disable-line + true: 45, + false: 40, }, }, nbHits: 85, @@ -278,7 +276,7 @@ describe('connectToggle', () => { }, }); - const helper = jsHelper(fakeClient, '', widget.getConfiguration()); + const helper = jsHelper({}, '', widget.getConfiguration()); helper.search = sinon.stub(); widget.init({ @@ -326,7 +324,7 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'false': 40, // eslint-disable-line + false: 40, }, }, nbHits: 40, @@ -334,8 +332,8 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line - 'false': 40, // eslint-disable-line + true: 45, + false: 40, }, }, nbHits: 85, @@ -380,7 +378,7 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line + true: 45, }, }, nbHits: 85, @@ -388,8 +386,8 @@ describe('connectToggle', () => { { facets: { isShippingFree: { - 'true': 45, // eslint-disable-line - 'false': 40, // eslint-disable-line + true: 45, + false: 40, }, }, nbHits: 85, @@ -443,7 +441,7 @@ describe('connectToggle', () => { }); const initialConfig = widget.getConfiguration({}); - const helper = jsHelper(fakeClient, '', initialConfig); + const helper = jsHelper({}, '', initialConfig); helper.search = jest.fn(); widget.init({ diff --git a/src/lib/InstantSearch.js b/src/lib/InstantSearch.js index aa60a95ac41..13fa52a65d9 100644 --- a/src/lib/InstantSearch.js +++ b/src/lib/InstantSearch.js @@ -65,7 +65,10 @@ Usage: instantsearch({ } const client = createAlgoliaClient(algoliasearch, appId, apiKey); - client.addAlgoliaAgent(`instantsearch.js ${version}`); + + if (typeof client.addAlgoliaAgent === 'function') { + client.addAlgoliaAgent(`instantsearch.js ${version}`); + } this.client = client; this.helper = null; @@ -115,7 +118,7 @@ Usage: instantsearch({ } /** - * Add a widget. This can be done before and after InstantSearch has been started. Adding a + * Adds a widget. This can be done before and after InstantSearch has been started. Adding a * widget after InstantSearch started is considered **EXPERIMENTAL** and therefore * it is possibly buggy, if you find anything please * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20hot%20addWidget). @@ -129,7 +132,7 @@ Usage: instantsearch({ } /** - * Add multiple widgets. This can be done before and after the InstantSearch has been started. This feature + * Adds multiple widgets. This can be done before and after the InstantSearch has been started. This feature * is considered **EXPERIMENTAL** and therefore it is possibly buggy, if you find anything please * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20addWidgets). * @param {Widget[]} widgets The array of widgets to add to InstantSearch. @@ -188,7 +191,7 @@ Usage: instantsearch({ } /** - * Remove multiple widgets. This can be done only after the InstantSearch has been started. This feature + * Removes multiple widgets. This can be done only after the InstantSearch has been started. This feature * is considered **EXPERIMENTAL** and therefore it is possibly buggy, if you find anything please * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20addWidgets). * @param {Widget[]} widgets Array of widgets instances to remove from InstantSearch. @@ -244,7 +247,7 @@ Usage: instantsearch({ } /** - * The refresh method clears the cached answers from Algolia and triggers a new search. + * Clears the cached answers from Algolia and triggers a new search. * * @return {undefined} Does not return anything */ @@ -255,7 +258,7 @@ Usage: instantsearch({ } /** - * The start method ends the initialization of InstantSearch.js and triggers the + * Ends the initialization of InstantSearch.js and triggers the * first search. This method should be called after all widgets have been added * to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing * widgets after the start as an **EXPERIMENTAL** feature. @@ -311,8 +314,7 @@ Usage: instantsearch({ helper.search = () => { const helperSearchFunction = algoliasearchHelper( { - addAlgoliaAgent: () => {}, - search: () => {}, + search: () => new Promise(() => {}), }, helper.state.index, helper.state @@ -356,7 +358,7 @@ Usage: instantsearch({ } /** - * Remove all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature, + * Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature, * if you find an issue with it, please * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose). * @return {undefined} This method does not return anything diff --git a/src/lib/RoutingManager.js b/src/lib/RoutingManager.js index 7f9a46798a9..4f980c0aaef 100644 --- a/src/lib/RoutingManager.js +++ b/src/lib/RoutingManager.js @@ -27,7 +27,7 @@ export default class RoutingManager { // like hierarchicalFacet.rootPath are then triggering a default refinement that would // be not present if it was not going trough the SearchParameters constructor this.originalConfig = algoliasearchHelper( - { addAlgoliaAgent() {} }, + {}, currentConfiguration.index, currentConfiguration ).state; diff --git a/src/lib/__tests__/InstantSearch-test-2.js b/src/lib/__tests__/InstantSearch-test-2.js index b5cca682c0a..62b4f279725 100644 --- a/src/lib/__tests__/InstantSearch-test-2.js +++ b/src/lib/__tests__/InstantSearch-test-2.js @@ -14,8 +14,7 @@ describe('InstantSearch life cycle', () => { }); const fakeClient = { - search: jest.fn(), - addAlgoliaAgent: () => {}, + search: jest.fn(() => Promise.resolve({ results: [{}] })), }; const search = new InstantSearch({ @@ -54,18 +53,13 @@ describe('InstantSearch life cycle', () => { }); it('triggers the stalled search rendering once if the search does not resolve in time', () => { - const searchResultsResolvers = []; const searchResultsPromises = []; const fakeClient = { - search: jest.fn((qs, cb) => { - const p = new Promise(resolve => - searchResultsResolvers.push(resolve) - ).then(() => { - cb(null, fakeResults()); - }); - searchResultsPromises.push(p); + search: jest.fn(() => { + const results = Promise.resolve(fakeResults()); + searchResultsPromises.push(results); + return results; }), - addAlgoliaAgent: () => {}, }; const search = new InstantSearch({ @@ -95,9 +89,6 @@ describe('InstantSearch life cycle', () => { expect(widget.init).toHaveBeenCalledTimes(1); expect(widget.render).not.toHaveBeenCalled(); - // first results come back - searchResultsResolvers[0](); - return searchResultsPromises[0].then(() => { // render has now been called expect(widget.render).toHaveBeenCalledTimes(1); @@ -126,7 +117,6 @@ describe('InstantSearch life cycle', () => { }) ); - searchResultsResolvers[1](); return searchResultsPromises[1].then(() => { expect(widget.render).toHaveBeenCalledTimes(3); expect(widget.render).toHaveBeenLastCalledWith( @@ -150,8 +140,7 @@ describe('InstantSearch life cycle', () => { }); const fakeClient = { - search: jest.fn(), - addAlgoliaAgent: () => {}, + search: jest.fn(() => Promise.resolve({ results: [{}] })), }; const search = new InstantSearch({ @@ -170,4 +159,24 @@ describe('InstantSearch life cycle', () => { jest.runAllTimers(); }); + + it('does not break when providing searchFunction with multiple resquests', () => { + const search = new InstantSearch({ + appId, + apiKey, + indexName, + searchFunction: h => { + h.addDisjunctiveFacetRefinement('brand', 'Apple'); + h.search(); + }, + searchParameters: { + disjunctiveFacetsRefinements: { brand: ['Apple'] }, + disjunctiveFacets: ['brand'], + }, + }); + + expect(() => { + search.start(); + }).not.toThrow(); + }); }); diff --git a/src/lib/__tests__/InstantSearch-test.js b/src/lib/__tests__/InstantSearch-test.js index 70657607475..9c18b58c663 100644 --- a/src/lib/__tests__/InstantSearch-test.js +++ b/src/lib/__tests__/InstantSearch-test.js @@ -19,7 +19,7 @@ describe('InstantSearch lifecycle', () => { let urlSync; beforeEach(() => { - client = { algolia: 'client', addAlgoliaAgent: () => {} }; + client = { algolia: 'client' }; helper = algoliaSearchHelper(client); // when using searchFunction, we lose the reference to diff --git a/src/lib/__tests__/RoutingManager-test.js b/src/lib/__tests__/RoutingManager-test.js index 04f6549a241..5a7bfe25c49 100644 --- a/src/lib/__tests__/RoutingManager-test.js +++ b/src/lib/__tests__/RoutingManager-test.js @@ -3,8 +3,7 @@ import RoutingManager from '../RoutingManager.js'; import simpleMapping from '../stateMappings/simple.js'; const makeFakeAlgoliaClient = () => ({ - addAlgoliaAgent: () => {}, - search: () => {}, + search: () => Promise.resolve({ results: [{}] }), }); describe('RoutingManager', () => { diff --git a/src/lib/__tests__/__snapshots__/InstantSearch-test.js.snap b/src/lib/__tests__/__snapshots__/InstantSearch-test.js.snap index d8c4e181c76..09bcd21de5b 100644 --- a/src/lib/__tests__/__snapshots__/InstantSearch-test.js.snap +++ b/src/lib/__tests__/__snapshots__/InstantSearch-test.js.snap @@ -15,7 +15,6 @@ Array [ "_lastQueryIdReceived": -1, "_queryId": 0, "client": Object { - "addAlgoliaAgent": [Function], "algolia": "client", }, "derivedHelpers": Array [], @@ -88,7 +87,6 @@ Array [ "_searchStalledTimer": null, "_stalledSearchDelay": 200, "client": Object { - "addAlgoliaAgent": [Function], "algolia": "client", }, "domain": null, @@ -103,7 +101,6 @@ Array [ "_lastQueryIdReceived": -1, "_queryId": 0, "client": Object { - "addAlgoliaAgent": [Function], "algolia": "client", }, "derivedHelpers": Array [], diff --git a/src/lib/__tests__/url-sync-test.js b/src/lib/__tests__/url-sync-test.js index 2dd982fa8a6..d6a7faa2a94 100644 --- a/src/lib/__tests__/url-sync-test.js +++ b/src/lib/__tests__/url-sync-test.js @@ -25,7 +25,7 @@ const makeTestUrlUtils = () => ({ describe('urlSync mechanics', () => { test('Generates urls on change', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); const urlUtils = makeTestUrlUtils(); const urlSyncWidget = urlSync({ urlUtils, threshold: 0 }); urlSyncWidget.init({ state: SearchParameters.make({}) }); @@ -40,7 +40,7 @@ describe('urlSync mechanics', () => { expect(urlUtils.lastQs).toMatchSnapshot(); }); test('Generated urls should not contain a version', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); const urlUtils = makeTestUrlUtils(); const urlSyncWidget = urlSync({ urlUtils, threshold: 0 }); urlSyncWidget.init({ state: SearchParameters.make({}) }); @@ -52,7 +52,7 @@ describe('urlSync mechanics', () => { expect(urlUtils.lastQs).not.toEqual(expect.stringContaining('is_v')); }); test('updates the URL during the first rendering if it has change since the initial configuration', () => { - const helper = jsHelper({ addAlgoliaAgent: () => {} }); + const helper = jsHelper({}); const urlUtils = makeTestUrlUtils(); const urlSyncWidget = urlSync({ urlUtils, threshold: 0 }); urlSyncWidget.init({ state: SearchParameters.make({}) }); diff --git a/src/lib/__tests__/utils-test.js b/src/lib/__tests__/utils-test.js index 448fac8be19..aa2e97e1079 100644 --- a/src/lib/__tests__/utils-test.js +++ b/src/lib/__tests__/utils-test.js @@ -291,7 +291,7 @@ describe('utils.getRefinements', () => { let results; beforeEach(() => { - helper = algoliasearchHelper({ addAlgoliaAgent: () => {} }, 'my_index', { + helper = algoliasearchHelper({}, 'my_index', { facets: ['facet1', 'facet2', 'numericFacet1'], disjunctiveFacets: [ 'disjunctiveFacet1', @@ -871,7 +871,7 @@ describe('utils.clearRefinementsFromState', () => { let state; beforeEach(() => { - helper = algoliasearchHelper({ addAlgoliaAgent: () => {} }, 'my_index', { + helper = algoliasearchHelper({}, 'my_index', { facets: ['facet1', 'facet2', 'numericFacet1', 'facetExclude1'], disjunctiveFacets: ['disjunctiveFacet1', 'numericDisjunctiveFacet'], hierarchicalFacets: [ diff --git a/src/lib/main.js b/src/lib/main.js index 50573bcb7a2..44b93883956 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -27,26 +27,26 @@ import * as stateMappings from './stateMappings/index.js'; * @property {Object} [mapping] Object used to define replacement query * parameter to use in place of another. Keys are current query parameters * and value the new value, e.g. `{ q: 'query' }`. - * @property {number} [threshold] Idle time in ms after which a new - * state is created in the browser history. The default value is 700. The url is always updated at each keystroke + * @property {number} [threshold=700] Idle time in ms after which a new + * state is created in the browser history. The URL is always updated at each keystroke * but we only create a "previous search state" (activated when click on back button) every 700ms of idle time. * @property {string[]} [trackedParameters] Parameters that will * be synchronized in the URL. Default value is `['query', 'attribute:*', * 'index', 'page', 'hitsPerPage']`. `attribute:*` means all the faceting attributes will be tracked. You - * can track only some of them by using [..., 'attribute:color', 'attribute:categories']. All other possible + * can track only some of them by using `[..., 'attribute:color', 'attribute:categories']`. All other possible * values are all the [attributes of the Helper SearchParameters](https://community.algolia.com/algoliasearch-helper-js/reference.html#searchparameters). - * @property {boolean} [useHash] If set to true, the url will be + * @property {boolean} [useHash] If set to `true`, the URL will be * hash based. Otherwise, it'll use the query parameters using the modern * history API. * @property {function} [getHistoryState] Pass this function to override the - * default history API state we set to `null`. For example this could be used to force passing - * {turbolinks: true} to the history API every time we update it. + * default history API state we set to `null`. For example, this could be used to force passing + * `{turbolinks: true}` to the history API every time we update it. */ /** * @typedef {Object|boolean} RoutingOptions * @property {Router} [router=HistoryRouter()] The router is the part that will save the UI State. - * By default, it uses an instance of the HistoryRouter with the default parameters. + * By default, it uses an instance of the `HistoryRouter` with the default parameters. * @property {StateMapping} [stateMapping=SimpleStateMapping()] This object transforms the UI state into * the object that willl be saved by the router. */ @@ -56,27 +56,27 @@ import * as stateMappings from './stateMappings/index.js'; * and filter out the properties. To work correctly, for any state ui S, the following should be valid: * `S = routeToState(stateToRoute(S))`. * @typedef {Object} StateMapping - * @property {function} stateToRoute transforms an UI state representation into a route object. - * It receives an object that contains the UI State of all the widget in the page. It should - * return an object of any form. As long as this form can be read by the `routeToState`. - * @property {function} routeToState transforms route object into an UI state representation. - * It receives an object that contains the UI State stored by the router. The format is the output + * @property {function} stateToRoute Transforms a UI state representation into a route object. + * It receives an object that contains the UI state of all the widgets in the page. It should + * return an object of any form as long as this form can be read by the `routeToState`. + * @property {function} routeToState Transforms route object into a UI state representation. + * It receives an object that contains the UI state stored by the router. The format is the output * of `stateToRoute`. */ /** * The router is the part that saves and reads the object from the storage (most of the time the URL). * @typedef {Object} Router - * @property {function} onUpdate sets an event listener that is triggered when the storage is updated. + * @property {function} onUpdate Sets an event listener that is triggered when the storage is updated. * The function should accept a callback to trigger when the update happens. In the case of the history * / URL in a browser, the callback will be called by `onPopState`. - * @property {function} read reads the storage and gets a route object. It does not take parameters, + * @property {function} read Reads the storage and gets a route object. It does not take parameters, * and should return an object. - * @property {function} write push a route object into a storage. Takes the UI state mapped by the state + * @property {function} write Pushes a route object into a storage. Takes the UI state mapped by the state * mapping configured in the mapping. - * @property {function} createURL transforms a route object into a URL. It receives an object and should + * @property {function} createURL Transforms a route object into a URL. It receives an object and should * return a string. It may return an empty string. - * @property {function} dispose cleans up any event listeners. + * @property {function} dispose Cleans up any event listeners. */ /** @@ -87,10 +87,10 @@ import * as stateMappings from './stateMappings/index.js'; * @property {string} [numberLocale] The locale used to display numbers. This will be passed * to [`Number.prototype.toLocaleString()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) * @property {function} [searchFunction] A hook that will be called each time a search needs to be done, with the - * helper as a parameter. It's your responsibility to call helper.search(). This option allows you to avoid doing + * helper as a parameter. It's your responsibility to call `helper.search()`. This option allows you to avoid doing * searches at page load for example. * @property {function} [createAlgoliaClient] Allows you to provide your own algolia client instead of - * the one instantiated internally by instantsearch.js. Useful in situations where you need + * the one instantiated internally by InstantSearch.js. Useful in situations where you need * to setup complex mechanism on the client or if you need to share it easily. * Usage: * ```javascript @@ -101,22 +101,23 @@ import * as stateMappings from './stateMappings/index.js'; * } * }); * ``` - * We forward `algoliasearch` which is the original algoliasearch module imported inside instantsearch.js + * We forward `algoliasearch`, which is the original [Algolia search client](https://www.algolia.com/doc/api-client/javascript/getting-started) imported inside InstantSearch.js * @property {object} [searchParameters] Additional parameters to pass to - * the Algolia API. - * [Full documentation](https://community.algolia.com/algoliasearch-helper-js/reference.html#searchparameters) - * @property {boolean|UrlSyncOptions} [urlSync] Url synchronization configuration. - * Setting to `true` will synchronize the needed search parameters with the browser url. + * the Algolia API ([see full documentation](https://community.algolia.com/algoliasearch-helper-js/reference.html#searchparameters)). + * @property {boolean|UrlSyncOptions} [urlSync] _Deprecated in favor of [`routing`](instantsearch.html#struct-InstantSearchOptions-routing)._ + * + * URL synchronization configuration. + * Setting to `true` will synchronize the needed search parameters with the browser URL. * @property {number} [stalledSearchDelay=200] Time before a search is considered stalled. - * @property {RoutingOptions} [routing] the router configuration used to save the UI State into the URL or + * @property {RoutingOptions} [routing] Router configuration used to save the UI State into the URL or * any client side persistence. */ /** * InstantSearch is the main component of InstantSearch.js. This object - * manages the widget and let you add new ones. + * manages the widget and lets you add new ones. * - * Three parameters are required to get you started with instantsearch.js: + * Three parameters are required to get you started with InstantSearch.js: * - `appId`: your algolia application id * - `apiKey`: the search key associated with your application * - `indexName`: the main index that you will use for your new search UI diff --git a/src/lib/url-sync.js b/src/lib/url-sync.js index 9b56cd74068..1e22349f6fb 100644 --- a/src/lib/url-sync.js +++ b/src/lib/url-sync.js @@ -127,7 +127,7 @@ class URLSync { // like hierarchicalFacet.rootPath are then triggering a default refinement that would // be not present if it was not going trough the SearchParameters constructor this.originalConfig = algoliasearchHelper( - { addAlgoliaAgent() {} }, + {}, currentConfiguration.index, currentConfiguration ).state; diff --git a/src/lib/version.js b/src/lib/version.js index 909f43764d6..3057f4f8169 100644 --- a/src/lib/version.js +++ b/src/lib/version.js @@ -1 +1 @@ -export default '2.7.1'; +export default '2.7.4'; diff --git a/src/widgets/geo-search/__tests__/geo-search-test.js b/src/widgets/geo-search/__tests__/geo-search-test.js index 75c9d094895..5e2df6b7d85 100644 --- a/src/widgets/geo-search/__tests__/geo-search-test.js +++ b/src/widgets/geo-search/__tests__/geo-search-test.js @@ -94,9 +94,8 @@ describe('GeoSearch', () => { const createFakeHelper = () => algoliasearchHelper( { - search() {}, - addAlgoliaAgent() { - return {}; + search() { + return Promise.resolve({ results: [{}] }); }, }, 'indexName' diff --git a/src/widgets/geo-search/geo-search.js b/src/widgets/geo-search/geo-search.js index c65ff497db8..18e2246e6f5 100644 --- a/src/widgets/geo-search/geo-search.js +++ b/src/widgets/geo-search/geo-search.js @@ -124,6 +124,8 @@ Full documentation available at https://community.algolia.com/instantsearch.js/v * * You are also responsible for loading the Google Maps library, it's not shipped with InstantSearch. You need to load the Google Maps library and pass a reference to the widget. You can find more information about how to install the library in [the Google Maps documentation](https://developers.google.com/maps/documentation/javascript/tutorial). * + * Don't forget to explicitly set the `height` of the map container (default class `.ais-geo-search--map`), otherwise it won't be shown (it's a requirement of Google Maps). + * * @type {WidgetFactory} * @devNovel GeoSearch * @param {GeoSearchWidgetOptions} $0 Options of the GeoSearch widget. diff --git a/src/widgets/infinite-hits/__tests__/infinite-hits-test.js b/src/widgets/infinite-hits/__tests__/infinite-hits-test.js index c20cbfb6320..00af87acfb4 100644 --- a/src/widgets/infinite-hits/__tests__/infinite-hits-test.js +++ b/src/widgets/infinite-hits/__tests__/infinite-hits-test.js @@ -17,7 +17,7 @@ describe('infiniteHits()', () => { let helper; beforeEach(() => { - helper = algoliasearchHelper({ addAlgoliaAgent: () => {} }); + helper = algoliasearchHelper({}); helper.search = sinon.spy(); ReactDOM = { render: sinon.spy() }; diff --git a/src/widgets/menu/menu.js b/src/widgets/menu/menu.js index 9afe437f12b..9509cda38ce 100644 --- a/src/widgets/menu/menu.js +++ b/src/widgets/menu/menu.js @@ -130,7 +130,7 @@ menu({ * * You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax). * @property {MenuTemplates} [templates] Customize the output through templating. - * @property {string} [limit=10] How many facets values to retrieve. + * @property {number} [limit=10] How many facets values to retrieve. * @property {boolean|MenuShowMoreOptions} [showMore=false] Limit the number of results and display a showMore button. * @property {MenuShowMoreTemplates} [templates] Templates to use for the widget. * @property {MenuTransforms} [transformData] Set of functions to update the data before passing them to the templates. diff --git a/src/widgets/range-input/__tests__/range-input-test.js b/src/widgets/range-input/__tests__/range-input-test.js index 0a93a172900..c56142a36f3 100644 --- a/src/widgets/range-input/__tests__/range-input-test.js +++ b/src/widgets/range-input/__tests__/range-input-test.js @@ -17,9 +17,8 @@ describe('rangeInput', () => { const createHelper = () => new AlgoliasearchHelper( { - search() {}, - addAlgoliaAgent() { - return {}; + search() { + return Promise.resolve({ results: [{}] }); }, }, 'indexName', diff --git a/src/widgets/range-slider/__tests__/range-slider-test.js b/src/widgets/range-slider/__tests__/range-slider-test.js index 83f1aaffe0a..479ec09a6f6 100644 --- a/src/widgets/range-slider/__tests__/range-slider-test.js +++ b/src/widgets/range-slider/__tests__/range-slider-test.js @@ -30,9 +30,8 @@ describe('rangeSlider', () => { container = document.createElement('div'); helper = new AlgoliasearchHelper( { - search() {}, - addAlgoliaAgent() { - return {}; + search() { + return Promise.resolve({ results: [{}] }); }, }, 'indexName', diff --git a/src/widgets/sort-by-selector/__tests__/sort-by-selector-test.js b/src/widgets/sort-by-selector/__tests__/sort-by-selector-test.js index 007212e9e8f..f88ded71bb1 100644 --- a/src/widgets/sort-by-selector/__tests__/sort-by-selector-test.js +++ b/src/widgets/sort-by-selector/__tests__/sort-by-selector-test.js @@ -5,8 +5,6 @@ import Selector from '../../../components/Selector'; import instantSearch from '../../../lib/main.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; - describe('sortBySelector call', () => { it('throws an exception when no options', () => { const container = document.createElement('div'); @@ -34,7 +32,7 @@ describe('sortBySelector()', () => { apiKey: '', appId: '', indexName: 'defaultIndex', - createAlgoliaClient: () => fakeClient, + createAlgoliaClient: () => ({}), }); autoHideContainer = sinon.stub().returns(Selector); ReactDOM = { render: sinon.spy() }; diff --git a/src/widgets/star-rating/__tests__/star-rating-test.js b/src/widgets/star-rating/__tests__/star-rating-test.js index b6446455995..5167dfd0488 100644 --- a/src/widgets/star-rating/__tests__/star-rating-test.js +++ b/src/widgets/star-rating/__tests__/star-rating-test.js @@ -6,7 +6,6 @@ import jsHelper from 'algoliasearch-helper'; import defaultLabels from '../../../widgets/star-rating/defaultLabels.js'; import starRating from '../star-rating.js'; -const fakeClient = { addAlgoliaAgent: () => {} }; const SearchResults = jsHelper.SearchResults; describe('starRating()', () => { @@ -30,7 +29,7 @@ describe('starRating()', () => { attributeName, cssClasses: { body: ['body', 'cx'] }, }); - helper = jsHelper(fakeClient, '', widget.getConfiguration({})); + helper = jsHelper({}, '', widget.getConfiguration({})); sinon.spy(helper, 'clearRefinements'); sinon.spy(helper, 'addDisjunctiveFacetRefinement'); sinon.spy(helper, 'getRefinements'); @@ -155,7 +154,7 @@ describe('starRating()', () => { attributeName, cssClasses: { body: ['body', 'cx'] }, }); - const _helper = jsHelper(fakeClient, '', _widget.getConfiguration({})); + const _helper = jsHelper({}, '', _widget.getConfiguration({})); _helper.search = sinon.stub(); _widget.init({ diff --git a/src/widgets/toggle/__tests__/currentToggle-test.js b/src/widgets/toggle/__tests__/currentToggle-test.js index a9170bcf9a6..db49d2bfcbf 100644 --- a/src/widgets/toggle/__tests__/currentToggle-test.js +++ b/src/widgets/toggle/__tests__/currentToggle-test.js @@ -230,7 +230,7 @@ describe('currentToggle()', () => { }); const config = widget.getConfiguration(); - const altHelper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const altHelper = jsHelper({}, '', config); altHelper.search = () => {}; widget.init({ @@ -471,7 +471,7 @@ describe('currentToggle()', () => { }); const config = widget.getConfiguration(); - const altHelper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const altHelper = jsHelper({}, '', config); altHelper.search = () => {}; const createURL = () => '#'; @@ -543,7 +543,7 @@ describe('currentToggle()', () => { values: userValues, }); const config = widget.getConfiguration(); - const helper = jsHelper({ addAlgoliaAgent: () => {} }, '', config); + const helper = jsHelper({}, '', config); // When widget.init({ diff --git a/yarn.lock b/yarn.lock index 871bca32d18..2d3c0238170 100644 --- a/yarn.lock +++ b/yarn.lock @@ -188,16 +188,36 @@ ajv@^6.1.0: fast-json-stable-stringify "^2.0.0" json-schema-traverse "^0.3.0" -algoliasearch-helper@2.24.0: - version "2.24.0" - resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-2.24.0.tgz#6ebf91683a82799bc4019ee1ad92d0ad0f41167b" +algoliasearch-helper@2.26.0: + version "2.26.0" + resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-2.26.0.tgz#cb784b692a5aacf17062493cb0b94f6d60d30d0f" dependencies: - events "^1.1.0" - lodash "^4.13.1" - qs "^6.2.1" + events "^1.1.1" + lodash "^4.17.5" + qs "^6.5.1" util "^0.10.3" -algoliasearch@3.25.1, algoliasearch@^3.24.0: +algoliasearch@3.27.0: + version "3.27.0" + resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-3.27.0.tgz#675b7f2d186e5785a1553369b15d47b53d4efb31" + dependencies: + agentkeepalive "^2.2.0" + debug "^2.6.8" + envify "^4.0.0" + es6-promise "^4.1.0" + events "^1.1.0" + foreach "^2.0.5" + global "^4.3.2" + inherits "^2.0.1" + isarray "^2.0.1" + load-script "^1.0.0" + object-keys "^1.0.11" + querystring-es3 "^0.2.1" + reduce "^1.0.1" + semver "^5.1.0" + tunnel-agent "^0.6.0" + +algoliasearch@^3.24.0: version "3.25.1" resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-3.25.1.tgz#e543108b528e5c89338834473cb8fb082d13d11f" dependencies: @@ -8089,7 +8109,7 @@ q@^1.1.2, q@^1.4.1, q@^1.5.1, q@~1.5.0: version "1.5.1" resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" -qs@6.5.1, qs@^6.2.1, qs@^6.4.0, qs@~6.5.1: +qs@6.5.1, qs@^6.4.0, qs@^6.5.1, qs@~6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"