File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ var settings = function() {
63
63
64
64
this . addCustomFieldFilter = function ( fieldName , value ) {
65
65
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
+ }
67
69
}
68
70
69
71
this . removeCustomFieldFilter = function ( fieldName , value ) {
@@ -114,7 +116,9 @@ var settings = function() {
114
116
}
115
117
116
118
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
+ }
118
122
}
119
123
120
124
this . setNumberOfFacets = function ( numFacets ) {
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ describe('settings', function() {
57
57
assert . equal ( JSON . stringify ( s . getSettings ( ) . customFieldFilters ) , expect ) ;
58
58
} ) ;
59
59
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
+
60
67
61
68
} ) ;
62
69
} ) ;
You can’t perform that action at this time.
0 commit comments