diff --git a/packages/algoliasearch-helper/README.md b/packages/algoliasearch-helper/README.md index 4e35999d8e..a1e90730ed 100644 --- a/packages/algoliasearch-helper/README.md +++ b/packages/algoliasearch-helper/README.md @@ -111,9 +111,9 @@ angular.module('searchApp', ['ngSanitize', 'algoliasearch']) $scope.content = event.results; }); }); - $scope.toggleRefine = function($event, facet, value) { + $scope.toggleFacetRefinement = function($event, facet, value) { $event.preventDefault(); - $scope.helper.toggleRefine(facet, value).search(); + $scope.helper.toggleFacetRefinement(facet, value).search(); }; $scope.$watch('q', function(q) { $scope.helper.setQuery(q).search(); diff --git a/packages/algoliasearch-helper/documentation-src/content/reference.md b/packages/algoliasearch-helper/documentation-src/content/reference.md index 861316106e..795908b4fd 100644 --- a/packages/algoliasearch-helper/documentation-src/content/reference.md +++ b/packages/algoliasearch-helper/documentation-src/content/reference.md @@ -385,8 +385,6 @@ The facet exclusions are not a type of facets by themselves, they are conjunctiv {{> jsdoc jsdoc/helper/hasRefinements}} -{{> jsdoc jsdoc/helper/isExcluded}} - ### Numeric filters The numeric filters don't require any configuration. However they require that the attribute is stored as a number in Algolia. @@ -409,8 +407,6 @@ The tag filters don't require any configuration. However, they require to be sto {{> jsdoc jsdoc/helper/toggleTag}} -{{> jsdoc jsdoc/helper/hasTag}} - {{> jsdoc jsdoc/helper/getTags}} ### State management diff --git a/packages/algoliasearch-helper/index.d.ts b/packages/algoliasearch-helper/index.d.ts index a24ec530cb..415202dfc9 100644 --- a/packages/algoliasearch-helper/index.d.ts +++ b/packages/algoliasearch-helper/index.d.ts @@ -237,10 +237,6 @@ declare namespace algoliasearchHelper { setIndex(name: string): this; addDisjunctiveFacetRefinement(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement} - */ - addDisjunctiveRefine(facet: string, value: string): this; addHierarchicalFacetRefinement(facet: string, path: string): this; addNumericRefinement( facet: string, @@ -248,15 +244,7 @@ declare namespace algoliasearchHelper { value?: number | number[] ): this; addFacetRefinement(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement} - */ - addRefine: AlgoliaSearchHelper['addFacetRefinement']; addFacetExclusion(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion} - */ - addExclude: AlgoliaSearchHelper['addFacetExclusion']; addTag(tag: string): this; addFrequentlyBoughtTogether( params: RecommendParametersWithId @@ -279,21 +267,9 @@ declare namespace algoliasearchHelper { value?: number | number[] ): this; removeDisjunctiveFacetRefinement(facet: string, value?: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement} - */ - removeDisjunctiveRefine(facet: string, value?: string): this; removeHierarchicalFacetRefinement(facet: string): this; removeFacetRefinement(facet: string, value?: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement} - */ - removeRefine(facet: string, value: string): this; removeFacetExclusion(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion} - */ - removeExclude(facet: string, value: string): this; removeTag(value: string): this; removeFrequentlyBoughtTogether(id: number): this; removeRelatedProducts(id: number): this; @@ -301,27 +277,11 @@ declare namespace algoliasearchHelper { removeTrendingFacets(id: number): this; removeLookingSimilar(id: number): this; toggleFacetExclusion(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion} - */ - toggleExclude(facet: string, value: string): this; toggleFacetRefinement(facet: string, value: string): this; - /** - * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement} - */ - toggleRefinement(facet: string, value: string): this; - /** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement} - */ - toggleRefine(facet: string, value: string): this; toggleTag(tag: string): this; nextPage(): this; previousPage(): this; setPage(page: number): this; - /** - * @deprecated - */ - setCurrentPage(page: number): this; setQueryParameter( parameter: SearchParameter, value: PlainSearchParameters[SearchParameter] @@ -338,30 +298,12 @@ declare namespace algoliasearchHelper { overrideStateWithoutTriggeringChangeEvent: AlgoliaSearchHelper['setState']; hasRefinements(facet: string): boolean; - isExcluded: SearchParameters['isExcludeRefined']; - /** - * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements} - */ - isDisjunctiveRefined: SearchParameters['isDisjunctiveFacetRefined']; - hasTag: SearchParameters['isTagRefined']; - /** - * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag} - */ - isTagRefined: SearchParameters['isTagRefined']; getIndex(): string; - /** - * @deprecated - */ - getCurrentPage(): number; getPage(): number; getTags(): string[]; getRefinements(facetName: string): any[]; getNumericRefinement: SearchParameters['getNumericRefinement']; getHierarchicalFacetBreadcrumb: SearchParameters['getHierarchicalFacetBreadcrumb']; - /** - * @deprecated - */ - containsRefinement(...any: any[]): any; clearCache(): this; setClient(client: SearchClient): this; getClient(): SearchClient; @@ -1382,14 +1324,6 @@ declare namespace algoliasearchHelper { options?: SearchResultsOptions ); - /** - * Get a facet object with its name - * @deprecated - * @param name name of the faceted attribute - * @return the facet object - */ - getFacetByName(name: string): SearchResults.Facet; - /** * Get a the list of values for a given facet attribute. Those values are sorted * refinement first, descending count (bigger value on top), and name ascending diff --git a/packages/algoliasearch-helper/src/SearchParameters/index.js b/packages/algoliasearch-helper/src/SearchParameters/index.js index 87bedb044a..4f860077c4 100644 --- a/packages/algoliasearch-helper/src/SearchParameters/index.js +++ b/packages/algoliasearch-helper/src/SearchParameters/index.js @@ -1049,18 +1049,6 @@ SearchParameters.prototype = { return this.setQueryParameters(modification); }, - /** - * Generic toggle refinement method to use with facet, disjunctive facets - * and hierarchical facets - * @param {string} facet the facet to refine - * @param {string} value the associated value - * @return {SearchParameters} new instance - * @throws will throw an error if the facet is not declared in the settings of the helper - * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement} - */ - toggleRefinement: function toggleRefinement(facet, value) { - return this.toggleFacetRefinement(facet, value); - }, /** * Generic toggle refinement method to use with facet, disjunctive facets * and hierarchical facets @@ -1190,11 +1178,11 @@ SearchParameters.prototype = { this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && // remove current refinement: - // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer` + // refinement was 'beer > IPA', call is toggleFacetRefinement('beer > IPA'), refinement should be `beer` (this.hierarchicalFacetsRefinements[facet][0] === value || // remove a parent refinement of the current refinement: // - refinement was 'beer > IPA > Flying dog' - // - call is toggleRefine('beer > IPA') + // - call is toggleFacetRefinement('beer > IPA') // - refinement should be `beer` this.hierarchicalFacetsRefinements[facet][0].indexOf( value + separator diff --git a/packages/algoliasearch-helper/src/SearchResults/index.js b/packages/algoliasearch-helper/src/SearchResults/index.js index 6d0b044766..9d3e375a3a 100644 --- a/packages/algoliasearch-helper/src/SearchResults/index.js +++ b/packages/algoliasearch-helper/src/SearchResults/index.js @@ -660,24 +660,6 @@ function SearchResults(state, results, options) { this._state = state; } -/** - * Get a facet object with its name - * @deprecated - * @param {string} name name of the faceted attribute - * @return {SearchResults.Facet} the facet object - */ -SearchResults.prototype.getFacetByName = function (name) { - function predicate(facet) { - return facet.name === name; - } - - return ( - find(this.facets, predicate) || - find(this.disjunctiveFacets, predicate) || - find(this.hierarchicalFacets, predicate) - ); -}; - /** * Get the facet values of a specified attribute from a SearchResults object. * @private diff --git a/packages/algoliasearch-helper/src/algoliasearch.helper.js b/packages/algoliasearch-helper/src/algoliasearch.helper.js index 0bdd5f386b..9adb88fc89 100644 --- a/packages/algoliasearch-helper/src/algoliasearch.helper.js +++ b/packages/algoliasearch-helper/src/algoliasearch.helper.js @@ -498,14 +498,6 @@ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function ( return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement} - */ -AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () { - return this.addDisjunctiveFacetRefinement.apply(this, arguments); -}; - /** * Adds a refinement on a hierarchical facet. It will throw * an exception if the facet is not defined or if the facet @@ -578,14 +570,6 @@ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement} - */ -AlgoliaSearchHelper.prototype.addRefine = function () { - return this.addFacetRefinement.apply(this, arguments); -}; - /** * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the * filter is already set, it doesn't change the filters. @@ -606,14 +590,6 @@ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion} - */ -AlgoliaSearchHelper.prototype.addExclude = function () { - return this.addFacetExclusion.apply(this, arguments); -}; - /** * Adds a tag filter with the `tag` provided. If the * filter is already set, it doesn't change the filters. @@ -774,14 +750,6 @@ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function ( return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement} - */ -AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () { - return this.removeDisjunctiveFacetRefinement.apply(this, arguments); -}; - /** * Removes the refinement set on a hierarchical facet. * @param {string} facet the facet name @@ -824,14 +792,6 @@ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement} - */ -AlgoliaSearchHelper.prototype.removeRefine = function () { - return this.removeFacetRefinement.apply(this, arguments); -}; - /** * Removes an exclusion filter to a faceted attribute with the `value` provided. If the * filter is not set, it doesn't change the filters. @@ -855,14 +815,6 @@ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion} - */ -AlgoliaSearchHelper.prototype.removeExclude = function () { - return this.removeFacetExclusion.apply(this, arguments); -}; - /** * Removes a tag filter with the `tag` provided. If the * filter is not set, it doesn't change the filters. @@ -982,33 +934,6 @@ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion} - */ -AlgoliaSearchHelper.prototype.toggleExclude = function () { - return this.toggleFacetExclusion.apply(this, arguments); -}; - -/** - * Adds or removes a filter to a faceted attribute with the `value` provided. If - * the value is set then it removes it, otherwise it adds the filter. - * - * This method can be used for conjunctive, disjunctive and hierarchical filters. - * - * This method resets the current page to 0. - * @param {string} facet the facet to refine - * @param {string} value the associated value - * @return {AlgoliaSearchHelper} Method is chainable, it returns itself - * @throws Error will throw an error if the facet is not declared in the settings of the helper - * @fires change - * @chainable - * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement} - */ -AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) { - return this.toggleFacetRefinement(facet, value); -}; - /** * Adds or removes a filter to a faceted attribute with the `value` provided. If * the value is set then it removes it, otherwise it adds the filter. @@ -1032,14 +957,6 @@ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) { return this; }; -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement} - */ -AlgoliaSearchHelper.prototype.toggleRefine = function () { - return this.toggleFacetRefinement.apply(this, arguments); -}; - /** * Adds or removes a tag filter with the `value` provided. If * the value is set then it removes it, otherwise it adds the filter. @@ -1088,13 +1005,14 @@ AlgoliaSearchHelper.prototype.previousPage = function () { }; /** - * @private - * @param {number} page The page number + * Updates the current page. + * @function + * @param {number} page The page number * @return {AlgoliaSearchHelper} Method is chainable, it returns itself - * @chainable * @fires change + * @chainable */ -function setCurrentPage(page) { +AlgoliaSearchHelper.prototype.setPage = function setPage(page) { if (page < 0) throw new Error('Page requested below 0.'); this._change({ @@ -1103,27 +1021,7 @@ function setCurrentPage(page) { }); return this; -} - -/** - * Change the current page - * @deprecated - * @param {number} page The page number - * @return {AlgoliaSearchHelper} Method is chainable, it returns itself - * @fires change - * @chainable - */ -AlgoliaSearchHelper.prototype.setCurrentPage = setCurrentPage; - -/** - * Updates the current page. - * @function - * @param {number} page The page number - * @return {AlgoliaSearchHelper} Method is chainable, it returns itself - * @fires change - * @chainable - */ -AlgoliaSearchHelper.prototype.setPage = setCurrentPage; +}; /** * Updates the name of the index that will be targeted by the query. @@ -1250,54 +1148,6 @@ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) { return false; }; -/** - * Check if a value is excluded for a specific faceted attribute. If the value - * is omitted then the function checks if there is any excluding refinements. - * - * @param {string} facet name of the attribute for used for faceting - * @param {string} [value] optional value. If passed will test that this value - * is filtering the given facet. - * @return {boolean} true if refined - * @example - * helper.isExcludeRefined('color'); // false - * helper.isExcludeRefined('color', 'blue') // false - * helper.isExcludeRefined('color', 'red') // false - * - * helper.addFacetExclusion('color', 'red'); - * - * helper.isExcludeRefined('color'); // true - * helper.isExcludeRefined('color', 'blue') // false - * helper.isExcludeRefined('color', 'red') // true - */ -AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) { - return this.state.isExcludeRefined(facet, value); -}; - -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements} - */ -AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) { - return this.state.isDisjunctiveFacetRefined(facet, value); -}; - -/** - * Check if the string is a currently filtering tag. - * @param {string} tag tag to check - * @return {boolean} true if the tag is currently refined - */ -AlgoliaSearchHelper.prototype.hasTag = function (tag) { - return this.state.isTagRefined(tag); -}; - -// eslint-disable-next-line valid-jsdoc -/** - * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag} - */ -AlgoliaSearchHelper.prototype.isTagRefined = function () { - return this.hasTagRefinements.apply(this, arguments); -}; - /** * Get the name of the currently used index. * @return {string} name of the index @@ -1309,22 +1159,14 @@ AlgoliaSearchHelper.prototype.getIndex = function () { return this.state.index; }; -function getCurrentPage() { - return this.state.page; -} - -/** - * Get the currently selected page - * @deprecated - * @return {number} the current page - */ -AlgoliaSearchHelper.prototype.getCurrentPage = getCurrentPage; /** * Get the currently selected page * @function * @return {number} the current page */ -AlgoliaSearchHelper.prototype.getPage = getCurrentPage; +AlgoliaSearchHelper.prototype.getPage = function () { + return this.state.page; +}; /** * Get all the tags currently set to filters the results. @@ -1798,20 +1640,6 @@ AlgoliaSearchHelper.prototype._dispatchRecommendError = function ( if (this._currentNbRecommendQueries === 0) this.emit('recommendQueueEmpty'); }; -AlgoliaSearchHelper.prototype.containsRefinement = function ( - query, - facetFilters, - numericFilters, - tagFilters -) { - return ( - query || - facetFilters.length !== 0 || - numericFilters.length !== 0 || - tagFilters.length !== 0 - ); -}; - /** * Test if there are some disjunctive refinements on the facet * @private diff --git a/packages/algoliasearch-helper/test/integration-spec/helper.filters.js b/packages/algoliasearch-helper/test/integration-spec/helper.filters.js index a83dff7fc2..9d85f1cc4f 100644 --- a/packages/algoliasearch-helper/test/integration-spec/helper.filters.js +++ b/packages/algoliasearch-helper/test/integration-spec/helper.filters.js @@ -49,7 +49,7 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records f3: 1, }); - helper.addRefine('facet', 'f2').search(); + helper.addFacetRefinement('facet', 'f2').search(); } if (calls === 2) { @@ -59,14 +59,14 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records f2: 1, }); - helper.toggleRefine('facet', 'f3').search(); + helper.toggleFacetRefinement('facet', 'f3').search(); } if (calls === 3) { expect(results.hits.length).toBe(0); expect(results.facets[0]).toBe(undefined); - helper.removeRefine('facet', 'f2').search(); + helper.removeFacetRefinement('facet', 'f2').search(); } if (calls === 4) { @@ -86,5 +86,5 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records } }); - helper.addRefine('facet', 'f1').search(); + helper.addFacetRefinement('facet', 'f1').search(); }); diff --git a/packages/algoliasearch-helper/test/spec/SearchResults/getFacet.js b/packages/algoliasearch-helper/test/spec/SearchResults/getFacet.js deleted file mode 100644 index 7672523f70..0000000000 --- a/packages/algoliasearch-helper/test/spec/SearchResults/getFacet.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -var SearchResults = require('../../../src/SearchResults'); - -test('getFacetByName should return a given facet be it disjunctive or conjunctive', function () { - var data = require('../../datasets/SearchParameters/search.dataset')(); - - var result = new SearchResults(data.searchParams, data.response.results); - - var cityFacet = result.getFacetByName('city'); - - expect(cityFacet.name).toBe('city'); - expect(cityFacet.data).toEqual({ - 'New York': 1, - Paris: 3, - 'San Francisco': 1, - }); -}); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/clears.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/clears.js index 2a8cac6626..e2cf0d84fb 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/clears.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/clears.js @@ -19,12 +19,12 @@ function fixture() { }); return helper - .toggleRefine('facet1', '0') - .toggleRefine('facet2', '0') - .toggleRefine('disjunctiveFacet1', '0') - .toggleRefine('disjunctiveFacet2', '0') - .toggleExclude('excluded1', '0') - .toggleExclude('excluded2', '0') + .toggleFacetRefinement('facet1', '0') + .toggleFacetRefinement('facet2', '0') + .toggleFacetRefinement('disjunctiveFacet1', '0') + .toggleFacetRefinement('disjunctiveFacet2', '0') + .toggleFacetExclusion('excluded1', '0') + .toggleFacetExclusion('excluded2', '0') .addHierarchicalFacetRefinement('hierarchy1', '0') .addHierarchicalFacetRefinement('hierarchy2', '0') .addNumericRefinement('numeric1', '>=', '0') @@ -79,7 +79,7 @@ test('Clearing the same field from multiple elements should remove it everywhere helper .addNumericRefinement('facet1', '>=', '10') - .toggleExclude('facet1', 'value'); + .toggleFacetExclusion('facet1', 'value'); expect(helper.state.facetsRefinements.facet1).toEqual(['0']); expect(helper.state.numericRefinements.facet1).toEqual({ '>=': [10] }); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/distinct.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/distinct.js index 5830c25869..f27466a934 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/distinct.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/distinct.js @@ -31,7 +31,7 @@ test('Distinct not set', function () { }); helper.setState(state0); - helper.addDisjunctiveRefine('facet', 'value'); + helper.addDisjunctiveFacetRefinement('facet', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -43,7 +43,7 @@ test('Distinct not set', function () { }); helper.setState(state0); - helper.addRefine('facetConj', 'value'); + helper.addFacetRefinement('facetConj', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -93,7 +93,7 @@ test('Distinct set to true', function () { expect(facetSearchParam.distinct).toBe(true); helper.setState(state0); - helper.addDisjunctiveRefine('facet', 'value'); + helper.addDisjunctiveFacetRefinement('facet', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -102,7 +102,7 @@ test('Distinct set to true', function () { expect(facetSearchParam.distinct).toBe(true); helper.setState(state0); - helper.addRefine('facetConj', 'value'); + helper.addFacetRefinement('facetConj', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -146,7 +146,7 @@ test('Distinct to false', function () { expect(facetSearchParam.distinct).toBe(false); helper.setState(state0); - helper.addDisjunctiveRefine('facet', 'value'); + helper.addDisjunctiveFacetRefinement('facet', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -155,7 +155,7 @@ test('Distinct to false', function () { expect(facetSearchParam.distinct).toBe(false); helper.setState(state0); - helper.addRefine('facetConj', 'value'); + helper.addFacetRefinement('facetConj', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -199,7 +199,7 @@ test('Distinct as a number', function () { expect(facetSearchParam.distinct).toBe(distinctValue); helper.setState(state0); - helper.addDisjunctiveRefine('facet', 'value'); + helper.addDisjunctiveFacetRefinement('facet', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); @@ -208,7 +208,7 @@ test('Distinct as a number', function () { expect(facetSearchParam.distinct).toBe(distinctValue); helper.setState(state0); - helper.addRefine('facetConj', 'value'); + helper.addFacetRefinement('facetConj', 'value'); disjunctiveFacetSearchParam = requestBuilder._getDisjunctiveFacetSearchParams( helper.state ); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/events.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/events.js index 737410a1db..db8eada81a 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/events.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/events.js @@ -108,27 +108,27 @@ test('Change events should be emitted as soon as the state change, but search sh expect(changeEventCount).toBe(2); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addDisjunctiveRefine('city', 'Paris'); + helper.addDisjunctiveFacetRefinement('city', 'Paris'); expect(changeEventCount).toBe(3); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeDisjunctiveRefine('city', 'Paris'); + helper.removeDisjunctiveFacetRefinement('city', 'Paris'); expect(changeEventCount).toBe(4); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addExclude('tower', 'Empire State Building'); + helper.addFacetExclusion('tower', 'Empire State Building'); expect(changeEventCount).toBe(5); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeExclude('tower', 'Empire State Building'); + helper.removeFacetExclusion('tower', 'Empire State Building'); expect(changeEventCount).toBe(6); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addRefine('tower', 'Empire State Building'); + helper.addFacetRefinement('tower', 'Empire State Building'); expect(changeEventCount).toBe(7); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeRefine('tower', 'Empire State Building'); + helper.removeFacetRefinement('tower', 'Empire State Building'); expect(changeEventCount).toBe(8); expect(fakeClient.search).toHaveBeenCalledTimes(0); @@ -167,15 +167,15 @@ test('Change events should only be emitted for meaningful changes', function () expect(changeEventCount).toBe(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addDisjunctiveRefine('city', 'Paris'); + helper.addDisjunctiveFacetRefinement('city', 'Paris'); expect(changeEventCount).toBe(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addExclude('tower', 'Empire State Building'); + helper.addFacetExclusion('tower', 'Empire State Building'); expect(changeEventCount).toBe(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addRefine('tower', 'Empire State Building'); + helper.addFacetRefinement('tower', 'Empire State Building'); expect(changeEventCount).toBe(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); @@ -192,15 +192,15 @@ test('Change events should only be emitted for meaningful changes', function () expect(changeEventCount).toBe(1); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeDisjunctiveRefine('city', 'Paris'); + helper.removeDisjunctiveFacetRefinement('city', 'Paris'); expect(changeEventCount).toBe(1); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeExclude('tower', 'Empire State Building'); + helper.removeFacetExclusion('tower', 'Empire State Building'); expect(changeEventCount).toBe(1); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeRefine('tower', 'Empire State Building'); + helper.removeFacetRefinement('tower', 'Empire State Building'); expect(changeEventCount).toBe(1); expect(fakeClient.search).toHaveBeenCalledTimes(0); @@ -227,27 +227,27 @@ test('search event should be emitted once when the search is triggered and befor expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addDisjunctiveRefine('city', 'Paris'); + helper.addDisjunctiveFacetRefinement('city', 'Paris'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeDisjunctiveRefine('city', 'Paris'); + helper.removeDisjunctiveFacetRefinement('city', 'Paris'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addExclude('tower', 'Empire State Building'); + helper.addFacetExclusion('tower', 'Empire State Building'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeExclude('tower', 'Empire State Building'); + helper.removeFacetExclusion('tower', 'Empire State Building'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.addRefine('tower', 'Empire State Building'); + helper.addFacetRefinement('tower', 'Empire State Building'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); - helper.removeRefine('tower', 'Empire State Building'); + helper.removeFacetRefinement('tower', 'Empire State Building'); expect(searched).toHaveBeenCalledTimes(0); expect(fakeClient.search).toHaveBeenCalledTimes(0); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/excludes.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/excludes.js index f80c1f8f7e..1eef17aece 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/excludes.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/excludes.js @@ -4,7 +4,7 @@ var algoliasearchHelper = require('../../../index'); var fakeClient = {}; -test('addExclude should add an exclusion', function () { +test('addFacetExclusion should add an exclusion', function () { var helper = algoliasearchHelper(fakeClient, null, { facets: ['facet'], }); @@ -15,14 +15,14 @@ test('addExclude should add an exclusion', function () { var facetValueToExclude = 'brand'; expect(helper.state.facetsExcludes[facetName]).toBeFalsy(); - helper.addExclude(facetName, facetValueToExclude); + helper.addFacetExclusion(facetName, facetValueToExclude); expect(helper.state.facetsExcludes[facetName]).toBeTruthy(); expect( helper.state.facetsExcludes[facetName][0] === facetValueToExclude ).toBeTruthy(); }); -test('removeExclude should remove an exclusion', function (done) { +test('removeFacetExclusion should remove an exclusion', function (done) { var helper = algoliasearchHelper(fakeClient, null, { facets: ['facet'], }); @@ -32,13 +32,13 @@ test('removeExclude should remove an exclusion', function (done) { var facetName = 'facet'; var facetValueToExclude = 'brand'; - helper.addExclude(facetName, facetValueToExclude); + helper.addFacetExclusion(facetName, facetValueToExclude); expect(helper.state.facetsExcludes[facetName].length === 1).toBeTruthy(); - helper.removeExclude(facetName, facetValueToExclude); + helper.removeFacetExclusion(facetName, facetValueToExclude); expect(helper.state.facetsExcludes[facetName]).toEqual([]); try { - helper.removeExclude(facetName, facetValueToExclude); + helper.removeFacetExclusion(facetName, facetValueToExclude); } catch (e) { done.fail('Removing unset exclusions should be ok...'); } @@ -55,13 +55,21 @@ test('isExcluded should allow to omit the value', function () { facets: [facetName], }); - expect(helper.isExcluded(facetName, facetValueToExclude)).toBeFalsy(); - expect(helper.isExcluded(facetName, facetValueNotExcluded)).toBeFalsy(); - expect(helper.isExcluded(facetName)).toBeFalsy(); - helper.addExclude(facetName, facetValueToExclude); - expect(helper.isExcluded(facetName, facetValueToExclude)).toBeTruthy(); - expect(helper.isExcluded(facetName, facetValueNotExcluded)).toBeFalsy(); - expect(helper.isExcluded(facetName)).toBeTruthy(); + expect( + helper.state.isExcludeRefined(facetName, facetValueToExclude) + ).toBeFalsy(); + expect( + helper.state.isExcludeRefined(facetName, facetValueNotExcluded) + ).toBeFalsy(); + expect(helper.state.isExcludeRefined(facetName)).toBeFalsy(); + helper.addFacetExclusion(facetName, facetValueToExclude); + expect( + helper.state.isExcludeRefined(facetName, facetValueToExclude) + ).toBeTruthy(); + expect( + helper.state.isExcludeRefined(facetName, facetValueNotExcluded) + ).toBeFalsy(); + expect(helper.state.isExcludeRefined(facetName)).toBeTruthy(); }); test('isExcluded should report exclusion correctly', function () { @@ -74,9 +82,15 @@ test('isExcluded should report exclusion correctly', function () { var facetName = 'facet'; var facetValueToExclude = 'brand'; - expect(helper.isExcluded(facetName, facetValueToExclude)).toBeFalsy(); - helper.addExclude(facetName, facetValueToExclude); - expect(helper.isExcluded(facetName, facetValueToExclude)).toBeTruthy(); - helper.removeExclude(facetName, facetValueToExclude); - expect(helper.isExcluded(facetName, facetValueToExclude)).toBeFalsy(); + expect( + helper.state.isExcludeRefined(facetName, facetValueToExclude) + ).toBeFalsy(); + helper.addFacetExclusion(facetName, facetValueToExclude); + expect( + helper.state.isExcludeRefined(facetName, facetValueToExclude) + ).toBeTruthy(); + helper.removeFacetExclusion(facetName, facetValueToExclude); + expect( + helper.state.isExcludeRefined(facetName, facetValueToExclude) + ).toBeFalsy(); }); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/facetFilters.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/facetFilters.js index 2382aeeae4..a934a5542a 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/facetFilters.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/facetFilters.js @@ -11,27 +11,27 @@ test('The filters should contain the different filters for a single conjunctive facets: [facetName], }); - helper.addRefine(facetName, 'value1'); + helper.addFacetRefinement(facetName, 'value1'); expect(requestBuilder._getFacetFilters(helper.state)).toEqual([ facetName + ':value1', ]); - helper.addRefine(facetName, 'value2'); + helper.addFacetRefinement(facetName, 'value2'); expect(requestBuilder._getFacetFilters(helper.state)).toEqual([ facetName + ':value1', facetName + ':value2', ]); - helper.toggleRefine(facetName, 'value3'); + helper.toggleFacetRefinement(facetName, 'value3'); expect(requestBuilder._getFacetFilters(helper.state)).toEqual([ facetName + ':value1', facetName + ':value2', facetName + ':value3', ]); - helper.removeRefine(facetName, 'value3'); + helper.removeFacetRefinement(facetName, 'value3'); expect(requestBuilder._getFacetFilters(helper.state)).toEqual([ facetName + ':value1', facetName + ':value2', ]); - helper.addRefine(facetName, 'value1'); + helper.addFacetRefinement(facetName, 'value1'); expect(requestBuilder._getFacetFilters(helper.state)).toEqual([ facetName + ':value1', facetName + ':value2', diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/incorrectFacetDefinition.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/incorrectFacetDefinition.js index a325087d37..ff82bca928 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/incorrectFacetDefinition.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/incorrectFacetDefinition.js @@ -7,22 +7,24 @@ var fakeClient = {}; test('Conjunctive facet should be declared to be refined', function () { var h = algoliasearchHelper(fakeClient, '', {}); - expect(h.addRefine.bind(h, 'undeclaredFacet', 'value')).toThrow(); - expect(h.removeRefine.bind(h, 'undeclaredFacet', 'value')).toThrow(); + expect(h.addFacetRefinement.bind(h, 'undeclaredFacet', 'value')).toThrow(); + expect(h.removeFacetRefinement.bind(h, 'undeclaredFacet', 'value')).toThrow(); }); test('Conjunctive facet should be declared to be excluded', function () { var h = algoliasearchHelper(fakeClient, '', {}); - expect(h.addExclude.bind(h, 'undeclaredFacet', 'value')).toThrow(); - expect(h.removeExclude.bind(h, 'undeclaredFacet', 'value')).toThrow(); + expect(h.addFacetExclusion.bind(h, 'undeclaredFacet', 'value')).toThrow(); + expect(h.removeFacetExclusion.bind(h, 'undeclaredFacet', 'value')).toThrow(); }); test('Conjuctive facet should be declared to be refine', function () { var h = algoliasearchHelper(fakeClient, '', {}); - expect(h.addDisjunctiveRefine.bind(h, 'undeclaredFacet', 'value')).toThrow(); expect( - h.removeDisjunctiveRefine.bind(h, 'undeclaredFacet', 'value') + h.addDisjunctiveFacetRefinement.bind(h, 'undeclaredFacet', 'value') + ).toThrow(); + expect( + h.removeDisjunctiveFacetRefinement.bind(h, 'undeclaredFacet', 'value') ).toThrow(); }); diff --git a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/pages.js b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/pages.js index 6a14952bd1..d79b83f685 100644 --- a/packages/algoliasearch-helper/test/spec/algoliasearch.helper/pages.js +++ b/packages/algoliasearch-helper/test/spec/algoliasearch.helper/pages.js @@ -60,17 +60,17 @@ test('pages should be reset if the mutation might change the number of pages', f ['addNumericRefinement', 'facet', '>', '2'], ['removeNumericRefinement', 'facet', '>'], - ['addExclude', 'facet1', 'val2'], - ['removeExclude', 'facet1', 'val2'], + ['addFacetExclusion', 'facet1', 'val2'], + ['removeFacetExclusion', 'facet1', 'val2'], - ['addRefine', 'f2', 'val'], - ['removeRefine', 'f2', 'val'], + ['addFacetRefinement', 'f2', 'val'], + ['removeFacetRefinement', 'f2', 'val'], - ['addDisjunctiveRefine', 'f1', 'val'], - ['removeDisjunctiveRefine', 'f1', 'val'], + ['addDisjunctiveFacetRefinement', 'f1', 'val'], + ['removeDisjunctiveFacetRefinement', 'f1', 'val'], - ['toggleRefine', 'f1', 'v1'], - ['toggleExclude', 'facet1', '55'], + ['toggleFacetRefinement', 'f1', 'v1'], + ['toggleFacetExclusion', 'facet1', '55'], ].forEach(function ([fn, ...args]) { helper.setPage(10); diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/attributes-order.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/attributes-order.js index 37f0c85a4d..024594088c 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/attributes-order.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/attributes-order.js @@ -8,9 +8,9 @@ test('hierarchical facets: attributes order', function (done) { var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -123,9 +123,9 @@ test('hierarchical facets: attributes order', function (done) { helper.once('result', function (event) { expect(event.results.hierarchicalFacets).toEqual(expectedHelperResponse); - expect(event.results.getFacetByName('categories')).toEqual( - expectedHelperResponse[0] - ); + expect( + event.results.hierarchicalFacets.find((f) => f.name === 'categories') + ).toEqual(expectedHelperResponse[0]); done(); }); diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/breadcrumb.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/breadcrumb.js index 3c27339845..fb64764a19 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/breadcrumb.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/breadcrumb.js @@ -25,7 +25,7 @@ test('hierarchical facets: using getHierarchicalFacetBreadcrumb()', function () ], }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); expect(helper.getHierarchicalFacetBreadcrumb('categories')).toEqual([ 'beers', diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-prefix-path.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-prefix-path.js index 5da483e52a..8ce6d91eb6 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-prefix-path.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-prefix-path.js @@ -22,7 +22,7 @@ test('hierarchical facets: custom prefix path', function (done) { ], }); - helper.toggleRefine('categories', 'beers | Belgian'); + helper.toggleFacetRefinement('categories', 'beers | Belgian'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-separator.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-separator.js index d1328e0a6c..7bfd262492 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-separator.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/custom-separator.js @@ -21,7 +21,7 @@ test('hierarchical facets: custom separator', function (done) { ], }); - helper.toggleRefine('categories', 'beers | IPA'); + helper.toggleFacetRefinement('categories', 'beers | IPA'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/do-not-show-parent-level.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/do-not-show-parent-level.js index dcde21476e..54532a62cd 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/do-not-show-parent-level.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/do-not-show-parent-level.js @@ -22,7 +22,7 @@ test('hierarchical facets: do not show parent level', function (done) { ], }); - helper.toggleRefine('categories', 'beers | IPA'); + helper.toggleFacetRefinement('categories', 'beers | IPA'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/getFacetValues.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/getFacetValues.js index cb23122036..0c8c99339b 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/getFacetValues.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/getFacetValues.js @@ -17,7 +17,7 @@ test('hierarchical facets: getFacetValues', function () { ], }); - helper.toggleRefine('categories', 'beers | IPA').setQuery('a'); + helper.toggleFacetRefinement('categories', 'beers | IPA').setQuery('a'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/no-trim.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/no-trim.js index deeda58932..9e6418cb68 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/no-trim.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/no-trim.js @@ -21,9 +21,9 @@ test('hierarchical facets: do not trim facetFilters values', function (done) { ], }); - helper.toggleRefine('categories', ' beers > IPA '); - helper.toggleRefine('categories', ' beers > IPA '); - helper.toggleRefine('categories', ' beers > IPA '); + helper.toggleFacetRefinement('categories', ' beers > IPA '); + helper.toggleFacetRefinement('categories', ' beers > IPA '); + helper.toggleFacetRefinement('categories', ' beers > IPA '); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/objects-with-multiple-categories.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/objects-with-multiple-categories.js index e65f107756..4e6a5f5cc1 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/objects-with-multiple-categories.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/objects-with-multiple-categories.js @@ -20,7 +20,7 @@ test('hierarchical facets: objects with multiple categories', function (done) { ], }); - helper.toggleRefine('categories', 'beers > IPA'); + helper.toggleFacetRefinement('categories', 'beers > IPA'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/one-level.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/one-level.js index 38557be453..3e8a30d9d5 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/one-level.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/one-level.js @@ -20,7 +20,7 @@ test('hierarchical facets: only one level deep', function (done) { ], }); - helper.toggleRefine('categories', 'beers'); + helper.toggleFacetRefinement('categories', 'beers'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/pagination.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/pagination.js index 724cecfbd2..a614e5af32 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/pagination.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/pagination.js @@ -6,9 +6,9 @@ test('hierarchical facets: pagination', function (done) { var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -25,7 +25,7 @@ test('hierarchical facets: pagination', function (done) { ], }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); var algoliaResponse = { results: [ @@ -85,8 +85,8 @@ test('hierarchical facets: pagination', function (done) { }); helper.setQuery(''); - helper.setCurrentPage(1); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.setPage(1); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); helper.search(); helper.once('result', function () { diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/parent-toggleRefine.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/parent-toggleRefine.js index ccdfc1c890..4fa035a481 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/parent-toggleRefine.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/parent-toggleRefine.js @@ -1,14 +1,14 @@ 'use strict'; -test('hierarchical facets: toggleRefine behavior', function () { +test('hierarchical facets: toggleFacetRefinement behavior', function () { var algoliasearch = require('algoliasearch'); algoliasearch = algoliasearch.algoliasearch || algoliasearch; var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -30,13 +30,13 @@ test('hierarchical facets: toggleRefine behavior', function () { }); // select `Flying dog` - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); // unselect `beers` - helper.toggleRefine('categories', 'beers'); + helper.toggleFacetRefinement('categories', 'beers'); // select `beers` - helper.toggleRefine('categories', 'beers'); + helper.toggleFacetRefinement('categories', 'beers'); // we should be on `beers` helper.setQuery('a').search(); @@ -51,15 +51,15 @@ test('hierarchical facets: toggleRefine behavior', function () { expect(hitsQuery.params.facetFilters).toEqual([['categories.lvl0:beers']]); }); -test('hierarchical facets: toggleRefine behavior when root level', function () { +test('hierarchical facets: toggleFacetRefinement behavior when root level', function () { var algoliasearch = require('algoliasearch'); algoliasearch = algoliasearch.algoliasearch || algoliasearch; var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -80,8 +80,8 @@ test('hierarchical facets: toggleRefine behavior when root level', function () { return new Promise(function () {}); }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); - helper.toggleRefine('categories', 'beers'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers'); // we should be on `` helper.setQuery('a').search(); @@ -93,15 +93,15 @@ test('hierarchical facets: toggleRefine behavior when root level', function () { expect(hitsQuery.params.facetFilters).toBe(undefined); }); -test('hierarchical facets: toggleRefine behavior when different root level', function () { +test('hierarchical facets: toggleFacetRefinement behavior when different root level', function () { var algoliasearch = require('algoliasearch'); algoliasearch = algoliasearch.algoliasearch || algoliasearch; var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -122,8 +122,8 @@ test('hierarchical facets: toggleRefine behavior when different root level', fun return new Promise(function () {}); }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); - helper.toggleRefine('categories', 'fruits'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'fruits'); // we should be on `fruits` helper.setQuery('a').search(); diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/refined-no-result.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/refined-no-result.js index 9147ee1d47..1e037bed67 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/refined-no-result.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/refined-no-result.js @@ -6,9 +6,9 @@ test('hierarchical facets: no results', function (done) { var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var client = algoliasearch(appId, apiKey); var helper = algoliasearchHelper(client, indexName, { @@ -25,7 +25,7 @@ test('hierarchical facets: no results', function (done) { ], }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/show-parent-level.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/show-parent-level.js index 6723174451..010dd5ae33 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/show-parent-level.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/show-parent-level.js @@ -22,7 +22,7 @@ test('hierarchical facets: show parent level', function (done) { ], }); - helper.toggleRefine('categories', 'beers | IPA'); + helper.toggleFacetRefinement('categories', 'beers | IPA'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js index 5261f74791..54230e4437 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js @@ -4,9 +4,9 @@ describe('hierarchical facets: simple usage', function () { var algoliasearch = require('algoliasearch'); algoliasearch = algoliasearch.algoliasearch || algoliasearch; var algoliasearchHelper = require('../../../'); - var appId = 'hierarchical-toggleRefine-appId'; - var apiKey = 'hierarchical-toggleRefine-apiKey'; - var indexName = 'hierarchical-toggleRefine-indexName'; + var appId = 'hierarchical-toggleFacetRefinement-appId'; + var apiKey = 'hierarchical-toggleFacetRefinement-apiKey'; + var indexName = 'hierarchical-toggleFacetRefinement-indexName'; var algoliaResponse = { results: [ @@ -101,7 +101,7 @@ describe('hierarchical facets: simple usage', function () { ], }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); var expectedHelperResponse = [ { @@ -234,9 +234,9 @@ describe('hierarchical facets: simple usage', function () { ]); expect(event.results.hierarchicalFacets).toEqual(expectedHelperResponse); - expect(event.results.getFacetByName('categories')).toEqual( - expectedHelperResponse[0] - ); + expect( + event.results.hierarchicalFacets.find((f) => f.name === 'categories') + ).toEqual(expectedHelperResponse[0]); // we do not yet support multiple values for hierarchicalFacetsRefinements // but at some point we may want to open multiple leafs of a hierarchical menu @@ -270,7 +270,7 @@ describe('hierarchical facets: simple usage', function () { } ); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); var expectedHelperResponse = [ { @@ -403,9 +403,9 @@ describe('hierarchical facets: simple usage', function () { ]); expect(event.results.hierarchicalFacets).toEqual(expectedHelperResponse); - expect(event.results.getFacetByName('categories')).toEqual( - expectedHelperResponse[0] - ); + expect( + event.results.hierarchicalFacets.find((f) => f.name === 'categories') + ).toEqual(expectedHelperResponse[0]); // we do not yet support multiple values for hierarchicalFacetsRefinements // but at some point we may want to open multiple leafs of a hierarchical menu diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/sort-by.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/sort-by.js index b04462f26a..079d149f4e 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/sort-by.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/sort-by.js @@ -26,7 +26,7 @@ test('hierarchical facets: using sortBy', function (done) { ], }); - helper.toggleRefine('categories', 'beers > IPA > Flying dog'); + helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/two-facets.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/two-facets.js index b1a9bdf681..41009ea28b 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/two-facets.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/two-facets.js @@ -24,8 +24,8 @@ test('hierarchical facets: two hierarchical facets', function (done) { ], }); - helper.toggleRefine('beers', 'IPA'); - helper.toggleRefine('fruits', 'oranges'); + helper.toggleFacetRefinement('beers', 'IPA'); + helper.toggleFacetRefinement('fruits', 'oranges'); var algoliaResponse = { results: [ diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/unknown-facet.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/unknown-facet.js index 87d82d86c5..472ecc914a 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/unknown-facet.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/unknown-facet.js @@ -20,6 +20,6 @@ test('hierarchical facets: throw on unknown facet', function () { }); expect(function () { - helper.toggleRefine('unknownFacet', 'beers'); + helper.toggleFacetRefinement('unknownFacet', 'beers'); }).toThrow(); }); diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/with-a-disjunctive-facet.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/with-a-disjunctive-facet.js index d024beed04..55afb99de6 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/with-a-disjunctive-facet.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/with-a-disjunctive-facet.js @@ -21,8 +21,8 @@ test('hierarchical facets: combined with a disjunctive facet', function () { ], }); - helper.toggleRefine('categories', 'beers > IPA'); - helper.toggleRefine('colors', 'blue'); + helper.toggleFacetRefinement('categories', 'beers > IPA'); + helper.toggleFacetRefinement('colors', 'blue'); client.search = jest.fn(function () { return new Promise(function () {}); diff --git a/packages/algoliasearch-helper/test/spec/refinements.js b/packages/algoliasearch-helper/test/spec/refinements.js index e61ebdea3f..cd2b6d7936 100644 --- a/packages/algoliasearch-helper/test/spec/refinements.js +++ b/packages/algoliasearch-helper/test/spec/refinements.js @@ -13,12 +13,12 @@ test('Adding refinements should add an entry to the refinements attribute', func }); expect(Object.keys(helper.state.facetsRefinements).length).toBe(0); - helper.addRefine(facetName, facetValue); + helper.addFacetRefinement(facetName, facetValue); expect(Object.keys(helper.state.facetsRefinements).length).toBe(1); expect(helper.state.facetsRefinements.facet1).toEqual([facetValue]); - helper.addRefine(facetName, facetValue); + helper.addFacetRefinement(facetName, facetValue); expect(Object.keys(helper.state.facetsRefinements).length).toBe(1); - helper.removeRefine(facetName, facetValue); + helper.removeFacetRefinement(facetName, facetValue); expect(Object.keys(helper.state.facetsRefinements).length).toBe(1); expect(helper.state.facetsRefinements[facetName]).toEqual([]); }); @@ -31,11 +31,11 @@ test('Adding several refinements for a single attribute should be handled', func }); expect(Object.keys(helper.state.facetsRefinements).length).toBe(0); - helper.addRefine(facetName, 'value1'); + helper.addFacetRefinement(facetName, 'value1'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(1); - helper.addRefine(facetName, 'value2'); + helper.addFacetRefinement(facetName, 'value2'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(2); - helper.addRefine(facetName, 'value1'); + helper.addFacetRefinement(facetName, 'value1'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(2); }); @@ -47,20 +47,20 @@ test('Toggling several refinements for a single attribute should be handled', fu }); expect(Object.keys(helper.state.facetsRefinements).length).toBe(0); - helper.toggleRefine(facetName, 'value1'); + helper.toggleFacetRefinement(facetName, 'value1'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(1); - helper.toggleRefine(facetName, 'value2'); + helper.toggleFacetRefinement(facetName, 'value2'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(2); - helper.toggleRefine(facetName, 'value1'); + helper.toggleFacetRefinement(facetName, 'value1'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(1); expect(helper.state.facetsRefinements[facetName]).toEqual(['value2']); }); -test('Using toggleRefine on a non specified facet should throw an exception', function () { +test('Using toggleFacetRefinement on a non specified facet should throw an exception', function () { var helper = algoliasearchHelper(emptyClient, null, {}); expect(function () { - helper.toggleRefine('unknown', 'value'); + helper.toggleFacetRefinement('unknown', 'value'); }).toThrow(); }); @@ -72,11 +72,11 @@ test('Removing several refinements for a single attribute should be handled', fu }); expect(Object.keys(helper.state.facetsRefinements).length).toBe(0); - helper.addRefine(facetName, 'value1'); - helper.addRefine(facetName, 'value2'); - helper.addRefine(facetName, 'value3'); + helper.addFacetRefinement(facetName, 'value1'); + helper.addFacetRefinement(facetName, 'value2'); + helper.addFacetRefinement(facetName, 'value3'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(3); - helper.removeRefine(facetName, 'value2'); + helper.removeFacetRefinement(facetName, 'value2'); expect(Object.keys(helper.state.facetsRefinements[facetName]).length).toBe(2); expect(helper.state.facetsRefinements[facetName]).toEqual([ 'value1', @@ -84,24 +84,6 @@ test('Removing several refinements for a single attribute should be handled', fu ]); }); -test('isDisjunctiveRefined', function () { - var facet = 'MyFacet'; - - var helper = algoliasearchHelper(emptyClient, null, { - disjunctiveFacets: [facet], - }); - - var value = 'MyValue'; - - expect(helper.isDisjunctiveRefined(facet, value)).toBe(false); - - helper.addDisjunctiveRefine(facet, value); - expect(helper.isDisjunctiveRefined(facet, value)).toBe(true); - - helper.removeDisjunctiveRefine(facet, value); - expect(helper.isDisjunctiveRefined(facet, value)).toBe(false); -}); - test('hasRefinements(facet) should return true if the facet is refined.', function () { var helper = algoliasearchHelper(emptyClient, null, { facets: ['facet1'], @@ -109,7 +91,7 @@ test('hasRefinements(facet) should return true if the facet is refined.', functi expect(helper.hasRefinements('facet1')).toBe(false); - helper.addRefine('facet1', 'boom'); + helper.addFacetRefinement('facet1', 'boom'); expect(helper.hasRefinements('facet1')).toBe(true); @@ -125,15 +107,15 @@ test('getRefinements should return all the refinements for a given facet', funct }); helper - .addRefine('facet1', 'val1') - .addRefine('facet1', 'val2') - .addExclude('facet1', 'val-1') - .toggleRefine('facet1', 'val3'); + .addFacetRefinement('facet1', 'val1') + .addFacetRefinement('facet1', 'val2') + .addFacetExclusion('facet1', 'val-1') + .toggleFacetRefinement('facet1', 'val3'); helper - .addDisjunctiveRefine('facet2', 'val4') - .addDisjunctiveRefine('facet2', 'val5') - .toggleRefine('facet2', 'val6'); + .addDisjunctiveFacetRefinement('facet2', 'val4') + .addDisjunctiveFacetRefinement('facet2', 'val5') + .toggleFacetRefinement('facet2', 'val6'); helper .addNumericRefinement('sales', '>', '3') @@ -174,17 +156,17 @@ test('[Conjunctive] Facets should be resilient to user attempt to use numbers', disjunctiveFacets: ['facet2'], }); - helper.addRefine('facet1', 42); + helper.addFacetRefinement('facet1', 42); expect(helper.hasRefinements('facet1', 42)).toBe(true); expect(helper.hasRefinements('facet1', '42')).toBe(true); var stateWithFacet1and42 = helper.state; - helper.removeRefine('facet1', '42'); + helper.removeFacetRefinement('facet1', '42'); expect(helper.hasRefinements('facet1', '42')).toBe(false); helper.setState(stateWithFacet1and42); - helper.removeRefine('facet1', 42); + helper.removeFacetRefinement('facet1', 42); expect(helper.hasRefinements('facet1', 42)).toBe(false); }); @@ -194,18 +176,18 @@ test('[Exclude] Facets should be resilient to user attempt to use numbers', func disjunctiveFacets: ['facet2'], }); - helper.addExclude('facet1', 42); - expect(helper.isExcluded('facet1', 42)).toBe(true); - expect(helper.isExcluded('facet1', '42')).toBe(true); + helper.addFacetExclusion('facet1', 42); + expect(helper.state.isExcludeRefined('facet1', 42)).toBe(true); + expect(helper.state.isExcludeRefined('facet1', '42')).toBe(true); var stateWithFacet1Without42 = helper.state; - helper.removeExclude('facet1', '42'); - expect(helper.isExcluded('facet1', '42')).toBe(false); + helper.removeFacetExclusion('facet1', '42'); + expect(helper.state.isExcludeRefined('facet1', '42')).toBe(false); helper.setState(stateWithFacet1Without42); - helper.removeExclude('facet1', 42); - expect(helper.isExcluded('facet1', 42)).toBe(false); + helper.removeFacetExclusion('facet1', 42); + expect(helper.state.isExcludeRefined('facet1', 42)).toBe(false); }); test('[Disjunctive] Facets should be resilient to user attempt to use numbers', function () { @@ -214,16 +196,16 @@ test('[Disjunctive] Facets should be resilient to user attempt to use numbers', disjunctiveFacets: ['facet2'], }); - helper.addDisjunctiveRefine('facet2', 42); - expect(helper.isDisjunctiveRefined('facet2', 42)).toBe(true); - expect(helper.isDisjunctiveRefined('facet2', '42')).toBe(true); + helper.addDisjunctiveFacetRefinement('facet2', 42); + expect(helper.state.isDisjunctiveFacetRefined('facet2', 42)).toBe(true); + expect(helper.state.isDisjunctiveFacetRefined('facet2', '42')).toBe(true); var stateWithFacet2and42 = helper.state; - helper.removeDisjunctiveRefine('facet2', '42'); - expect(helper.isDisjunctiveRefined('facet2', '42')).toBe(false); + helper.removeDisjunctiveFacetRefinement('facet2', '42'); + expect(helper.state.isDisjunctiveFacetRefined('facet2', '42')).toBe(false); helper.setState(stateWithFacet2and42); - helper.removeDisjunctiveRefine('facet2', 42); - expect(helper.isDisjunctiveRefined('facet2', 42)).toBe(false); + helper.removeDisjunctiveFacetRefinement('facet2', 42); + expect(helper.state.isDisjunctiveFacetRefined('facet2', 42)).toBe(false); }); diff --git a/packages/algoliasearch-helper/test/spec/search.js b/packages/algoliasearch-helper/test/spec/search.js index 535f0df87a..e701b01551 100644 --- a/packages/algoliasearch-helper/test/spec/search.js +++ b/packages/algoliasearch-helper/test/spec/search.js @@ -15,8 +15,8 @@ test('Search should call the algolia client according to the number of refinemen disjunctiveFacets: ['city'], }); - helper.addDisjunctiveRefine('city', 'Paris', true); - helper.addDisjunctiveRefine('city', 'New York', true); + helper.addDisjunctiveFacetRefinement('city', 'Paris', true); + helper.addDisjunctiveFacetRefinement('city', 'New York', true); helper.on('result', function (event) { var results = event.results; @@ -127,12 +127,12 @@ test('no mutating methods should trigger a search', function () { helper.setQuery(''); helper.clearRefinements(); - helper.addDisjunctiveRefine('city', 'Paris'); - helper.removeDisjunctiveRefine('city', 'Paris'); - helper.addExclude('tower', 'Empire State Building'); - helper.removeExclude('tower', 'Empire State Building'); - helper.addRefine('tower', 'Empire State Building'); - helper.removeRefine('tower', 'Empire State Building'); + helper.addDisjunctiveFacetRefinement('city', 'Paris'); + helper.removeDisjunctiveFacetRefinement('city', 'Paris'); + helper.addFacetExclusion('tower', 'Empire State Building'); + helper.removeFacetExclusion('tower', 'Empire State Building'); + helper.addFacetRefinement('tower', 'Empire State Building'); + helper.removeFacetRefinement('tower', 'Empire State Building'); expect(client.search).toHaveBeenCalledTimes(0);