File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ var settings = function() {
6363
6464 this . addCustomFieldFilter = function ( fieldName , value ) {
6565 var filter = encodeURIComponent ( fieldName + '=' + value ) ;
66- this . settings . customFieldFilters . push ( filter ) ;
66+ if ( this . settings . customFieldFilters . indexOf ( filter ) === - 1 ) {
67+ this . settings . customFieldFilters . push ( filter ) ;
68+ }
6769 }
6870
6971 this . removeCustomFieldFilter = function ( fieldName , value ) {
@@ -114,7 +116,9 @@ var settings = function() {
114116 }
115117
116118 this . addFacetField = function ( field ) {
117- this . settings . facetFields . push ( field ) ;
119+ if ( this . settings . facetFields . indexOf ( field ) === - 1 ) {
120+ this . settings . facetFields . push ( field ) ;
121+ }
118122 }
119123
120124 this . setNumberOfFacets = function ( numFacets ) {
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ describe('settings', function() {
5757 assert . equal ( JSON . stringify ( s . getSettings ( ) . customFieldFilters ) , expect ) ;
5858 } ) ;
5959
60+ it ( 'adding custom fields filter should be idempotent' , function ( ) {
61+ s . addCustomFieldFilter ( 'city' , 'helsinki' ) ;
62+ s . addCustomFieldFilter ( 'city' , 'helsinki' ) ;
63+ var expect = '["city%3Dhelsinki"]' ;
64+ assert . equal ( JSON . stringify ( s . getSettings ( ) . customFieldFilters ) , expect ) ;
65+ } ) ;
66+
6067
6168 } ) ;
6269} ) ;
You can’t perform that action at this time.
0 commit comments