-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix algolia/algoliasearch-helper-js#84 : Add a more friendly way to u…
…pdate a single parameter on SearchParameters
- Loading branch information
Alexandre Stanislawski
committed
Jun 2, 2015
1 parent
dca4298
commit 6aedb1d
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/algoliasearch-helper/test/spec/SearchParameters.setQueryParameter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use strict"; | ||
var test = require( "tape" ); | ||
//var _ = require( "lodash" ); | ||
var SearchParameters = require( "../../src/SearchParameters" ); | ||
|
||
test( "setqueryparameter should update existing parameter", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
var newValue = []; | ||
var newsp = sp.setQueryParameter( "facets", newValue ); | ||
|
||
t.equal( newsp.facets, newValue, "update of an existing parameter" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setqueryparameter should add non-existing parameter", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
var newValue = [ "attributesToHighlight" ]; | ||
var newsp = sp.setQueryParameter( "attributesToHighlight", newValue ); | ||
|
||
t.equal( newsp.attributesToHighlight, newValue, "add new parameter" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setQueryParameter should not create a new instance if the update is non effective", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"], | ||
maxValuesPerFacet : 10 | ||
} ); | ||
|
||
var newValue = 10; | ||
var newsp = sp.setQueryParameter( "maxValuesPerFacet", newValue ); | ||
|
||
t.equal( newsp, sp, "No change should result in the same instance" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setQueryParameter should not create a new instance if the parameter is unknown", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
var newValue = [ "attributesToHighlight" ]; | ||
var newsp = sp.setQueryParameter( "unknown", newValue ); | ||
|
||
t.equal( newsp, sp, "Unknown parameter should return the same instance" ); | ||
|
||
t.end(); | ||
} ); |
File renamed without changes.